|
7 | 7 |
|
8 | 8 | let(:uid) { 'example-uid' } |
9 | 9 | let(:session_params) { {saml_uid: uid, omniauth_provider: 'nbp'} } |
| 10 | + let(:relationship) { instance_double(Enmeshed::Relationship) } |
10 | 11 |
|
11 | 12 | before do |
12 | 13 | set_session(session_params) |
13 | 14 | end |
14 | 15 |
|
15 | 16 | context 'without any errors' do |
16 | | - let(:relationship) do |
17 | | - instance_double(Enmeshed::Relationship, |
18 | | - accept!: true, |
19 | | - userdata: { |
20 | | - |
21 | | - first_name: 'john', |
22 | | - last_name: 'oliver', |
23 | | - status_group: 'learner', |
24 | | - }) |
25 | | - end |
26 | | - |
27 | 17 | before do |
28 | 18 | allow(Enmeshed::Relationship).to receive(:pending_for).with(uid).and_return(relationship) |
29 | | - allow(relationship).to receive(:peer).and_return('id1EvvJ68x6wdHBwYrFTR31XtALHko9fnbyp') |
| 19 | + allow(relationship).to receive_messages(peer: 'id1EvvJ68x6wdHBwYrFTR31XtALHko9fnbyp', accept!: true, |
| 20 | + userdata: {email: '[email protected]', first_name: 'john', last_name: 'oliver', status_group: :learner}) |
30 | 21 | end |
31 | 22 |
|
32 | 23 | it 'creates a user' do |
|
112 | 103 | end |
113 | 104 |
|
114 | 105 | context 'when an attribute is missing' do |
115 | | - # `Enmeshed::ConnectorError` is unknown until 'lib/enmeshed/connector.rb' is loaded, because it's defined there |
116 | | - require 'enmeshed/connector' |
117 | | - |
118 | | - let(:relationship) do |
119 | | - instance_double(Enmeshed::Relationship, accept!: false, reject!: true) |
120 | | - end |
121 | | - |
122 | 106 | before do |
123 | 107 | allow(Enmeshed::Relationship).to receive(:pending_for).with(uid).and_return(relationship) |
124 | | - allow(relationship).to receive(:userdata).and_raise(Enmeshed::ConnectorError, 'EMailAddress must not be empty') |
| 108 | + allow(relationship).to receive_messages( |
| 109 | + userdata: {first_name: 'john', last_name: 'oliver', status_group: :learner}, |
| 110 | + peer: 'id1EvvJ68x6wdHBwYrFTR31XtALHko9fnbyp', |
| 111 | + reject!: true |
| 112 | + ) |
125 | 113 | end |
126 | 114 |
|
127 | | - it_behaves_like 'a handled erroneous request', I18n.t('common.errors.generic') |
128 | | - it_behaves_like 'a documented erroneous request', Enmeshed::ConnectorError |
| 115 | + it_behaves_like 'a handled erroneous request', "Could not create User: Email can't be blank" |
129 | 116 | end |
130 | 117 |
|
131 | 118 | context 'with an invalid status group' do |
132 | | - let(:relationship) do |
133 | | - instance_double(Enmeshed::Relationship, |
134 | | - reject!: true, |
135 | | - userdata: { |
136 | | - |
137 | | - first_name: 'john', |
138 | | - last_name: 'oliver', |
139 | | - status_group: nil, |
140 | | - }) |
141 | | - end |
142 | | - |
143 | 119 | before do |
144 | 120 | allow(Enmeshed::Relationship).to receive(:pending_for).with(uid).and_return(relationship) |
| 121 | + allow(relationship).to receive_messages(reject!: true, peer: 'id1EvvJ68x6wdHBwYrFTR31XtALHko9fnbyp', userdata: { |
| 122 | + |
| 123 | + first_name: 'john', |
| 124 | + last_name: 'oliver', |
| 125 | + status_group: nil, |
| 126 | + }) |
145 | 127 | end |
146 | 128 |
|
147 | | - it_behaves_like 'a handled erroneous request', 'Could not create User: Unknown role. Please select either ' \ |
148 | | - '"Teacher" or "Student" as your role.' |
| 129 | + it_behaves_like 'a handled erroneous request', 'Could not create User: Status Group is unknown. ' \ |
| 130 | + 'Please select either "Teacher" or "Student" as your role.' |
149 | 131 | end |
150 | 132 |
|
151 | | - context 'when the User cannot be saved' do |
152 | | - let(:relationship) do |
153 | | - instance_double(Enmeshed::Relationship, |
154 | | - reject!: true, |
155 | | - userdata: { |
156 | | - |
157 | | - first_name: 'john', |
158 | | - last_name: 'oliver', |
159 | | - status_group: 'learner', |
160 | | - }) |
| 133 | + context 'with a blank name' do |
| 134 | + before do |
| 135 | + allow(Enmeshed::Relationship).to receive(:pending_for).with(uid).and_return(relationship) |
| 136 | + allow(relationship).to receive_messages( |
| 137 | + userdata: {email: '[email protected]', first_name: ' ', last_name: 'oliver', status_group: :learner}, |
| 138 | + peer: 'id1EvvJ68x6wdHBwYrFTR31XtALHko9fnbyp', |
| 139 | + reject!: true |
| 140 | + ) |
161 | 141 | end |
162 | 142 |
|
| 143 | + it_behaves_like 'a handled erroneous request', "Could not create User: First Name can't be blank" |
| 144 | + end |
| 145 | + |
| 146 | + context 'when email address already has been taken' do |
163 | 147 | before do |
164 | | - create(:user, email: relationship.userdata[:email]) |
| 148 | + create(:user, email: '[email protected]') |
165 | 149 | allow(Enmeshed::Relationship).to receive(:pending_for).with(uid).and_return(relationship) |
166 | | - allow(relationship).to receive(:peer).and_return('id1EvvJ68x6wdHBwYrFTR31XtALHko9fnbyp') |
| 150 | + allow(relationship).to receive_messages( |
| 151 | + userdata: {email: '[email protected]', first_name: 'john', last_name: 'oliver', status_group: :learner}, |
| 152 | + peer: 'id1EvvJ68x6wdHBwYrFTR31XtALHko9fnbyp', |
| 153 | + reject!: true |
| 154 | + ) |
167 | 155 | end |
168 | 156 |
|
169 | 157 | it_behaves_like 'a handled erroneous request', 'Could not create User: Email has already been taken' |
170 | 158 | end |
171 | 159 |
|
172 | 160 | context 'when the RelationshipChange cannot be accepted' do |
173 | | - let(:relationship) do |
174 | | - instance_double(Enmeshed::Relationship, |
175 | | - accept!: false, |
176 | | - reject!: true, |
177 | | - userdata: { |
178 | | - |
179 | | - first_name: 'john', |
180 | | - last_name: 'oliver', |
181 | | - status_group: 'learner', |
182 | | - }) |
183 | | - end |
184 | | - |
185 | 161 | before do |
186 | 162 | allow(Enmeshed::Relationship).to receive(:pending_for).with(uid).and_return(relationship) |
187 | | - allow(relationship).to receive(:peer).and_return('id1EvvJ68x6wdHBwYrFTR31XtALHko9fnbyp') |
| 163 | + allow(relationship).to receive_messages( |
| 164 | + userdata: {email: '[email protected]', first_name: 'john', last_name: 'oliver', status_group: :learner}, |
| 165 | + peer: 'id1EvvJ68x6wdHBwYrFTR31XtALHko9fnbyp', |
| 166 | + accept!: false, |
| 167 | + reject!: true |
| 168 | + ) |
188 | 169 | end |
189 | 170 |
|
190 | 171 | it_behaves_like 'a handled erroneous request', I18n.t('common.errors.generic') |
|
0 commit comments