@@ -9,22 +9,28 @@ const testUser = {
99 location : {
1010 name : 'Valhalla' ,
1111 centre : 'Nairobi' ,
12- country : 'Kenya' ,
13- } ,
12+ country : 'Kenya'
13+ }
1414} ;
1515
1616const newUser = {
1717 ...testUser ,
181819- username : 'Oliver Brice' ,
19+ username : 'Oliver Brice'
20+ } ;
21+
22+ const newUserCaps = {
23+ ...testUser ,
24+ 25+ username : 'Oliver Brice'
2026} ;
2127
2228jest . mock ( 'nodemailer' , ( ) => ( {
2329 createTransport : ( ) => ( {
2430 sendMail : ( options , call ) => {
2531 call ( ) ;
26- } ,
27- } ) ,
32+ }
33+ } )
2834} ) ) ;
2935
3036jest . mock ( 'axios' , ( ) => ( {
@@ -33,10 +39,10 @@ jest.mock('axios', () => ({
3339 get : ( ) => ( {
3440 data : {
3541 values : [ { } ] ,
36- total : 1 ,
37- } ,
38- } ) ,
39- } ) ,
42+ total : 1
43+ }
44+ } )
45+ } )
4046} ) ) ;
4147
4248describe ( 'User tests' , ( ) => {
@@ -56,6 +62,15 @@ describe('User tests', () => {
5662 } ) ;
5763 } ) ;
5864
65+ it ( 'should normalize email' , done => {
66+ sendRequest ( 'post' , '/api/users' , newUser , ( ) => {
67+ sendRequest ( 'post' , '/api/users' , newUserCaps , ( err , res ) => {
68+ expect ( res . text ) . toMatch ( 'email must be unique' ) ;
69+ done ( ) ;
70+ } ) ;
71+ } ) ;
72+ } ) ;
73+
5974 it ( 'should login an authorised user' , done => {
6075 sendRequest (
6176 'post' ,
@@ -139,7 +154,7 @@ describe('User tests', () => {
139154 {
140155141156 roleId : 3 ,
142- locationId : 'cjee24cz40000guxs6bdner6l' ,
157+ locationId : 'cjee24cz40000guxs6bdner6l'
143158 } ,
144159 ( err , res ) => {
145160 expect ( res . body . data . username ) . toEqual ( 'Oliver Munala' ) ;
@@ -155,7 +170,7 @@ describe('User tests', () => {
155170 {
156171157172 roleId : 3 ,
158- locationId : 'cjee24cz40000guxs6bdner6l' ,
173+ locationId : 'cjee24cz40000guxs6bdner6l'
159174 } ,
160175 ( err , res ) => {
161176 expect ( res . body . message ) . toMatch (
@@ -173,7 +188,7 @@ describe('User tests', () => {
173188 {
174189175190 roleId : 3 ,
176- locationId : 'cjee24cz40000guxs6bdner6l' ,
191+ locationId : 'cjee24cz40000guxs6bdner6l'
177192 } ,
178193 ( err , res ) => {
179194 expect ( res . body . message ) . toMatch (
@@ -191,7 +206,7 @@ describe('User tests', () => {
191206 {
192207193208 roleId : 1 ,
194- locationId : 'cjee24n0n0000hfxsefer9tjh' ,
209+ locationId : 'cjee24n0n0000hfxsefer9tjh'
195210 } ,
196211 ( err , res ) => {
197212 expect ( res . body . data . username ) . toEqual ( 'Batian Sss' ) ;
0 commit comments