Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions application/backend/src/controllers/UsersController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,25 +155,27 @@ describe('UsersController', () => {
})

it('should not return user password', async () => {
const userId = TestUsers.PARTICIPANT_UNANSWERED.id
const response = await request(app)
.get('/users')
.get(`/users/${userId}`)
.set({ Authorization: `Bearer ${orgAdminToken}` })
expect(response.status).toBe(200)

const body: GetAllUsersResponse = response.body
const body: GetUserByIdResponse = response.body
expect(body).toHaveProperty('data')
expect(body.data[0]).not.toHaveProperty('password')
expect(body.data).not.toHaveProperty('password')
})

it('should not return user emailHash', async () => {
const userId = TestUsers.PARTICIPANT_UNANSWERED.id
const response = await request(app)
.get('/users')
.get(`/users/${userId}`)
.set({ Authorization: `Bearer ${orgAdminToken}` })
expect(response.status).toBe(200)

const body: GetAllUsersResponse = response.body
const body: GetUserByIdResponse = response.body
expect(body).toHaveProperty('data')
expect(body.data[0]).not.toHaveProperty('emailHash')
expect(body.data).not.toHaveProperty('emailHash')
})
})

Expand Down
1 change: 1 addition & 0 deletions application/backend/src/controllers/UsersController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export class UsersController extends Controller {
const user: UserResponse | null = await this.userRepo.findUnique({
where: { id: userId },
include: { adminOfStudies: { select: { name: true, id: true } } },
omit: { password: true, emailHash: true },
})
if (!user) {
const errorMessage: string = `User with ID: ${userId} not found`
Expand Down
Loading