@@ -91,23 +91,76 @@ describe('Database client', async () => {
9191 TEST_USER . admin ,
9292 ) ;
9393 const users = await db . getUsers ( ) ;
94- console . log ( 'TEST USER:' , JSON . stringify ( TEST_USER , null , 2 ) ) ;
95- console . log ( 'USERS:' , JSON . stringify ( users , null , 2 ) ) ;
9694 // remove password as it will have been hashed
9795 // eslint-disable-next-line no-unused-vars
9896 const { password : _ , ...TEST_USER_CLEAN } = TEST_USER ;
9997 const cleanUsers = cleanResponseData ( TEST_USER_CLEAN , users ) ;
100- console . log ( 'CLEAN USERS:' , JSON . stringify ( cleanUsers , null , 2 ) ) ;
10198 expect ( cleanUsers ) . to . deep . include ( TEST_USER_CLEAN ) ;
10299 } ) ;
103100
101+ it ( 'should be able to find a user' , async function ( ) {
102+ const user = await db . findUser ( TEST_USER . username ) ;
103+ // eslint-disable-next-line no-unused-vars
104+ const { password : _ , ...TEST_USER_CLEAN } = TEST_USER ;
105+ // eslint-disable-next-line no-unused-vars
106+ const { password : _2 , _id : _3 , ...DB_USER_CLEAN } = user ;
107+
108+ expect ( DB_USER_CLEAN ) . to . eql ( TEST_USER_CLEAN ) ;
109+ } ) ;
110+
111+ it ( 'should be able to filter getUsers' , async function ( ) {
112+ // uppercase the filter value to confirm db client is lowercasing inputs
113+ const users = await db . getUsers ( { username : TEST_USER . username . toUpperCase ( ) } ) ;
114+ // eslint-disable-next-line no-unused-vars
115+ const { password : _ , ...TEST_USER_CLEAN } = TEST_USER ;
116+ const cleanUsers = cleanResponseData ( TEST_USER_CLEAN , users ) ;
117+ expect ( cleanUsers [ 0 ] ) . to . eql ( TEST_USER_CLEAN ) ;
118+
119+ const users2 = await db . getUsers ( { email : TEST_USER . email . toUpperCase ( ) } ) ;
120+ const cleanUsers2 = cleanResponseData ( TEST_USER_CLEAN , users2 ) ;
121+ expect ( cleanUsers2 [ 0 ] ) . to . eql ( TEST_USER_CLEAN ) ;
122+ } ) ;
123+
104124 it ( 'should be able to delete a user' , async function ( ) {
105125 await db . deleteUser ( TEST_USER . username ) ;
106126 const users = await db . getUsers ( ) ;
107127 const cleanUsers = cleanResponseData ( TEST_USER , users ) ;
108128 expect ( cleanUsers ) . to . not . deep . include ( TEST_USER ) ;
109129 } ) ;
110130
131+ it ( 'should be able to update a user' , async function ( ) {
132+ await db . createUser (
133+ TEST_USER . username ,
134+ TEST_USER . password ,
135+ TEST_USER . email ,
136+ TEST_USER . gitAccount ,
137+ TEST_USER . admin ,
138+ ) ;
139+
140+ // has less properties to prove that records are merged
141+ const updateToApply = {
142+ username : TEST_USER . username ,
143+ gitAccount : 'updatedGitAccount' ,
144+ admin : false ,
145+ } ;
146+
147+ const updatedUser = {
148+ // remove password as it will have been hashed
149+ username : TEST_USER . username ,
150+ email : TEST_USER . email ,
151+ gitAccount : 'updatedGitAccount' ,
152+ admin : false ,
153+ } ;
154+ await db . updateUser ( updateToApply ) ;
155+
156+ const users = await db . getUsers ( ) ;
157+ console . log ( 'TEST USER:' , JSON . stringify ( TEST_USER , null , 2 ) ) ;
158+ console . log ( 'USERS:' , JSON . stringify ( users , null , 2 ) ) ;
159+ const cleanUsers = cleanResponseData ( updatedUser , users ) ;
160+ console . log ( 'CLEAN USERS:' , JSON . stringify ( cleanUsers , null , 2 ) ) ;
161+ expect ( cleanUsers ) . to . deep . include ( updatedUser ) ;
162+ } ) ;
163+
111164 it ( 'should be able to create a push' , async function ( ) {
112165 await db . writeAudit ( TEST_PUSH ) ;
113166 const pushes = await db . getPushes ( ) ;
@@ -122,5 +175,9 @@ describe('Database client', async () => {
122175 expect ( cleanPushes ) . to . not . deep . include ( TEST_PUSH ) ;
123176 } ) ;
124177
125- after ( async function ( ) { } ) ;
178+ after ( async function ( ) {
179+ await db . deleteRepo ( TEST_REPO . name ) ;
180+ await db . deleteUser ( TEST_USER . username ) ;
181+ await db . deletePush ( TEST_PUSH . id ) ;
182+ } ) ;
126183} ) ;
0 commit comments