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.5KB

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