Fixes for invitation unit tests

This commit is contained in:
Dean 2023-02-28 22:27:02 +00:00
parent f66fc22f29
commit 09adef4d59
2 changed files with 10 additions and 4 deletions

View File

@ -254,7 +254,7 @@ export const onboardUsers = async (ctx: any) => {
onboardingResponse = await userSdk.bulkCreate(assignUsers, groups) onboardingResponse = await userSdk.bulkCreate(assignUsers, groups)
ctx.body = onboardingResponse ctx.body = onboardingResponse
} else if (emailConfigured) { } else if (emailConfigured) {
onboardingResponse = await invite(ctx) onboardingResponse = await inviteMultiple(ctx)
} else if (!emailConfigured) { } else if (!emailConfigured) {
const inviteRequest = ctx.request.body as InviteUsersRequest const inviteRequest = ctx.request.body as InviteUsersRequest
@ -297,8 +297,10 @@ export const onboardUsers = async (ctx: any) => {
} }
export const invite = async (ctx: any) => { export const invite = async (ctx: any) => {
const request = ctx.request.body as InviteUsersRequest const request = ctx.request.body as InviteUserRequest
const response = await userSdk.invite(request)
let multiRequest = [request] as InviteUsersRequest
const response = await userSdk.invite(multiRequest)
// explicitly throw for single user invite // explicitly throw for single user invite
if (response.unsuccessful.length) { if (response.unsuccessful.length) {

View File

@ -30,7 +30,11 @@ describe("/api/global/users", () => {
email email
) )
expect(res.body).toEqual({ message: "Invitation has been sent." }) expect(res.body?.message).toBe("Invitation has been sent.")
expect(res.body?.unsuccessful.length).toBe(0)
expect(res.body?.successful.length).toBe(1)
expect(res.body?.successful[0].email).toBe(email)
expect(sendMailMock).toHaveBeenCalled() expect(sendMailMock).toHaveBeenCalled()
expect(code).toBeDefined() expect(code).toBeDefined()
expect(events.user.invited).toBeCalledTimes(1) expect(events.user.invited).toBeCalledTimes(1)