Skip to content

Commit

Permalink
fix(condo): DOMA-10773 add error if user is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
nomerdvadcatpyat committed Jan 31, 2025
1 parent 56e1250 commit 2f07822
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const ERRORS = {
type: NOT_FOUND,
message: 'No B2BAppAccessRight found for the provided user and B2BApp.',
},
NO_EMPLOYEE_FOR_USER: {
USER_IS_NOT_AN_EMPLOYEE: {
mutation: 'sendB2BAppPushMessage',
variable: ['data', 'user'],
code: FORBIDDEN,
Expand Down Expand Up @@ -128,6 +128,10 @@ const SendB2BAppPushMessageService = new GQLCustomSchema('SendB2BAppPushMessageS
...userFilter,
deletedAt: null,
})
if (!user) {
throw new GQLError(ERRORS.USER_IS_NOT_AN_EMPLOYEE, context)
}
const messageLocale = get(user, 'locale', conf.DEFAULT_LOCALE)

const [b2bAppContext] = await itemsQuery('B2BAppContext', {
where: {
Expand Down Expand Up @@ -167,7 +171,7 @@ const SendB2BAppPushMessageService = new GQLCustomSchema('SendB2BAppPushMessageS
deletedAt: null,
})
if (!employee) {
throw new GQLError(ERRORS.NO_EMPLOYEE_FOR_USER, context)
throw new GQLError(ERRORS.USER_IS_NOT_AN_EMPLOYEE, context)
}

const roleId = get(employee, 'role', null)
Expand All @@ -184,7 +188,7 @@ const SendB2BAppPushMessageService = new GQLCustomSchema('SendB2BAppPushMessageS
to: { user: userFilter },
organization: organizationFilter,
type,
lang: get(user, 'locale', conf.DEFAULT_LOCALE),
lang: messageLocale,
meta,
dv,
sender,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const { Message, syncRemoteClientWithPushTokenByTestClient } = require('@condo/d
const { DEFAULT_ROLES } = require('@condo/domains/organization/constants/common')
const { createTestOrganization, createTestOrganizationEmployeeRole, createTestOrganizationEmployee } = require('@condo/domains/organization/utils/testSchema')
const { GQL_ERRORS } = require('@condo/domains/user/constants/errors')
const { User, makeClientWithServiceUser, makeClientWithSupportUser, makeClientWithNewRegisteredAndLoggedInUser } = require('@condo/domains/user/utils/testSchema')
const { User, updateTestUser, makeClientWithServiceUser, makeClientWithSupportUser, makeClientWithNewRegisteredAndLoggedInUser } = require('@condo/domains/user/utils/testSchema')

const { ERRORS } = require('./SendB2BAppPushMessageService')

Expand All @@ -29,10 +29,13 @@ describe('SendB2BAppPushMessageService', () => {
organization,
b2bApp

beforeEach(async () => {
beforeAll(async () => {
admin = await makeLoggedInAdminClient()
support = await makeClientWithSupportUser()
anonymous = await makeClient()
})

beforeEach(async () => {
staffClient = await makeClientWithNewRegisteredAndLoggedInUser({
locale: faker.helpers.arrayElement(Object.keys(LOCALES)),
})
Expand Down Expand Up @@ -144,7 +147,7 @@ describe('SendB2BAppPushMessageService', () => {

await expectToThrowGQLErrorToResult(async () => {
await sendB2BAppPushMessageByTestClient(serviceUser, b2bApp, organization, user.user)
}, ERRORS.NO_EMPLOYEE_FOR_USER)
}, ERRORS.USER_IS_NOT_AN_EMPLOYEE)
})

it('Throws an error if notifications are sent more often than specified in AppMessageSetting', async () => {
Expand Down Expand Up @@ -208,5 +211,17 @@ describe('SendB2BAppPushMessageService', () => {
})
}, ERRORS.NO_B2B_APP_ROLE_FOR_EMPLOYEE_ROLE_AND_B2B_APP)
})

it('Throws an error if user is deleted', async () => {
await updateTestUser(admin, staffClient.user.id, {
deletedAt: new Date(),
})

await expectToThrowGQLErrorToResult(async () => {
await sendB2BAppPushMessageByTestClient(serviceUser, b2bApp, organization, staffClient.user, {
type: PASS_TICKET_CREATED_MESSAGE_TYPE,
})
}, ERRORS.USER_IS_NOT_AN_EMPLOYEE)
})
})
})

0 comments on commit 2f07822

Please sign in to comment.