3
3
const request = require ( '../lib/request' ) ;
4
4
const fs = require ( 'fs' ) . promises ;
5
5
const Utils = require ( '../lib/Utils' ) ;
6
- const { PublicAPIRouter, pages } = require ( '../lib/Routers/PublicAPIRouter' ) ;
6
+ const { PublicAPIRouter, pages, pageParams } = require ( '../lib/Routers/PublicAPIRouter' ) ;
7
7
8
8
describe ( 'public API' , ( ) => {
9
- it ( 'should return missing username error on ajax request without username provided' , async ( ) => {
10
- await reconfigureServer ( {
11
- publicServerURL : 'http://localhost:8378/1' ,
12
- } ) ;
13
-
14
- try {
15
- await request ( {
16
- method : 'POST' ,
17
- url : 'http://localhost:8378/1/apps/test/request_password_reset' ,
18
- body : `new_password=user1&token=43634643&username=` ,
19
- headers : {
20
- 'Content-Type' : 'application/x-www-form-urlencoded' ,
21
- 'X-Requested-With' : 'XMLHttpRequest' ,
22
- } ,
23
- followRedirects : false ,
9
+ describe ( 'basic request' , ( ) => {
10
+ it ( 'should return missing username error on ajax request without username provided' , async ( ) => {
11
+ await reconfigureServer ( {
12
+ publicServerURL : 'http://localhost:8378/1' ,
24
13
} ) ;
25
- } catch ( error ) {
26
- expect ( error . status ) . not . toBe ( 302 ) ;
27
- expect ( error . text ) . toEqual ( '{"code":200,"error":"Missing username"}' ) ;
28
- }
29
- } ) ;
30
14
31
- it ( 'should return missing token error on ajax request without token provided' , async ( ) => {
32
- await reconfigureServer ( {
33
- publicServerURL : 'http://localhost:8378/1' ,
15
+ try {
16
+ await request ( {
17
+ method : 'POST' ,
18
+ url : 'http://localhost:8378/1/apps/test/request_password_reset' ,
19
+ body : `new_password=user1&token=43634643&username=` ,
20
+ headers : {
21
+ 'Content-Type' : 'application/x-www-form-urlencoded' ,
22
+ 'X-Requested-With' : 'XMLHttpRequest' ,
23
+ } ,
24
+ followRedirects : false ,
25
+ } ) ;
26
+ } catch ( error ) {
27
+ expect ( error . status ) . not . toBe ( 302 ) ;
28
+ expect ( error . text ) . toEqual ( '{"code":200,"error":"Missing username"}' ) ;
29
+ }
34
30
} ) ;
35
31
36
- try {
37
- await request ( {
38
- method : 'POST' ,
39
- url : 'http://localhost:8378/1/apps/test/request_password_reset' ,
40
- body : `new_password=user1&token=&username=Johnny` ,
41
- headers : {
42
- 'Content-Type' : 'application/x-www-form-urlencoded' ,
43
- 'X-Requested-With' : 'XMLHttpRequest' ,
44
- } ,
45
- followRedirects : false ,
32
+ it ( 'should return missing token error on ajax request without token provided' , async ( ) => {
33
+ await reconfigureServer ( {
34
+ publicServerURL : 'http://localhost:8378/1' ,
46
35
} ) ;
47
- } catch ( error ) {
48
- expect ( error . status ) . not . toBe ( 302 ) ;
49
- expect ( error . text ) . toEqual ( '{"code":-1,"error":"Missing token"}' ) ;
50
- }
51
- } ) ;
52
36
53
- it ( 'should return missing password error on ajax request without password provided' , async ( ) => {
54
- await reconfigureServer ( {
55
- publicServerURL : 'http://localhost:8378/1' ,
37
+ try {
38
+ await request ( {
39
+ method : 'POST' ,
40
+ url : 'http://localhost:8378/1/apps/test/request_password_reset' ,
41
+ body : `new_password=user1&token=&username=Johnny` ,
42
+ headers : {
43
+ 'Content-Type' : 'application/x-www-form-urlencoded' ,
44
+ 'X-Requested-With' : 'XMLHttpRequest' ,
45
+ } ,
46
+ followRedirects : false ,
47
+ } ) ;
48
+ } catch ( error ) {
49
+ expect ( error . status ) . not . toBe ( 302 ) ;
50
+ expect ( error . text ) . toEqual ( '{"code":-1,"error":"Missing token"}' ) ;
51
+ }
56
52
} ) ;
57
53
58
- try {
59
- await request ( {
60
- method : 'POST' ,
61
- url : 'http://localhost:8378/1/apps/test/request_password_reset' ,
62
- body : `new_password=&token=132414&username=Johnny` ,
63
- headers : {
64
- 'Content-Type' : 'application/x-www-form-urlencoded' ,
65
- 'X-Requested-With' : 'XMLHttpRequest' ,
66
- } ,
67
- followRedirects : false ,
54
+ it ( 'should return missing password error on ajax request without password provided' , async ( ) => {
55
+ await reconfigureServer ( {
56
+ publicServerURL : 'http://localhost:8378/1' ,
68
57
} ) ;
69
- } catch ( error ) {
70
- expect ( error . status ) . not . toBe ( 302 ) ;
71
- expect ( error . text ) . toEqual ( '{"code":201,"error":"Missing password"}' ) ;
72
- }
73
- } ) ;
74
58
75
- it ( 'should get invalid_link.html' , async ( ) => {
76
- const httpResponse = await request ( {
77
- url : 'http://localhost:8378/1/apps/invalid_link.html' ,
59
+ try {
60
+ await request ( {
61
+ method : 'POST' ,
62
+ url : 'http://localhost:8378/1/apps/test/request_password_reset' ,
63
+ body : `new_password=&token=132414&username=Johnny` ,
64
+ headers : {
65
+ 'Content-Type' : 'application/x-www-form-urlencoded' ,
66
+ 'X-Requested-With' : 'XMLHttpRequest' ,
67
+ } ,
68
+ followRedirects : false ,
69
+ } ) ;
70
+ } catch ( error ) {
71
+ expect ( error . status ) . not . toBe ( 302 ) ;
72
+ expect ( error . text ) . toEqual ( '{"code":201,"error":"Missing password"}' ) ;
73
+ }
78
74
} ) ;
79
- expect ( httpResponse . status ) . toBe ( 200 ) ;
80
- } ) ;
81
75
82
- it ( 'should get choose_password' , async ( ) => {
83
- await reconfigureServer ( {
84
- appName : 'unused' ,
85
- publicServerURL : 'http://localhost:8378/1' ,
76
+ it ( 'should get invalid_link.html' , async ( ) => {
77
+ const httpResponse = await request ( {
78
+ url : 'http://localhost:8378/1/apps/invalid_link.html' ,
79
+ } ) ;
80
+ expect ( httpResponse . status ) . toBe ( 200 ) ;
86
81
} ) ;
87
- const httpResponse = await request ( {
88
- url : 'http://localhost:8378/1/apps/choose_password?appId=test' ,
82
+
83
+ it ( 'should get choose_password' , async ( ) => {
84
+ await reconfigureServer ( {
85
+ appName : 'unused' ,
86
+ publicServerURL : 'http://localhost:8378/1' ,
87
+ } ) ;
88
+ const httpResponse = await request ( {
89
+ url : 'http://localhost:8378/1/apps/choose_password?appId=test' ,
90
+ } ) ;
91
+ expect ( httpResponse . status ) . toBe ( 200 ) ;
89
92
} ) ;
90
- expect ( httpResponse . status ) . toBe ( 200 ) ;
91
- } ) ;
92
93
93
- it ( 'should get verify_email_success.html' , async ( ) => {
94
- const httpResponse = await request ( {
95
- url : 'http://localhost:8378/1/apps/verify_email_success.html' ,
94
+ it ( 'should get verify_email_success.html' , async ( ) => {
95
+ const httpResponse = await request ( {
96
+ url : 'http://localhost:8378/1/apps/verify_email_success.html' ,
97
+ } ) ;
98
+ expect ( httpResponse . status ) . toBe ( 200 ) ;
96
99
} ) ;
97
- expect ( httpResponse . status ) . toBe ( 200 ) ;
98
- } ) ;
99
100
100
- it ( 'should get password_reset_success.html' , async ( ) => {
101
- const httpResponse = await request ( {
102
- url : 'http://localhost:8378/1/apps/password_reset_success.html' ,
101
+ it ( 'should get password_reset_success.html' , async ( ) => {
102
+ const httpResponse = await request ( {
103
+ url : 'http://localhost:8378/1/apps/password_reset_success.html' ,
104
+ } ) ;
105
+ expect ( httpResponse . status ) . toBe ( 200 ) ;
103
106
} ) ;
104
- expect ( httpResponse . status ) . toBe ( 200 ) ;
105
107
} ) ;
106
108
107
109
describe ( 'public API without publicServerURL' , function ( ) {
@@ -196,8 +198,8 @@ describe('public API', () => {
196
198
beforeEach ( async ( ) => {
197
199
router = new PublicAPIRouter ( ) ;
198
200
readFile = spyOn ( fs , 'readFile' ) . and . callThrough ( ) ;
199
- pageResponse = spyOn ( router , 'pageResponse' ) . and . callThrough ( ) ;
200
- redirectResponse = spyOn ( router , 'redirectResponse' ) . and . callThrough ( ) ;
201
+ pageResponse = spyOn ( PublicAPIRouter . prototype , 'pageResponse' ) . and . callThrough ( )
202
+ redirectResponse = spyOn ( PublicAPIRouter . prototype , 'redirectResponse' ) . and . callThrough ( ) ;
201
203
req = {
202
204
method : 'GET' ,
203
205
config : {
@@ -247,8 +249,8 @@ describe('public API', () => {
247
249
delete req . config . enablePageLocalization ;
248
250
249
251
await expectAsync ( router . goToPage ( req , pages . invalidLink ) ) . toBeResolved ( ) ;
250
- expect ( pageResponse . calls . all ( ) [ 0 ] . args [ 1 ] ) . toBeDefined ( ) ;
251
- expect ( pageResponse . calls . all ( ) [ 0 ] . args [ 1 ] ) . not . toMatch (
252
+ expect ( pageResponse . calls . all ( ) [ 0 ] . args [ 0 ] ) . toBeDefined ( ) ;
253
+ expect ( pageResponse . calls . all ( ) [ 0 ] . args [ 0 ] ) . not . toMatch (
252
254
new RegExp ( `\/de(-AT)?\/${ pages . invalidLink . defaultFile } ` )
253
255
) ;
254
256
} ) ;
@@ -257,8 +259,8 @@ describe('public API', () => {
257
259
delete req . query . locale ;
258
260
259
261
await expectAsync ( router . goToPage ( req , pages . invalidLink ) ) . toBeResolved ( ) ;
260
- expect ( pageResponse . calls . all ( ) [ 0 ] . args [ 1 ] ) . toBeDefined ( ) ;
261
- expect ( pageResponse . calls . all ( ) [ 0 ] . args [ 1 ] ) . not . toMatch (
262
+ expect ( pageResponse . calls . all ( ) [ 0 ] . args [ 0 ] ) . toBeDefined ( ) ;
263
+ expect ( pageResponse . calls . all ( ) [ 0 ] . args [ 0 ] ) . not . toMatch (
262
264
new RegExp ( `\/de(-AT)?\/${ pages . invalidLink . defaultFile } ` )
263
265
) ;
264
266
} ) ;
@@ -273,8 +275,8 @@ describe('public API', () => {
273
275
274
276
it ( 'returns file for locale match' , async ( ) => {
275
277
await expectAsync ( router . goToPage ( req , pages . invalidLink ) ) . toBeResolved ( ) ;
276
- expect ( pageResponse . calls . all ( ) [ 0 ] . args [ 1 ] ) . toBeDefined ( ) ;
277
- expect ( pageResponse . calls . all ( ) [ 0 ] . args [ 1 ] ) . toMatch (
278
+ expect ( pageResponse . calls . all ( ) [ 0 ] . args [ 0 ] ) . toBeDefined ( ) ;
279
+ expect ( pageResponse . calls . all ( ) [ 0 ] . args [ 0 ] ) . toMatch (
278
280
new RegExp ( `\/de-AT\/${ pages . invalidLink . defaultFile } ` )
279
281
) ;
280
282
} ) ;
@@ -286,8 +288,8 @@ describe('public API', () => {
286
288
} ) ;
287
289
288
290
await expectAsync ( router . goToPage ( req , pages . invalidLink ) ) . toBeResolved ( ) ;
289
- expect ( pageResponse . calls . all ( ) [ 0 ] . args [ 1 ] ) . toBeDefined ( ) ;
290
- expect ( pageResponse . calls . all ( ) [ 0 ] . args [ 1 ] ) . toMatch (
291
+ expect ( pageResponse . calls . all ( ) [ 0 ] . args [ 0 ] ) . toBeDefined ( ) ;
292
+ expect ( pageResponse . calls . all ( ) [ 0 ] . args [ 0 ] ) . toMatch (
291
293
new RegExp ( `\/de\/${ pages . invalidLink . defaultFile } ` )
292
294
) ;
293
295
} ) ;
@@ -296,8 +298,8 @@ describe('public API', () => {
296
298
req . query . locale = 'yo-LO' ;
297
299
298
300
await expectAsync ( router . goToPage ( req , pages . invalidLink ) ) . toBeResolved ( ) ;
299
- expect ( pageResponse . calls . all ( ) [ 0 ] . args [ 1 ] ) . toBeDefined ( ) ;
300
- expect ( pageResponse . calls . all ( ) [ 0 ] . args [ 1 ] ) . not . toMatch (
301
+ expect ( pageResponse . calls . all ( ) [ 0 ] . args [ 0 ] ) . toBeDefined ( ) ;
302
+ expect ( pageResponse . calls . all ( ) [ 0 ] . args [ 0 ] ) . not . toMatch (
301
303
new RegExp ( `\/yo(-LO)?\/${ pages . invalidLink . defaultFile } ` )
302
304
) ;
303
305
} ) ;
@@ -315,7 +317,7 @@ describe('public API', () => {
315
317
expect ( redirectResponse ) . toHaveBeenCalled ( ) ;
316
318
} ) ;
317
319
318
- it ( 'returns a redirect for custom pages for GET and POST' , async ( ) => {
320
+ it ( 'returns a redirect for custom pages for GET and POST request ' , async ( ) => {
319
321
req . config . customPages = { invalidLink : 'http://invalid-link.example.com' } ;
320
322
321
323
for ( const method of [ 'GET' , 'POST' ] ) {
0 commit comments