@@ -7,13 +7,19 @@ describe('Users', () => {
7
7
const username = `john-${ new Date ( ) . getTime ( ) } @acme.com` ;
8
8
const password = '123' ;
9
9
10
+ const orgUsername = `jim-${ new Date ( ) . getTime ( ) } @insurance.com` ;
11
+ const orgPassword = '456' ;
12
+ const organization = `org-${ new Date ( ) . getTime ( ) } ` ;
13
+
10
14
let app ;
11
15
let api ;
16
+ let apiAnon ;
12
17
13
18
before ( ( done ) => {
14
19
require ( '../server' ) ( ( err , readyApp ) => {
15
20
app = readyApp ;
16
21
api = supertest . agent ( app ) ; // .agent() persists cookies between calls
22
+ apiAnon = supertest ( app ) ;
17
23
done ( ) ;
18
24
} ) ;
19
25
} ) ;
@@ -74,6 +80,17 @@ describe('Users', () => {
74
80
} ) ;
75
81
} ) ;
76
82
83
+ it ( 'can not log in with an organization if it is not part of one' , ( done ) => {
84
+ api . post ( '/api/users/login' )
85
+ . send ( `email=${ username } ` )
86
+ . send ( `password=${ password } ` )
87
+ . send ( 'organization=anOrg' )
88
+ . expect ( 401 )
89
+ . end ( ( err ) => {
90
+ done ( err ) ;
91
+ } ) ;
92
+ } ) ;
93
+
77
94
it ( 'can ensure if it is logged' , ( done ) => {
78
95
api . get ( '/api/users/isLoggedIn' )
79
96
. expect ( 200 )
@@ -83,4 +100,37 @@ describe('Users', () => {
83
100
done ( err ) ;
84
101
} ) ;
85
102
} ) ;
103
+
104
+
105
+ it ( 'can register an organization account' , ( done ) => {
106
+ apiAnon . post ( '/api/users/signup' )
107
+ . send ( `email=${ orgUsername } ` )
108
+ . send ( `password=${ orgPassword } ` )
109
+ . send ( `organization=${ organization } ` )
110
+ . expect ( 200 )
111
+ . end ( ( err ) => {
112
+ done ( err ) ;
113
+ } ) ;
114
+ } ) ;
115
+
116
+ it ( 'can login by specifying its organization' , ( done ) => {
117
+ apiAnon . post ( '/api/users/login' )
118
+ . send ( `email=${ orgUsername } ` )
119
+ . send ( `password=${ orgPassword } ` )
120
+ . send ( `organization=${ organization } ` )
121
+ . expect ( 200 )
122
+ . end ( ( err ) => {
123
+ done ( err ) ;
124
+ } ) ;
125
+ } ) ;
126
+
127
+ it ( 'can not login without specifying its organization' , ( done ) => {
128
+ apiAnon . post ( '/api/users/login' )
129
+ . send ( `email=${ orgUsername } ` )
130
+ . send ( `password=${ orgPassword } ` )
131
+ . expect ( 401 )
132
+ . end ( ( err ) => {
133
+ done ( err ) ;
134
+ } ) ;
135
+ } ) ;
86
136
} ) ;
0 commit comments