1
- const app = require ( ' ../server/server.js' ) ;
2
- const request = require ( ' supertest' ) ;
1
+ const app = require ( " ../server/server.js" ) ;
2
+ const request = require ( " supertest" ) ;
3
3
4
- const server = ' http://localhost:8080' ;
4
+ const server = " http://localhost:8080" ;
5
5
6
6
describe ( 'GET "/"' , ( ) => {
7
- it ( ' Serves the application' , async ( ) => {
7
+ it ( " Serves the application" , async ( ) => {
8
8
await request ( server )
9
- . get ( '/' )
9
+ . get ( "/" )
10
10
. expect ( 200 )
11
- . expect ( ' Content-Type' , / t e x t \/ h t m l / )
12
- } )
13
- } )
11
+ . expect ( " Content-Type" , / t e x t \/ h t m l / ) ;
12
+ } ) ;
13
+ } ) ;
14
14
15
15
describe ( 'POST "/user/login" - login check' , ( ) => {
16
- it ( ' Logs in with correct credentials' , async ( ) => {
16
+ it ( " Logs in with correct credentials" , async ( ) => {
17
17
const res = await request ( server )
18
- . post ( ' /user/login' )
19
- . set ( ' Content-Type' , ' application/json' )
20
- . send ( { email :
' [email protected] ' , password :
' 123' } )
21
- . expect ( 200 )
22
- } )
23
- it ( ' Sends cookies after successful login' , async ( ) => {
18
+ . post ( " /user/login" )
19
+ . set ( " Content-Type" , " application/json" )
20
+ . send ( { email :
" [email protected] " , password :
" 123" } )
21
+ . expect ( 200 ) ;
22
+ } ) ;
23
+ it ( " Sends cookies after successful login" , async ( ) => {
24
24
const res = await request ( server )
25
- . post ( ' /user/login' )
26
- . set ( ' Content-Type' , ' application/json' )
27
- . send ( { email :
' [email protected] ' , password :
' 123' } )
28
- . expect ( 200 )
29
- expect ( res . headers [ ' set-cookie' ] . length ) . not . toBe ( 0 )
30
- } )
31
- it ( ' Returns an error with incorrect credentials' , async ( ) => {
25
+ . post ( " /user/login" )
26
+ . set ( " Content-Type" , " application/json" )
27
+ . send ( { email :
" [email protected] " , password :
" 123" } )
28
+ . expect ( 200 ) ;
29
+ expect ( res . headers [ " set-cookie" ] . length ) . not . toBe ( 0 ) ;
30
+ } ) ;
31
+ it ( " Returns an error with incorrect credentials" , async ( ) => {
32
32
const res = await request ( server )
33
- . post ( ' /user/login' )
34
- . set ( ' Content-Type' , ' application/json' )
35
- . send ( { email :
' [email protected] ' , password :
' incorrect' } )
36
- . expect ( 500 )
37
- expect ( res . body ) . toBe ( ' Incorrect username/password' )
38
- } )
39
- } )
33
+ . post ( " /user/login" )
34
+ . set ( " Content-Type" , " application/json" )
35
+ . send ( { email :
" [email protected] " , password :
" incorrect" } )
36
+ . expect ( 500 ) ;
37
+ expect ( res . body ) . toBe ( " Incorrect username/password" ) ;
38
+ } ) ;
39
+ } ) ;
40
40
41
41
describe ( 'POST "/user/create" - creating user' , ( ) => {
42
42
afterAll ( async ( ) => {
43
43
await request ( server )
44
- . delete ( ' /user' )
45
- . set ( ' Content-type' , ' application/json' )
46
- . send ( { email :
' [email protected] ' } )
47
- } )
44
+ . delete ( " /user" )
45
+ . set ( " Content-type" , " application/json" )
46
+ . send ( { email :
" [email protected] " } ) ;
47
+ } ) ;
48
48
49
- it ( ' Adds a new user to the database' , async ( ) => {
49
+ it ( " Adds a new user to the database" , async ( ) => {
50
50
const res = await request ( server )
51
- . post ( ' /user/create' )
52
- . set ( ' Content-type' , ' application/json' )
51
+ . post ( " /user/create" )
52
+ . set ( " Content-type" , " application/json" )
53
53
. send ( {
54
-
55
- password : ' 123' ,
56
- firstName : ' test' ,
57
- lastName : ' test' ,
58
- teamName : ' ohana' ,
59
- isAdmin : ' true' ,
54
+
55
+ password : " 123" ,
56
+ firstName : " test" ,
57
+ lastName : " test" ,
58
+ teamName : " ohana" ,
59
+ isAdmin : " true" ,
60
60
} )
61
- . expect ( 200 )
62
- expect ( res . body ) . toBe ( ' Successfully added new user' )
63
- } )
61
+ . expect ( 200 ) ;
62
+ expect ( res . body ) . toBe ( " Successfully added new user" ) ;
63
+ } ) ;
64
64
65
- it ( 'New user appears in the database' , async ( ) => {
66
- const res = await request ( server )
67
- . get ( '/user' )
68
- . expect ( 200 )
69
- expect ( res . body [ res . body . length - 1 ] . email ) . toBe ( '[email protected] ' )
70
- } )
71
- } )
65
+ it ( "New user appears in the database" , async ( ) => {
66
+ const res = await request ( server ) . get ( "/user" ) . expect ( 200 ) ;
67
+ expect ( res . body [ res . body . length - 1 ] . email ) . toBe ( "[email protected] " ) ;
68
+ } ) ;
69
+ } ) ;
72
70
73
71
describe ( 'GET "/spaces" and "/vclusters"' , ( ) => {
74
- it ( 'Receives a list of all the active namespaces' , async ( ) => {
75
- const res = await request ( server )
76
- . get ( '/spaces/fetch' )
77
- . expect ( 200 )
78
- expect ( Array . isArray ( res . body ) ) . toBe ( true )
79
- } )
80
- it ( 'Receives a list of all the active vClusters' , async ( ) => {
81
- const res = await request ( server )
82
- . get ( '/vclusters' )
83
- . expect ( 200 )
84
- expect ( Array . isArray ( res . body ) ) . toBe ( true )
85
- } )
86
- } )
72
+ it ( "Receives a list of all the active namespaces" , async ( ) => {
73
+ const res = await request ( server ) . get ( "/spaces/fetch" ) . expect ( 200 ) ;
74
+ expect ( Array . isArray ( res . body ) ) . toBe ( true ) ;
75
+ } ) ;
76
+ it ( "Receives a list of all the active vClusters" , async ( ) => {
77
+ const res = await request ( server ) . get ( "/vclusters" ) . expect ( 200 ) ;
78
+ expect ( Array . isArray ( res . body ) ) . toBe ( true ) ;
79
+ } ) ;
80
+ } ) ;
0 commit comments