@@ -4,6 +4,7 @@ const chai = require('chai')
44const dirtyChai = require ( 'dirty-chai' )
55chai . use ( dirtyChai )
66const expect = chai . expect
7+ const assert = chai . assert
78const sinon = require ( 'sinon' )
89const sinonChai = require ( 'sinon-chai' )
910chai . use ( sinonChai )
@@ -220,13 +221,33 @@ describe('UserStore', () => {
220221 store = UserStore . from ( { path : './db' } )
221222 } )
222223
223- it ( 'should call backend.del with normalized user id' , ( ) => {
224+ it ( 'should call backend.del with normalized user id and email ' , ( ) => {
224225 let userId = 'alice.solidtest.space/profile/card#me'
226+ 225227
226228 store . backend . del = sinon . stub ( )
227229
228- store . deleteUser ( { id : userId } )
229- expect ( store . backend . del ) . to . have . been . calledWith ( 'users' , UserStore . normalizeIdKey ( userId ) )
230+ return store . deleteUser ( { id : userId , email : email } )
231+ . then ( ( ) => {
232+ expect ( store . backend . del ) . to . have . been . calledWith ( 'users' , UserStore . normalizeIdKey ( userId ) )
233+ expect ( store . backend . del ) . to . have . been . calledWith ( 'users-by-email' , UserStore . normalizeEmailKey ( email ) )
234+ } )
235+ } )
236+
237+ it ( 'should call backend.del with normalized user id but no email' , ( ) => {
238+ let userId = 'alice.solidtest.space/profile/card#me'
239+
240+ store . backend . del = sinon . stub ( )
241+
242+ return store . deleteUser ( { id : userId } )
243+ . then ( ( ) => {
244+ expect ( store . backend . del ) . to . have . been . calledWith ( 'users' , UserStore . normalizeIdKey ( userId ) )
245+ expect ( store . backend . del ) . to . not . have . been . calledWith ( 'users-by-email' , UserStore . normalizeEmailKey ( ) )
246+ } )
247+ . then (
248+ ( ) => Promise . reject ( new Error ( 'Expected method to reject.' ) ) ,
249+ err => assert . instanceOf ( err , Error )
250+ )
230251 } )
231252 } )
232253} )
0 commit comments