You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

slack_client_spec.rb 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. require "dotenv/load"
  2. require "slack_mattermost_emoji/slack_client"
  3. RSpec.describe SlackMattermostEmoji::SlackClient do
  4. it 'should raise if credentials are missing' do
  5. expect do
  6. SlackMattermostEmoji::SlackClient.new(
  7. username: '',
  8. password: '',
  9. domain: '',
  10. )
  11. end.to raise_error('Slack username, password, and domain are all required')
  12. end
  13. it 'should be able to log in to slack using the provided credentials' do
  14. client = SlackMattermostEmoji::SlackClient.new(
  15. username: ENV['SLACK_USERNAME'],
  16. password: ENV['SLACK_PASSWORD'],
  17. domain: ENV['SLACK_DOMAIN'],
  18. log: false,
  19. )
  20. client.authenticate
  21. expect(client.authenticated?).to be true
  22. end
  23. it 'should handle a bad credentials error' do
  24. client = SlackMattermostEmoji::SlackClient.new(
  25. username: ENV['SLACK_USERNAME'],
  26. password: 'wrongpassword',
  27. domain: ENV['SLACK_DOMAIN'],
  28. log: false,
  29. )
  30. expect { client.authenticate }.to raise_error('Invalid Slack credentials')
  31. end
  32. it 'should download emoji from slack' do
  33. download_path = File.expand_path('~/Desktop/slack-emoji')
  34. FileUtils.rm_rf(download_path) if Dir.exist?(download_path)
  35. client = SlackMattermostEmoji::SlackClient.new(
  36. username: ENV['SLACK_USERNAME'],
  37. password: ENV['SLACK_PASSWORD'],
  38. domain: ENV['SLACK_DOMAIN'],
  39. download_path: download_path,
  40. log: false,
  41. )
  42. client.authenticate
  43. emoji = client.download_emoji
  44. emoji.each do |name, image_url|
  45. next if URI(image_url).scheme == 'alias'
  46. extension = File.extname(image_url)
  47. file_name = "#{name}#{extension}"
  48. file_path = File.join(download_path, file_name)
  49. expect(File.exist?(file_path)).to be true
  50. end
  51. end
  52. end