|
@@ -11,20 +11,19 @@ afterEach(() => {
|
11
|
11
|
});
|
12
|
12
|
|
13
|
13
|
test('isLoggedIn yes', () => {
|
14
|
|
- jest.spyOn(ConnectionManager.prototype, 'recoverLogin').mockImplementationOnce(() => {
|
15
|
|
- return Promise.resolve(true);
|
|
14
|
+ jest.spyOn(ConnectionManager.prototype, 'getToken').mockImplementationOnce(() => {
|
|
15
|
+ return 'token';
|
16
|
16
|
});
|
17
|
|
- return expect(c.isLoggedIn()).resolves.toBe(true);
|
|
17
|
+ return expect(c.isLoggedIn()).toBe(true);
|
18
|
18
|
});
|
19
|
19
|
|
20
|
20
|
test('isLoggedIn no', () => {
|
21
|
|
- jest.spyOn(ConnectionManager.prototype, 'recoverLogin').mockImplementationOnce(() => {
|
22
|
|
- return Promise.reject(false);
|
|
21
|
+ jest.spyOn(ConnectionManager.prototype, 'getToken').mockImplementationOnce(() => {
|
|
22
|
+ return null;
|
23
|
23
|
});
|
24
|
|
- return expect(c.isLoggedIn()).rejects.toBe(false);
|
|
24
|
+ return expect(c.isLoggedIn()).toBe(false);
|
25
|
25
|
});
|
26
|
26
|
|
27
|
|
-
|
28
|
27
|
test('recoverLogin error crypto', () => {
|
29
|
28
|
jest.spyOn(SecureStore, 'getItemAsync').mockImplementationOnce(() => {
|
30
|
29
|
return Promise.reject();
|
|
@@ -111,7 +110,12 @@ test("isConnectionResponseValid", () => {
|
111
|
110
|
state: false,
|
112
|
111
|
};
|
113
|
112
|
expect(c.isConnectionResponseValid(json)).toBeTrue();
|
114
|
|
-
|
|
113
|
+ json = {
|
|
114
|
+ state: false,
|
|
115
|
+ message: 'Adresse mail ou mot de passe incorrect',
|
|
116
|
+ token: ''
|
|
117
|
+ };
|
|
118
|
+ expect(c.isConnectionResponseValid(json)).toBeTrue();
|
115
|
119
|
json = {
|
116
|
120
|
state: true,
|
117
|
121
|
message: 'Connexion confirmée',
|
|
@@ -143,7 +147,6 @@ test("isConnectionResponseValid", () => {
|
143
|
147
|
expect(c.isConnectionResponseValid(json)).toBeFalse();
|
144
|
148
|
});
|
145
|
149
|
|
146
|
|
-
|
147
|
150
|
test("connect bad credentials", () => {
|
148
|
151
|
jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
|
149
|
152
|
return Promise.resolve({
|
|
@@ -178,6 +181,25 @@ test("connect good credentials", () => {
|
178
|
181
|
return expect(c.connect('email', 'password')).resolves.toBeTruthy();
|
179
|
182
|
});
|
180
|
183
|
|
|
184
|
+test("connect good credentials no consent", () => {
|
|
185
|
+ jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
|
|
186
|
+ return Promise.resolve({
|
|
187
|
+ json: () => {
|
|
188
|
+ return {
|
|
189
|
+ state: false,
|
|
190
|
+ message: 'pas de consent',
|
|
191
|
+ token: '',
|
|
192
|
+ data: {
|
|
193
|
+ consent: false,
|
|
194
|
+ }
|
|
195
|
+ }
|
|
196
|
+ },
|
|
197
|
+ })
|
|
198
|
+ });
|
|
199
|
+ return expect(c.connect('email', 'password'))
|
|
200
|
+ .rejects.toBe(ERROR_TYPE.NO_CONSENT);
|
|
201
|
+});
|
|
202
|
+
|
181
|
203
|
test("connect good credentials, fail save token", () => {
|
182
|
204
|
jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
|
183
|
205
|
return Promise.resolve({
|
|
@@ -221,8 +243,8 @@ test("connect bogus response 1", () => {
|
221
|
243
|
|
222
|
244
|
|
223
|
245
|
test("authenticatedRequest success", () => {
|
224
|
|
- jest.spyOn(ConnectionManager.prototype, 'recoverLogin').mockImplementationOnce(() => {
|
225
|
|
- return Promise.resolve('token');
|
|
246
|
+ jest.spyOn(ConnectionManager.prototype, 'getToken').mockImplementationOnce(() => {
|
|
247
|
+ return 'token';
|
226
|
248
|
});
|
227
|
249
|
jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
|
228
|
250
|
return Promise.resolve({
|
|
@@ -236,8 +258,8 @@ test("authenticatedRequest success", () => {
|
236
|
258
|
});
|
237
|
259
|
|
238
|
260
|
test("authenticatedRequest error wrong token", () => {
|
239
|
|
- jest.spyOn(ConnectionManager.prototype, 'recoverLogin').mockImplementationOnce(() => {
|
240
|
|
- return Promise.resolve('token');
|
|
261
|
+ jest.spyOn(ConnectionManager.prototype, 'getToken').mockImplementationOnce(() => {
|
|
262
|
+ return 'token';
|
241
|
263
|
});
|
242
|
264
|
jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
|
243
|
265
|
return Promise.resolve({
|
|
@@ -251,8 +273,8 @@ test("authenticatedRequest error wrong token", () => {
|
251
|
273
|
});
|
252
|
274
|
|
253
|
275
|
test("authenticatedRequest error bogus response", () => {
|
254
|
|
- jest.spyOn(ConnectionManager.prototype, 'recoverLogin').mockImplementationOnce(() => {
|
255
|
|
- return Promise.resolve('token');
|
|
276
|
+ jest.spyOn(ConnectionManager.prototype, 'getToken').mockImplementationOnce(() => {
|
|
277
|
+ return 'token';
|
256
|
278
|
});
|
257
|
279
|
jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
|
258
|
280
|
return Promise.resolve({
|
|
@@ -266,8 +288,8 @@ test("authenticatedRequest error bogus response", () => {
|
266
|
288
|
});
|
267
|
289
|
|
268
|
290
|
test("authenticatedRequest connection error", () => {
|
269
|
|
- jest.spyOn(ConnectionManager.prototype, 'recoverLogin').mockImplementationOnce(() => {
|
270
|
|
- return Promise.resolve('token');
|
|
291
|
+ jest.spyOn(ConnectionManager.prototype, 'getToken').mockImplementationOnce(() => {
|
|
292
|
+ return 'token';
|
271
|
293
|
});
|
272
|
294
|
jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
|
273
|
295
|
return Promise.reject()
|
|
@@ -277,8 +299,8 @@ test("authenticatedRequest connection error", () => {
|
277
|
299
|
});
|
278
|
300
|
|
279
|
301
|
test("authenticatedRequest error no token", () => {
|
280
|
|
- jest.spyOn(ConnectionManager.prototype, 'recoverLogin').mockImplementationOnce(() => {
|
281
|
|
- return Promise.reject(false);
|
|
302
|
+ jest.spyOn(ConnectionManager.prototype, 'getToken').mockImplementationOnce(() => {
|
|
303
|
+ return null;
|
282
|
304
|
});
|
283
|
305
|
jest.spyOn(global, 'fetch').mockImplementationOnce(() => {
|
284
|
306
|
return Promise.resolve({
|