Skip to content

Commit

Permalink
Update user.test.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
aelassas committed Nov 17, 2024
1 parent 72eee6a commit 318baf4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion api/src/controllers/userController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,7 @@ export const deleteUsers = async (req: Request, res: Response) => {
}
}

if (user.contracts) {
if (user.contracts && user.contracts.length > 0) {
for (const contract of user.contracts) {
if (contract.file) {
const file = path.join(env.CDN_CONTRACTS, contract.file)
Expand Down
16 changes: 14 additions & 2 deletions api/tests/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1290,12 +1290,24 @@ describe('POST /api/delete-users', () => {
it('should delete users', async () => {
const token = await testHelper.signinAsAdmin()

let payload: string[] = [USER1_ID, USER2_ID, ADMIN_ID]
const supplierName1 = testHelper.getSupplierName()
const supplier1Id = await testHelper.createSupplier(`${supplierName1}@test.bookcars.ma`, supplierName1)

const supplierName2 = testHelper.getSupplierName()
const supplier2Id = await testHelper.createSupplier(`${supplierName2}@test.bookcars.ma`, supplierName1)
const supplier2 = await User.findById(supplier2Id)
supplier2!.contracts = [
{ language: 'en', file: null },
{ language: 'fr', file: `${nanoid()}.pdf` },
]
await supplier2?.save()

let payload: string[] = [USER1_ID, USER2_ID, ADMIN_ID, supplier1Id, supplier2Id]
const user1 = await User.findById(USER1_ID)
user1!.avatar = `${nanoid()}.jpg`
await user1?.save()
let users = await User.find({ _id: { $in: payload } })
expect(users.length).toBe(3)
expect(users.length).toBe(5)
let res = await request(app)
.post('/api/delete-users')
.set(env.X_ACCESS_TOKEN, token)
Expand Down

0 comments on commit 318baf4

Please sign in to comment.