get_email_contacts_job_test.rb
1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require_relative "../test_helper"
class GetEmailContactsJobTest < ActiveSupport::TestCase
should 'register error' do
contact_list = ContactList.create
Invitation.expects(:get_contacts).with('from-email', 'mylogin', 'mypassword', contact_list.id).raises(Exception.new("crash"))
job = GetEmailContactsJob.new('from-email', 'mylogin', 'mypassword', contact_list.id)
job.perform
assert ContactList.find(contact_list).fetched
assert_equal 'There was an error while looking for your contact list. Please, try again', ContactList.find(contact_list).error_fetching
end
should 'register auth error' do
contact_list = ContactList.create
Invitation.expects(:get_contacts).with('from-email', 'mylogin', 'wrongpassword', contact_list.id).raises(Contacts::AuthenticationError)
job = GetEmailContactsJob.new('from-email', 'mylogin', 'wrongpassword', contact_list.id)
job.perform
assert ContactList.find(contact_list).fetched
assert_equal 'There was an error while authenticating. Did you enter correct login and password?', ContactList.find(contact_list).error_fetching
end
should 'not try to register error if has no contact list' do
contact_list = ContactList.create
Invitation.expects(:get_contacts).with('from-email', 'mylogin', 'mypassword', contact_list.id).raises(Exception.new("crash"))
job = GetEmailContactsJob.new('from-email', 'mylogin', 'mypassword', contact_list.id)
contact_list.destroy
assert_nothing_raised do
job.perform
end
end
should 'not try to register auth error if has no contact list' do
contact_list = ContactList.create
Invitation.expects(:get_contacts).with('from-email', 'mylogin', 'wrongpassword', contact_list.id).raises(Contacts::AuthenticationError)
job = GetEmailContactsJob.new('from-email', 'mylogin', 'wrongpassword', contact_list.id)
contact_list.destroy
assert_nothing_raised do
job.perform
end
end
end