require "dotenv/load" require "slack_mattermost_emoji/slack_client" RSpec.describe SlackMattermostEmoji::SlackClient do it 'should raise if credentials are missing' do expect do SlackMattermostEmoji::SlackClient.new( username: '', password: '', domain: '', ) end.to raise_error('Slack username, password, and domain are all required') end it 'should be able to log in to slack using the provided credentials' do client = SlackMattermostEmoji::SlackClient.new( username: ENV['SLACK_USERNAME'], password: ENV['SLACK_PASSWORD'], domain: ENV['SLACK_DOMAIN'], log: false, ) client.authenticate expect(client.authenticated?).to be true end it 'should handle a bad credentials error' do client = SlackMattermostEmoji::SlackClient.new( username: ENV['SLACK_USERNAME'], password: 'wrongpassword', domain: ENV['SLACK_DOMAIN'], log: false, ) expect { client.authenticate }.to raise_error('Invalid Slack credentials') end it 'should download emoji from slack' do download_path = File.expand_path('~/Desktop/slack-emoji') FileUtils.rm_rf(download_path) if Dir.exist?(download_path) client = SlackMattermostEmoji::SlackClient.new( username: ENV['SLACK_USERNAME'], password: ENV['SLACK_PASSWORD'], domain: ENV['SLACK_DOMAIN'], download_path: download_path, log: false, ) client.authenticate emoji = client.download_emoji emoji.each do |name, image_url| next if URI(image_url).scheme == 'alias' extension = File.extname(image_url) file_name = "#{name}#{extension}" file_path = File.join(download_path, file_name) expect(File.exist?(file_path)).to be true end end end