Skip to content

Commit

Permalink
fix(condo): DOMA-11023 prevent update the client field if no reside…
Browse files Browse the repository at this point in the history
…nt found (#5779)
  • Loading branch information
AleX83Xpert authored Feb 7, 2025
1 parent f083a46 commit 90d5238
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
4 changes: 3 additions & 1 deletion apps/condo/domains/marketplace/schema/Invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,9 @@ const Invoice = new GQLListSchema('Invoice', {
deletedAt: null,
})

set(resolvedData, 'client', get(resident, 'user', null))
if (resident) {
set(resolvedData, 'client', get(resident, 'user'))
}
}
}
}
Expand Down
62 changes: 61 additions & 1 deletion apps/condo/domains/marketplace/schema/Invoice.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const {
} = require('@condo/domains/organization/utils/testSchema')
const { FLAT_UNIT_TYPE, COMMERCIAL_UNIT_TYPE } = require('@condo/domains/property/constants/common')
const { makeClientWithProperty, createTestProperty } = require('@condo/domains/property/utils/testSchema')
const { registerResidentByTestClient, registerResidentInvoiceByTestClient } = require('@condo/domains/resident/utils/testSchema')
const { registerResidentByTestClient, registerResidentInvoiceByTestClient, updateTestResident } = require('@condo/domains/resident/utils/testSchema')
const { STATUS_IDS } = require('@condo/domains/ticket/constants/statusTransitions')
const { createTestTicket, updateTestTicket, TicketStatus } = require('@condo/domains/ticket/utils/testSchema')
const {
Expand Down Expand Up @@ -942,6 +942,66 @@ describe('Invoice', () => {
})
})
})

test('client keep as is during update if no resident was deleted', async () => {
const [o10n] = await createTestOrganization(adminClient)

await createTestAcquiringIntegrationContext(adminClient, o10n, dummyAcquiringIntegration, {
invoiceStatus: CONTEXT_FINISHED_STATUS,
invoiceRecipient: createTestRecipient(),
})

const [property] = await createTestProperty(adminClient, o10n)

const residentClient = await makeClientWithResidentUser()
const unitType = FLAT_UNIT_TYPE
const unitName = faker.lorem.word()

const [resident] = await registerResidentByTestClient(
residentClient,
{
address: property.address,
addressMeta: property.addressMeta,
unitType,
unitName,
})

const staffClient = await makeClientWithStaffUser()
const [role] = await createTestOrganizationEmployeeRole(adminClient, o10n, {
canManageInvoices: true,
canManageContacts: true,
})
await createTestOrganizationEmployee(adminClient, o10n, staffClient.user, role)

const [contact] = await createTestContact(staffClient, o10n, property, {
phone: residentClient.userAttrs.phone,
unitType,
unitName,
})

const [invoice] = await createTestInvoice(staffClient, o10n, {
property: { connect: { id: property.id } },
unitType,
unitName,
contact: { connect: { id: contact.id } },
status: INVOICE_STATUS_PUBLISHED,
})

const invoices = await Invoice.getAll(residentClient, {}, { sortBy: ['updatedAt_DESC'] })

expect(invoices).toEqual([
expect.objectContaining({
id: invoice.id,
client: expect.objectContaining({ id: resident.user.id, name: resident.user.name }),
}),
])

await updateTestResident(adminClient, resident.id, { deletedAt: faker.date.recent() })
const [updatedInvoice] = await updateTestInvoice(staffClient, invoice.id, { status: INVOICE_STATUS_CANCELED })

expect(updatedInvoice.client.id).toBe(resident.user.id)
expect(updatedInvoice.status).toBe(INVOICE_STATUS_CANCELED)
})
})

describe('virtual fields check', () => {
Expand Down

0 comments on commit 90d5238

Please sign in to comment.