Skip to content

Commit b0bb1d3

Browse files
authored
fix(condo): DOMA-10854 add check for unitType (#5684)
* fix(condo): DOMA-10854 add check for unitType * fix(condo): DOMA-10854 add test cases
1 parent 02caac1 commit b0bb1d3

File tree

2 files changed

+219
-2
lines changed

2 files changed

+219
-2
lines changed

apps/condo/domains/ticket/schema/Ticket.test.js

+218-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const {
5858
createTestOrganizationEmployeeRole,
5959
updateTestOrganizationEmployee,
6060
} = require('@condo/domains/organization/utils/testSchema')
61-
const { FLAT_UNIT_TYPE, SECTION_SECTION_TYPE, COMMERCIAL_UNIT_TYPE, PARKING_SECTION_TYPE } = require('@condo/domains/property/constants/common')
61+
const { FLAT_UNIT_TYPE, WAREHOUSE_UNIT_TYPE, SECTION_SECTION_TYPE, COMMERCIAL_UNIT_TYPE, PARKING_SECTION_TYPE } = require('@condo/domains/property/constants/common')
6262
const {
6363
makeClientWithProperty,
6464
createTestProperty,
@@ -2720,6 +2720,223 @@ describe('Ticket', () => {
27202720

27212721
expect(readTicket.client.id).toEqual(residentClient.user.id)
27222722
})
2723+
2724+
test('ticket creating with sectionName, sectionType and floorName by resident user' +
2725+
'when unitName and unitType match in map and resident', async () => {
2726+
const residentClient = await makeClientWithResidentUser()
2727+
2728+
const [organization] = await createTestOrganization(admin)
2729+
2730+
const unitName = faker.random.alphaNumeric(5)
2731+
const unitType = WAREHOUSE_UNIT_TYPE
2732+
const sectionName = faker.random.alphaNumeric(5)
2733+
const sectionType = SECTION_SECTION_TYPE
2734+
const floorName = faker.random.alphaNumeric(5)
2735+
2736+
const [property] = await createTestProperty(admin, organization, {
2737+
map: {
2738+
dv: 1,
2739+
type: 'building',
2740+
sections: [
2741+
{
2742+
id: '1',
2743+
type: sectionType,
2744+
index: 1,
2745+
name: String(sectionName + 1),
2746+
preview: null,
2747+
floors: [
2748+
{
2749+
id: String(0),
2750+
type: 'floor',
2751+
index: 0,
2752+
name: String(floorName + 1),
2753+
units: [
2754+
{
2755+
id: String(0),
2756+
type: 'unit',
2757+
name: null,
2758+
label: unitName,
2759+
preview: null,
2760+
unitType: FLAT_UNIT_TYPE,
2761+
},
2762+
],
2763+
},
2764+
],
2765+
},
2766+
{
2767+
id: '2',
2768+
type: sectionType,
2769+
index: 2,
2770+
name: sectionName,
2771+
preview: null,
2772+
floors: [
2773+
{
2774+
id: String(1),
2775+
type: 'floor',
2776+
index: 1,
2777+
name: floorName,
2778+
units: [
2779+
{
2780+
id: String(1),
2781+
type: 'unit',
2782+
name: null,
2783+
label: unitName,
2784+
preview: null,
2785+
unitType: unitType,
2786+
},
2787+
],
2788+
},
2789+
],
2790+
},
2791+
],
2792+
},
2793+
})
2794+
2795+
await createTestResident(admin, residentClient.user, property, {
2796+
unitName,
2797+
unitType,
2798+
})
2799+
2800+
const [ticket] = await createTestTicket(residentClient, organization, property, {
2801+
unitName,
2802+
unitType,
2803+
})
2804+
2805+
const readTicket = await Ticket.getOne(residentClient, { id: ticket.id })
2806+
2807+
expect(readTicket.client.id).toEqual(residentClient.user.id)
2808+
expect(readTicket.unitName).toEqual(unitName)
2809+
expect(readTicket.unitType).toEqual(unitType)
2810+
expect(readTicket.sectionName).toEqual(sectionName)
2811+
expect(readTicket.sectionType).toEqual(sectionType)
2812+
expect(readTicket.floorName).toEqual(floorName)
2813+
})
2814+
2815+
test('ticket creating without sectionName, sectionType and floorName by resident user' +
2816+
'when unitType did not match in map and resident, but unitName the same', async () => {
2817+
const residentClient = await makeClientWithResidentUser()
2818+
2819+
const [organization] = await createTestOrganization(admin)
2820+
2821+
const unitName = faker.random.alphaNumeric(5)
2822+
const unitType = WAREHOUSE_UNIT_TYPE
2823+
2824+
const [property] = await createTestProperty(admin, organization, {
2825+
map: {
2826+
dv: 1,
2827+
type: 'building',
2828+
sections: [
2829+
{
2830+
id: '1',
2831+
type: SECTION_SECTION_TYPE,
2832+
index: 1,
2833+
name: '1',
2834+
preview: null,
2835+
floors: [
2836+
{
2837+
id: String(0),
2838+
type: 'floor',
2839+
index: 0,
2840+
name: String(0),
2841+
units: [
2842+
{
2843+
id: String(0),
2844+
type: 'unit',
2845+
name: null,
2846+
label: unitName,
2847+
preview: null,
2848+
unitType: FLAT_UNIT_TYPE,
2849+
},
2850+
],
2851+
},
2852+
],
2853+
},
2854+
],
2855+
},
2856+
})
2857+
2858+
await createTestResident(admin, residentClient.user, property, {
2859+
unitName,
2860+
unitType,
2861+
})
2862+
2863+
const [ticket] = await createTestTicket(residentClient, organization, property, {
2864+
unitName,
2865+
unitType,
2866+
})
2867+
2868+
const readTicket = await Ticket.getOne(residentClient, { id: ticket.id })
2869+
2870+
expect(readTicket.client.id).toEqual(residentClient.user.id)
2871+
expect(readTicket.unitName).toEqual(unitName)
2872+
expect(readTicket.unitType).toEqual(unitType)
2873+
expect(readTicket.sectionName).toBeNull()
2874+
expect(readTicket.sectionType).toBeNull()
2875+
expect(readTicket.floorName).toBeNull()
2876+
})
2877+
2878+
test('ticket creating without sectionName, sectionType and floorName by resident user' +
2879+
'when unitName did not match in map and resident, but unitType the same', async () => {
2880+
const residentClient = await makeClientWithResidentUser()
2881+
2882+
const [organization] = await createTestOrganization(admin)
2883+
2884+
const unitName = faker.random.alphaNumeric(5)
2885+
const unitType = FLAT_UNIT_TYPE
2886+
2887+
const [property] = await createTestProperty(admin, organization, {
2888+
map: {
2889+
dv: 1,
2890+
type: 'building',
2891+
sections: [
2892+
{
2893+
id: '1',
2894+
type: SECTION_SECTION_TYPE,
2895+
index: 1,
2896+
name: '1',
2897+
preview: null,
2898+
floors: [
2899+
{
2900+
id: String(0),
2901+
type: 'floor',
2902+
index: 0,
2903+
name: String(0),
2904+
units: [
2905+
{
2906+
id: String(0),
2907+
type: 'unit',
2908+
name: null,
2909+
label: faker.random.alphaNumeric(5),
2910+
preview: null,
2911+
unitType: FLAT_UNIT_TYPE,
2912+
},
2913+
],
2914+
},
2915+
],
2916+
},
2917+
],
2918+
},
2919+
})
2920+
2921+
await createTestResident(admin, residentClient.user, property, {
2922+
unitName,
2923+
unitType,
2924+
})
2925+
2926+
const [ticket] = await createTestTicket(residentClient, organization, property, {
2927+
unitName,
2928+
unitType,
2929+
})
2930+
2931+
const readTicket = await Ticket.getOne(residentClient, { id: ticket.id })
2932+
2933+
expect(readTicket.client.id).toEqual(residentClient.user.id)
2934+
expect(readTicket.unitName).toEqual(unitName)
2935+
expect(readTicket.unitType).toEqual(unitType)
2936+
expect(readTicket.sectionName).toBeNull()
2937+
expect(readTicket.sectionType).toBeNull()
2938+
expect(readTicket.floorName).toBeNull()
2939+
})
27232940
})
27242941

27252942
describe('contact', () => {

apps/condo/domains/ticket/utils/unit.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function getSectionAndFloorByUnitName (property, unitName, unitType) {
1616
for (const section of sections) {
1717
for (const floor of section.floors) {
1818
for (const unit of floor.units) {
19-
if (unit.label === unitName) {
19+
if (unit.label === unitName && unit.unitType === unitType) {
2020
res.sectionName = section.name
2121
res.sectionType = unitType !== PARKING_UNIT_TYPE ? SECTION_SECTION_TYPE : PARKING_SECTION_TYPE
2222
res.floorName = floor.name

0 commit comments

Comments
 (0)