passaporteweb-client 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +27 -23
- data/README.rdoc +1 -1
- data/lib/passaporte_web/version.rb +1 -1
- data/passaporteweb-client.gemspec +1 -1
- data/spec/passaporte_web/configuration_spec.rb +8 -8
- data/spec/passaporte_web/helpers_spec.rb +10 -10
- data/spec/passaporte_web/http_spec.rb +7 -7
- data/spec/passaporte_web/identity_service_account_spec.rb +60 -60
- data/spec/passaporte_web/identity_service_spec.rb +26 -26
- data/spec/passaporte_web/identity_spec.rb +117 -117
- data/spec/passaporte_web/notification_spec.rb +84 -84
- data/spec/passaporte_web/service_account_member_spec.rb +50 -50
- data/spec/passaporte_web/service_account_spec.rb +54 -54
- data/spec/passaporte_web_spec.rb +7 -7
- data/spec/spec_helper.rb +0 -4
- metadata +5 -5
@@ -10,14 +10,14 @@ describe PassaporteWeb::IdentityService do
|
|
10
10
|
describe ".new" do
|
11
11
|
it "should instanciate an (almost) empty object" do
|
12
12
|
identity_service = described_class.new(mock_identity)
|
13
|
-
identity_service.attributes.
|
14
|
-
identity_service.identity.
|
15
|
-
identity_service.slug.
|
16
|
-
identity_service.is_active.
|
13
|
+
expect(identity_service.attributes).to eq({identity: mock_identity, slug: nil, is_active: nil, service_data: nil})
|
14
|
+
expect(identity_service.identity).to eq(mock_identity)
|
15
|
+
expect(identity_service.slug).to be_nil
|
16
|
+
expect(identity_service.is_active).to be_nil
|
17
17
|
expect(identity_service.is_active?).to be_falsy
|
18
|
-
identity_service.service_data.
|
19
|
-
identity_service.errors.
|
20
|
-
identity_service.
|
18
|
+
expect(identity_service.service_data).to be_nil
|
19
|
+
expect(identity_service.errors).to be_empty
|
20
|
+
expect(identity_service).not_to be_persisted
|
21
21
|
end
|
22
22
|
it "should instanciate an object with attributes set" do
|
23
23
|
identity_service = described_class.new(mock_identity)
|
@@ -27,32 +27,32 @@ describe PassaporteWeb::IdentityService do
|
|
27
27
|
'service_data' => identity_service_data_hash
|
28
28
|
}
|
29
29
|
identity_service = described_class.new(mock_identity, attributes)
|
30
|
-
identity_service.attributes.
|
31
|
-
identity_service.identity.
|
32
|
-
identity_service.slug.
|
33
|
-
identity_service.is_active.
|
30
|
+
expect(identity_service.attributes).to eq({identity: mock_identity, slug: 'identity_client', is_active: true, service_data: identity_service_data_hash})
|
31
|
+
expect(identity_service.identity).to eq(mock_identity)
|
32
|
+
expect(identity_service.slug).to eq('identity_client')
|
33
|
+
expect(identity_service.is_active).to eq(true)
|
34
34
|
expect(identity_service.is_active?).to be_truthy
|
35
|
-
identity_service.service_data.
|
36
|
-
identity_service.errors.
|
37
|
-
identity_service.
|
35
|
+
expect(identity_service.service_data).to eq(identity_service_data_hash)
|
36
|
+
expect(identity_service.errors).to be_empty
|
37
|
+
expect(identity_service).not_to be_persisted
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
describe ".find", vcr: true do
|
42
42
|
it "should find the IdentityService representing the existing relationship between the Identity and the Service" do
|
43
43
|
identity_service = described_class.find(identity, 'identity_client')
|
44
|
-
identity_service.
|
45
|
-
identity_service.identity.
|
46
|
-
identity_service.slug.
|
44
|
+
expect(identity_service).to be_instance_of(described_class)
|
45
|
+
expect(identity_service.identity).to eq(identity)
|
46
|
+
expect(identity_service.slug).to eq('identity_client')
|
47
47
|
expect(identity_service.is_active).to be_truthy
|
48
48
|
expect(identity_service.is_active?).to be_truthy
|
49
|
-
identity_service.service_data.
|
50
|
-
identity_service.errors.
|
51
|
-
identity_service.
|
49
|
+
expect(identity_service.service_data).to be_nil
|
50
|
+
expect(identity_service.errors).to be_empty
|
51
|
+
expect(identity_service).to be_persisted
|
52
52
|
end
|
53
53
|
it "should return nil it the Identity does not have a relationship with the Service" do
|
54
54
|
other_identity = PassaporteWeb::Identity.find('840df3bd-8414-4085-9920-1937f4b37dd3')
|
55
|
-
described_class.find(other_identity, 'identity_client').
|
55
|
+
expect(described_class.find(other_identity, 'identity_client')).to be_nil
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -66,20 +66,20 @@ describe PassaporteWeb::IdentityService do
|
|
66
66
|
}
|
67
67
|
identity_service = described_class.new(other_identity, attributes)
|
68
68
|
expect(identity_service.save).to be_truthy
|
69
|
-
identity_service.service_data.
|
69
|
+
expect(identity_service.service_data).to eq(identity_service_data_hash_as_strings)
|
70
70
|
|
71
71
|
identity_service = described_class.find(other_identity, 'identity_client')
|
72
|
-
identity_service.service_data.
|
72
|
+
expect(identity_service.service_data).to eq(identity_service_data_hash_as_strings)
|
73
73
|
end
|
74
74
|
it "should update the relationship between Identity and Service with extra data" do
|
75
75
|
identity_service = described_class.find(identity, 'identity_client')
|
76
|
-
identity_service.service_data.
|
76
|
+
expect(identity_service.service_data).to be_empty
|
77
77
|
identity_service.service_data = identity_service_data_hash
|
78
78
|
expect(identity_service.save).to be_truthy
|
79
|
-
identity_service.service_data.
|
79
|
+
expect(identity_service.service_data).to eq(identity_service_data_hash_as_strings)
|
80
80
|
|
81
81
|
identity_service = described_class.find(identity, 'identity_client')
|
82
|
-
identity_service.service_data.
|
82
|
+
expect(identity_service.service_data).to eq(identity_service_data_hash_as_strings)
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
@@ -4,15 +4,15 @@ require 'spec_helper'
|
|
4
4
|
describe PassaporteWeb::Identity do
|
5
5
|
|
6
6
|
describe "constants" do
|
7
|
-
it { described_class::ATTRIBUTES.
|
8
|
-
it { described_class::UPDATABLE_ATTRIBUTES.
|
9
|
-
it { described_class::CREATABLE_ATTRIBUTES.
|
7
|
+
it { expect(described_class::ATTRIBUTES).to eq([:accounts, :birth_date, :country, :cpf, :email, :first_name, :gender, :id_token, :is_active, :language, :last_name, :nickname, :notifications, :send_myfreecomm_news, :send_partner_news, :services, :timezone, :update_info_url, :uuid, :password, :password2, :must_change_password, :inhibit_activation_message, :tos, :bio, :position, :city, :company, :profession, :identity_info_url, :state, :email_list]) }
|
8
|
+
it { expect(described_class::UPDATABLE_ATTRIBUTES).to eq([:first_name, :last_name, :nickname, :cpf, :birth_date, :gender, :send_myfreecomm_news, :send_partner_news, :country, :language, :timezone, :bio, :position, :city, :company, :profession, :state]) }
|
9
|
+
it { expect(described_class::CREATABLE_ATTRIBUTES).to eq([:first_name, :last_name, :nickname, :cpf, :birth_date, :gender, :send_myfreecomm_news, :send_partner_news, :country, :language, :timezone, :bio, :position, :city, :company, :profession, :state, :email, :password, :password2, :must_change_password, :tos, :inhibit_activation_message]) }
|
10
10
|
end
|
11
11
|
|
12
12
|
describe ".new" do
|
13
13
|
it "should instanciate an empty object" do
|
14
14
|
identity = described_class.new
|
15
|
-
identity.attributes.
|
15
|
+
expect(identity.attributes).to eq({:accounts=>nil, :birth_date=>nil, :country=>nil, :cpf=>nil, :email=>nil, :first_name=>nil, :gender=>nil, :id_token=>nil, :is_active=>nil, :language=>nil, :last_name=>nil, :nickname=>nil, :notifications=>nil, :send_myfreecomm_news=>nil, :send_partner_news=>nil, :services=>nil, :timezone=>nil, :update_info_url=>nil, :uuid=>nil, :password=>nil, :password2=>nil, :must_change_password=>nil, :inhibit_activation_message=>nil, :tos=>nil, :bio=>nil, :position=>nil, :city=>nil, :company=>nil, :profession=>nil, :identity_info_url=>nil, :state=>nil, :email_list=>nil})
|
16
16
|
end
|
17
17
|
it "should instanciate an object with attributes set" do
|
18
18
|
attributes = {
|
@@ -46,29 +46,29 @@ describe PassaporteWeb::Identity do
|
|
46
46
|
"tos"=>nil
|
47
47
|
}
|
48
48
|
identity = described_class.new(attributes)
|
49
|
-
identity.attributes.
|
50
|
-
identity.last_name.
|
51
|
-
identity.is_active.
|
52
|
-
identity.timezone.
|
53
|
-
identity.nickname.
|
54
|
-
identity.first_name.
|
55
|
-
identity.send_partner_news.
|
56
|
-
identity.uuid.
|
57
|
-
identity.language.
|
58
|
-
identity.country.
|
59
|
-
identity.update_info_url.
|
60
|
-
identity.send_myfreecomm_news.
|
61
|
-
identity.gender.
|
62
|
-
identity.birth_date.
|
63
|
-
identity.email.
|
64
|
-
identity.notifications.
|
65
|
-
identity.accounts.
|
66
|
-
identity.services.
|
67
|
-
identity.password.
|
68
|
-
identity.password2.
|
69
|
-
identity.must_change_password.
|
70
|
-
identity.inhibit_activation_message.
|
71
|
-
identity.tos.
|
49
|
+
expect(identity.attributes).to eq({:accounts=>[], :birth_date=>"1945-10-27", :country=>"Brasil", :cpf=>nil, :email=>"lula@example.com", :first_name=>"Luis Inácio", :gender=>"M", :id_token=>nil, :is_active=>true, :language=>"pt_BR", :last_name=>"da Silva", :nickname=>"Lula", :notifications=>{"count"=>0, "list"=>"/notifications/api/"}, :send_myfreecomm_news=>false, :send_partner_news=>false, :services=>{"myfinance"=>"/accounts/api/service-info/a5868d14-6529-477a-9c6b-a09dd42a7cd2/myfinance/", "account_manager"=>"/accounts/api/service-info/a5868d14-6529-477a-9c6b-a09dd42a7cd2/account_manager/"}, :timezone=>"GMT-3", :update_info_url=>"/profile/api/info/a5868d14-6529-477a-9c6b-a09dd42a7cd2/", :uuid=>"a5868d14-6529-477a-9c6b-a09dd42a7cd2", :password=>nil, :password2=>nil, :must_change_password=>nil, :inhibit_activation_message=>nil, :tos=>nil, :bio=>nil, :position=>nil, :city=>nil, :company=>nil, :profession=>nil, :identity_info_url=>nil, :state=>nil, :email_list=>nil})
|
50
|
+
expect(identity.last_name).to eq("da Silva")
|
51
|
+
expect(identity.is_active).to eq(true)
|
52
|
+
expect(identity.timezone).to eq("GMT-3")
|
53
|
+
expect(identity.nickname).to eq("Lula")
|
54
|
+
expect(identity.first_name).to eq("Luis Inácio")
|
55
|
+
expect(identity.send_partner_news).to eq(false)
|
56
|
+
expect(identity.uuid).to eq("a5868d14-6529-477a-9c6b-a09dd42a7cd2")
|
57
|
+
expect(identity.language).to eq("pt_BR")
|
58
|
+
expect(identity.country).to eq("Brasil")
|
59
|
+
expect(identity.update_info_url).to eq("/profile/api/info/a5868d14-6529-477a-9c6b-a09dd42a7cd2/")
|
60
|
+
expect(identity.send_myfreecomm_news).to eq(false)
|
61
|
+
expect(identity.gender).to eq("M")
|
62
|
+
expect(identity.birth_date).to eq("1945-10-27")
|
63
|
+
expect(identity.email).to eq("lula@example.com")
|
64
|
+
expect(identity.notifications).to eq({"count" => 0, "list" => "/notifications/api/"})
|
65
|
+
expect(identity.accounts).to eq([])
|
66
|
+
expect(identity.services).to eq({"myfinance" => "/accounts/api/service-info/a5868d14-6529-477a-9c6b-a09dd42a7cd2/myfinance/", "account_manager" => "/accounts/api/service-info/a5868d14-6529-477a-9c6b-a09dd42a7cd2/account_manager/"})
|
67
|
+
expect(identity.password).to be_nil
|
68
|
+
expect(identity.password2).to be_nil
|
69
|
+
expect(identity.must_change_password).to be_nil
|
70
|
+
expect(identity.inhibit_activation_message).to be_nil
|
71
|
+
expect(identity.tos).to be_nil
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -76,60 +76,60 @@ describe PassaporteWeb::Identity do
|
|
76
76
|
it "should identify two profiles with the same uuid as equal" do
|
77
77
|
p1 = described_class.new('uuid' => 'some-uuid')
|
78
78
|
p2 = described_class.new('uuid' => 'some-uuid')
|
79
|
-
p1.
|
80
|
-
p1.
|
81
|
-
p2.
|
82
|
-
p2.
|
79
|
+
expect(p1).to eq(p2)
|
80
|
+
expect(p1).not_to be === p2
|
81
|
+
expect(p2).to eq(p1)
|
82
|
+
expect(p2).not_to be === p1
|
83
83
|
end
|
84
84
|
it "should identify two profiles with different uuids as different" do
|
85
85
|
p1 = described_class.new('uuid' => 'some-uuid-1')
|
86
86
|
p2 = described_class.new('uuid' => 'some-uuid-2')
|
87
|
-
p1.
|
88
|
-
p1.
|
89
|
-
p2.
|
90
|
-
p2.
|
87
|
+
expect(p1).not_to eq(p2)
|
88
|
+
expect(p1).not_to be === p2
|
89
|
+
expect(p2).not_to eq(p1)
|
90
|
+
expect(p2).not_to be === p1
|
91
91
|
p3 = described_class.new
|
92
|
-
p1.
|
93
|
-
p3.
|
94
|
-
p3.
|
92
|
+
expect(p1).not_to eq(p3)
|
93
|
+
expect(p3).not_to eq(p1)
|
94
|
+
expect(p3).not_to be === p1
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
98
|
describe ".find", :vcr => true do
|
99
99
|
it "should find the requested profile by uuid" do
|
100
100
|
identity = described_class.find("5e32f927-c4ab-404e-a91c-b2abc05afb56")
|
101
|
-
identity.
|
102
|
-
identity.uuid.
|
103
|
-
identity.
|
104
|
-
identity.email.
|
105
|
-
identity.update_info_url.
|
106
|
-
identity.accounts.size.
|
107
|
-
identity.accounts.map { |a| a['expiration'] }.uniq.
|
108
|
-
identity.accounts.map { |a| a['services'] }.flatten.uniq.map { |s| s['slug'] rescue nil }.sort.
|
101
|
+
expect(identity).to be_instance_of(described_class)
|
102
|
+
expect(identity.uuid).to eq('5e32f927-c4ab-404e-a91c-b2abc05afb56')
|
103
|
+
expect(identity).to be_persisted
|
104
|
+
expect(identity.email).to eq('teste@teste.com')
|
105
|
+
expect(identity.update_info_url).to eq('/accounts/api/identities/5e32f927-c4ab-404e-a91c-b2abc05afb56/')
|
106
|
+
expect(identity.accounts.size).to eq(9)
|
107
|
+
expect(identity.accounts.map { |a| a['expiration'] }.uniq).to eq([nil, "2014-05-01 00:00:00"])
|
108
|
+
expect(identity.accounts.map { |a| a['services'] }.flatten.uniq.map { |s| s['slug'] rescue nil }.sort).to eq([nil])
|
109
109
|
end
|
110
110
|
it "should find the requested profile by uuid, including expired accounts" do
|
111
111
|
identity = described_class.find("5e32f927-c4ab-404e-a91c-b2abc05afb56", true)
|
112
|
-
identity.accounts.size.
|
113
|
-
identity.accounts.map { |a| a['expiration'] }.uniq.
|
114
|
-
identity.accounts.map { |a| a['services'] }.flatten.uniq.map { |s| s['slug'] rescue nil }.sort.
|
112
|
+
expect(identity.accounts.size).to eq(10)
|
113
|
+
expect(identity.accounts.map { |a| a['expiration'] }.uniq).to eq([nil, "2013-04-02 00:00:00", "2014-05-01 00:00:00"])
|
114
|
+
expect(identity.accounts.map { |a| a['services'] }.flatten.uniq.map { |s| s['slug'] rescue nil }.sort).to eq([nil])
|
115
115
|
end
|
116
116
|
it "should find the requested profile by uuid, including other services" do
|
117
117
|
identity = described_class.find("5e32f927-c4ab-404e-a91c-b2abc05afb56", false, true)
|
118
|
-
identity.accounts.size.
|
119
|
-
identity.accounts.map { |a| a['expiration'] }.uniq.
|
120
|
-
identity.accounts.map { |a| a['services'] }.flatten.uniq.map { |s| s['slug'] }.sort.
|
118
|
+
expect(identity.accounts.size).to eq(10)
|
119
|
+
expect(identity.accounts.map { |a| a['expiration'] }.uniq).to eq([nil, "2014-05-01 00:00:00"])
|
120
|
+
expect(identity.accounts.map { |a| a['services'] }.flatten.uniq.map { |s| s['slug'] }.sort).to eq(["identity_client", "vc-promove"])
|
121
121
|
end
|
122
122
|
it "should find the requested profile by uuid, including other services and expired accounts" do
|
123
123
|
identity = described_class.find("5e32f927-c4ab-404e-a91c-b2abc05afb56", true, true)
|
124
|
-
identity.accounts.size.
|
125
|
-
identity.accounts.map { |a| a['expiration'] }.uniq.
|
126
|
-
identity.accounts.map { |a| a['services'] }.flatten.uniq.map { |s| s['slug'] }.sort.
|
124
|
+
expect(identity.accounts.size).to eq(11)
|
125
|
+
expect(identity.accounts.map { |a| a['expiration'] }.uniq).to eq([nil, "2013-04-02 00:00:00", "2014-05-01 00:00:00"])
|
126
|
+
expect(identity.accounts.map { |a| a['services'] }.flatten.uniq.map { |s| s['slug'] }.sort).to eq(["identity_client", "vc-promove"])
|
127
127
|
end
|
128
128
|
# REGRSSION
|
129
129
|
it "should return the is_active and id_token fields" do
|
130
130
|
identity = described_class.find('13b972ab-0946-4a5b-8217-60255a9cbee7', true, true)
|
131
131
|
expect(identity.is_active).to be_truthy
|
132
|
-
identity.id_token.
|
132
|
+
expect(identity.id_token).to be_nil # não mostra token pois não foi autenticado com a senha do usuário
|
133
133
|
end
|
134
134
|
it "should raise an error if no profiles exist with that uuid" do
|
135
135
|
expect {
|
@@ -141,42 +141,42 @@ describe PassaporteWeb::Identity do
|
|
141
141
|
describe ".find_by_email", :vcr => true do
|
142
142
|
it "should find the requested profile by email" do
|
143
143
|
identity = described_class.find_by_email("teste@teste.com")
|
144
|
-
identity.
|
145
|
-
identity.uuid.
|
146
|
-
identity.
|
147
|
-
identity.email.
|
148
|
-
identity.update_info_url.
|
149
|
-
identity.accounts.size.
|
150
|
-
identity.accounts.map { |a| a['expiration'] }.uniq.
|
151
|
-
identity.accounts.map { |a| a['services'] }.flatten.uniq.map { |s| s['slug'] rescue nil }.sort.
|
152
|
-
identity.services.size.
|
153
|
-
identity.services.keys.
|
144
|
+
expect(identity).to be_instance_of(described_class)
|
145
|
+
expect(identity.uuid).to eq('5e32f927-c4ab-404e-a91c-b2abc05afb56')
|
146
|
+
expect(identity).to be_persisted
|
147
|
+
expect(identity.email).to eq('teste@teste.com')
|
148
|
+
expect(identity.update_info_url).to eq('/accounts/api/identities/5e32f927-c4ab-404e-a91c-b2abc05afb56/')
|
149
|
+
expect(identity.accounts.size).to eq(9)
|
150
|
+
expect(identity.accounts.map { |a| a['expiration'] }.uniq).to eq([nil, "2014-05-01 00:00:00"])
|
151
|
+
expect(identity.accounts.map { |a| a['services'] }.flatten.uniq.map { |s| s['slug'] rescue nil }.sort).to eq([nil])
|
152
|
+
expect(identity.services.size).to eq(1)
|
153
|
+
expect(identity.services.keys).to eq(['identity_client'])
|
154
154
|
end
|
155
155
|
it "should find the requested profile by email, including expired accounts" do
|
156
156
|
identity = described_class.find_by_email("teste@teste.com", true)
|
157
|
-
identity.accounts.size.
|
158
|
-
identity.accounts.map { |a| a['expiration'] }.uniq.
|
159
|
-
identity.accounts.map { |a| a['services'] }.flatten.uniq.map { |s| s['slug'] rescue nil }.sort.
|
160
|
-
identity.services.size.
|
161
|
-
identity.services.keys.
|
157
|
+
expect(identity.accounts.size).to eq(10)
|
158
|
+
expect(identity.accounts.map { |a| a['expiration'] }.uniq).to eq([nil, "2013-04-02 00:00:00", "2014-05-01 00:00:00"])
|
159
|
+
expect(identity.accounts.map { |a| a['services'] }.flatten.uniq.map { |s| s['slug'] rescue nil }.sort).to eq([nil])
|
160
|
+
expect(identity.services.size).to eq(1)
|
161
|
+
expect(identity.services.keys).to eq(['identity_client'])
|
162
162
|
end
|
163
163
|
it "should find the requested profile by email, including other services" do
|
164
164
|
identity = described_class.find_by_email("teste@teste.com", false, true)
|
165
|
-
identity.accounts.size.
|
166
|
-
identity.accounts.map { |a| a['expiration'] }.uniq.
|
167
|
-
identity.accounts.map { |a| a['services'] }.flatten.uniq.map { |s| s['slug'] }.sort.
|
165
|
+
expect(identity.accounts.size).to eq(10)
|
166
|
+
expect(identity.accounts.map { |a| a['expiration'] }.uniq).to eq([nil, "2014-05-01 00:00:00"])
|
167
|
+
expect(identity.accounts.map { |a| a['services'] }.flatten.uniq.map { |s| s['slug'] }.sort).to eq(["identity_client", "vc-promove"])
|
168
168
|
end
|
169
169
|
it "should find the requested profile by email, including other services and expired accounts" do
|
170
170
|
identity = described_class.find_by_email("teste@teste.com", true, true)
|
171
|
-
identity.accounts.size.
|
172
|
-
identity.accounts.map { |a| a['expiration'] }.uniq.
|
173
|
-
identity.accounts.map { |a| a['services'] }.flatten.uniq.map { |s| s['slug'] }.sort.
|
171
|
+
expect(identity.accounts.size).to eq(11)
|
172
|
+
expect(identity.accounts.map { |a| a['expiration'] }.uniq).to eq([nil, "2013-04-02 00:00:00", "2014-05-01 00:00:00"])
|
173
|
+
expect(identity.accounts.map { |a| a['services'] }.flatten.uniq.map { |s| s['slug'] }.sort).to eq(["identity_client", "vc-promove"])
|
174
174
|
end
|
175
175
|
# REGRSSION
|
176
176
|
it "should return the is_active and id_token fields" do
|
177
177
|
identity = described_class.find_by_email('mobileteste269@mailinator.com', true, true)
|
178
178
|
expect(identity.is_active).to be_truthy
|
179
|
-
identity.id_token.
|
179
|
+
expect(identity.id_token).to be_nil # não mostra token pois não foi autenticado com a senha do usuário
|
180
180
|
end
|
181
181
|
it "should raise an error if no profiles exist with that email" do
|
182
182
|
expect {
|
@@ -188,27 +188,27 @@ describe PassaporteWeb::Identity do
|
|
188
188
|
describe ".profile", :vcr => true do
|
189
189
|
it "should find the requested profile by email" do
|
190
190
|
identity = described_class.profile('8923199e-6c43-415a-bbd1-2e302fdf8d96')
|
191
|
-
identity.
|
192
|
-
identity.bio.
|
193
|
-
identity.position.
|
194
|
-
identity.language.
|
195
|
-
identity.city.
|
196
|
-
identity.gender.
|
197
|
-
identity.company.
|
198
|
-
identity.profession.
|
199
|
-
identity.identity_info_url.
|
200
|
-
identity.state.
|
201
|
-
identity.country.
|
202
|
-
identity.birth_date.
|
203
|
-
identity.timezone.
|
204
|
-
identity.nickname.
|
205
|
-
identity.email_list.count.
|
191
|
+
expect(identity).to be_instance_of(described_class)
|
192
|
+
expect(identity.bio).to eq('I\'m the Kingslayer!')
|
193
|
+
expect(identity.position).to eq('Knight')
|
194
|
+
expect(identity.language).to eq('ur')
|
195
|
+
expect(identity.city).to eq('Casterly Rock')
|
196
|
+
expect(identity.gender).to eq('M')
|
197
|
+
expect(identity.company).to eq('Lannister House')
|
198
|
+
expect(identity.profession).to eq('Kingslayer')
|
199
|
+
expect(identity.identity_info_url).to eq('http://sandbox.app.passaporteweb.com.br/accounts/api/identities/8923199e-6c43-415a-bbd1-2e302fdf8d96/')
|
200
|
+
expect(identity.state).to eq('AC')
|
201
|
+
expect(identity.country).to eq('Westeros')
|
202
|
+
expect(identity.birth_date).to eq('1950-01-01')
|
203
|
+
expect(identity.timezone).to eq('Pacific/Midway')
|
204
|
+
expect(identity.nickname).to eq('Jaime')
|
205
|
+
expect(identity.email_list.count).to eq(2)
|
206
206
|
# Primary e-mail
|
207
|
-
identity.email_list[0]['address'].
|
207
|
+
expect(identity.email_list[0]['address']).to eq('jaime.lannister@mailinator.com')
|
208
208
|
expect(identity.email_list[0]['is_primary']).to be_truthy
|
209
209
|
expect(identity.email_list[0]['is_active']).to be_truthy
|
210
210
|
# Secondary email
|
211
|
-
identity.email_list[1]['address'].
|
211
|
+
expect(identity.email_list[1]['address']).to eq('kingslayer@mailinator.com')
|
212
212
|
expect(identity.email_list[1]['is_primary']).to be_falsy
|
213
213
|
expect(identity.email_list[1]['is_active']).to be_truthy
|
214
214
|
end
|
@@ -222,17 +222,17 @@ describe PassaporteWeb::Identity do
|
|
222
222
|
describe ".authenticate", vcr: true do
|
223
223
|
it "should return an instance of Identity if the password is correct for the given email" do
|
224
224
|
identity = described_class.authenticate('teste@teste.com', '123456')
|
225
|
-
identity.
|
226
|
-
identity.
|
227
|
-
identity.uuid.
|
228
|
-
identity.email.
|
229
|
-
identity.update_info_url.
|
225
|
+
expect(identity).to be_instance_of(described_class)
|
226
|
+
expect(identity).to be_persisted
|
227
|
+
expect(identity.uuid).to eq('5e32f927-c4ab-404e-a91c-b2abc05afb56')
|
228
|
+
expect(identity.email).to eq('teste@teste.com')
|
229
|
+
expect(identity.update_info_url).to eq('/accounts/api/identities/5e32f927-c4ab-404e-a91c-b2abc05afb56/')
|
230
230
|
end
|
231
231
|
# REGRSSION
|
232
232
|
it "should return the is_active and id_token fields" do
|
233
233
|
identity = described_class.authenticate('mobileteste269@mailinator.com', 'vivalasvegas')
|
234
234
|
expect(identity.is_active).to be_truthy
|
235
|
-
identity.id_token.
|
235
|
+
expect(identity.id_token).to eq('9864ec27fb4fd866f6fad5bc041d0363d0bc0fd2945858a1')
|
236
236
|
end
|
237
237
|
it "should return false if the password is wrong for the given email" do
|
238
238
|
expect(described_class.authenticate('teste@teste.com', 'wrong password')).to be_falsy
|
@@ -263,24 +263,24 @@ describe PassaporteWeb::Identity do
|
|
263
263
|
let(:identity) { described_class.find("5e32f927-c4ab-404e-a91c-b2abc05afb56") }
|
264
264
|
context "on success" do
|
265
265
|
it "should update the profile attributes on the server" do
|
266
|
-
identity.first_name.
|
267
|
-
identity.
|
266
|
+
expect(identity.first_name).to eq('Testador')
|
267
|
+
expect(identity).to be_persisted
|
268
268
|
identity.first_name = 'Testador 2'
|
269
269
|
expect(identity.save).to be_truthy
|
270
|
-
identity.
|
271
|
-
identity.first_name.
|
270
|
+
expect(identity).to be_persisted
|
271
|
+
expect(identity.first_name).to eq('Testador 2')
|
272
272
|
|
273
273
|
identity = described_class.find("5e32f927-c4ab-404e-a91c-b2abc05afb56")
|
274
|
-
identity.first_name.
|
274
|
+
expect(identity.first_name).to eq('Testador 2')
|
275
275
|
end
|
276
276
|
end
|
277
277
|
context "on failure" do
|
278
278
|
it "should return false and set the errors hash" do
|
279
279
|
identity.cpf = 42
|
280
|
-
identity.
|
280
|
+
expect(identity).to be_persisted
|
281
281
|
expect(identity.save).to be_falsy
|
282
|
-
identity.
|
283
|
-
identity.errors.
|
282
|
+
expect(identity).to be_persisted
|
283
|
+
expect(identity.errors).to eq({"cpf" => ["Certifique-se de que o valor tenha no mínimo 11 caracteres (ele possui 2)."]})
|
284
284
|
end
|
285
285
|
end
|
286
286
|
end
|
@@ -297,9 +297,9 @@ describe PassaporteWeb::Identity do
|
|
297
297
|
"tos" => true
|
298
298
|
}
|
299
299
|
identity = described_class.new(attributes)
|
300
|
-
identity.
|
300
|
+
expect(identity).not_to be_persisted
|
301
301
|
expect(identity.save).to be_truthy
|
302
|
-
identity.
|
302
|
+
expect(identity).to be_persisted
|
303
303
|
end
|
304
304
|
it "should save with all params" do
|
305
305
|
attributes = {
|
@@ -316,9 +316,9 @@ describe PassaporteWeb::Identity do
|
|
316
316
|
"send_myfreecomm_news" => false
|
317
317
|
}
|
318
318
|
identity = described_class.new(attributes)
|
319
|
-
identity.
|
319
|
+
expect(identity).not_to be_persisted
|
320
320
|
expect(identity.save).to be_truthy
|
321
|
-
identity.
|
321
|
+
expect(identity).to be_persisted
|
322
322
|
end
|
323
323
|
# REGRESSION
|
324
324
|
it "should send the inhibit_activation_message information" do
|
@@ -333,7 +333,7 @@ describe PassaporteWeb::Identity do
|
|
333
333
|
}
|
334
334
|
identity = described_class.new(attributes)
|
335
335
|
mock_response = double('response', code: 201, body: MultiJson.encode(attributes))
|
336
|
-
PassaporteWeb::Http.
|
336
|
+
expect(PassaporteWeb::Http).to receive(:post).with("/accounts/api/create/", attributes).and_return(mock_response)
|
337
337
|
expect(identity.save).to be_truthy
|
338
338
|
end
|
339
339
|
end
|
@@ -346,10 +346,10 @@ describe PassaporteWeb::Identity do
|
|
346
346
|
"tos" => true
|
347
347
|
}
|
348
348
|
identity = described_class.new(attributes)
|
349
|
-
identity.
|
349
|
+
expect(identity).to_not be_persisted
|
350
350
|
expect(identity.save).to_not be_truthy
|
351
|
-
identity.
|
352
|
-
identity.errors.
|
351
|
+
expect(identity).to_not be_persisted
|
352
|
+
expect(identity.errors).to eq({"password2"=>["Este campo é obrigatório."], "password"=>["Este campo é obrigatório."]})
|
353
353
|
end
|
354
354
|
end
|
355
355
|
end
|