Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(DOMA-10698): fixed some cases of unitName parsing #5500

Closed
Closed
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
1 change: 0 additions & 1 deletion apps/condo/domains/billing/utils/receiptQRCodeUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ async function findAuxiliaryData (qrCodeFields, errors) {
const normalizedAddress = await addressServiceClient.search(getQRCodeField(qrCodeFields, 'PayerAddress'), { extractUnit: true })

if (!normalizedAddress.addressKey || !normalizedAddress.unitType || !normalizedAddress.unitName) throw errors.address

const properties = await find('Property', {
organization: { tin: getQRCodeField(qrCodeFields, 'PayeeINN'), deletedAt: null },
addressKey: normalizedAddress.addressKey,
Expand Down
12 changes: 6 additions & 6 deletions apps/condo/domains/billing/utils/receiptQRCodeUtils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ describe('receiptQRCodeUtils', () => {
})

test('Auxiliary data: throw an error if address not found', async () => {
const [o10n] = await createTestOrganization(adminClient)
const [property] = await createTestProperty(adminClient, o10n)
const [organization] = await createTestOrganization(adminClient)
const [property] = await createTestProperty(adminClient, organization)

const bic = createValidRuRoutingNumber()
const qrCodeObj = {
Expand All @@ -316,15 +316,15 @@ describe('receiptQRCodeUtils', () => {
PaymPeriod: '06.2024',
Sum: '10000',
PersAcc: faker.random.numeric(8),
PayeeINN: o10n.tin,
PayeeINN: organization.tin,
PersonalAcc: createValidRuNumber(bic),
}

await addBillingIntegrationAndContext(adminClient, o10n, {}, { status: CONTEXT_FINISHED_STATUS })
await addAcquiringIntegrationAndContext(adminClient, o10n, {}, { status: CONTEXT_FINISHED_STATUS })
await addBillingIntegrationAndContext(adminClient, organization, {}, { status: CONTEXT_FINISHED_STATUS })
await addAcquiringIntegrationAndContext(adminClient, organization, {}, { status: CONTEXT_FINISHED_STATUS })

await catchErrorFrom(
async () => await findAuxiliaryData({ ...qrCodeObj, PayerAddress: `${property.address}, кв` }, { address: new Error('error about address') }),
async () => await findAuxiliaryData({ ...qrCodeObj, PayerAddress: 'some-property-address' }, { address: new Error('error about address') }),
(err) => {
expect(err.message).toMatch('error about address')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ const KEYWORDS = {
parking: ['автоместо', 'парковка', 'паркинг', 'машиноместо', 'гараж', 'м/м', 'мм', 'место', 'м/место', 'а/м', 'бокс', 'парк'],
apartment: ['аппарт', 'апарт', 'ап', 'к/п'],
commercial: ['офис', 'оф'],
warehouse: ['помещение', 'подвал', 'помещ', 'пом', 'кл', 'кладовка', 'кладовая', 'нп'],
warehouse: ['помещение', 'подвал', 'помещ', 'пом', 'кл', 'кладовка', 'кладовая', 'нп', 'клад'],
flat: ['квартира', 'кв', 'комн'],
}

const HOUSE_IDENTIFIERS = 'д|уч|дом|участок|двлд'
const HOUSE_IDENTIFIERS = 'д|уч|дом|участок|двлд|домовладение'
Comment on lines -5 to +9
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we think to make that configurable through environment?

const SPLIT_SYMBOL = '%'

class AddressFromStringParser {
Expand Down Expand Up @@ -60,11 +60,12 @@ class AddressFromStringParser {
parseUnit (unitInput = '') {
let detectedType = null
for (const unitType in KEYWORDS) {
const unitTypeRegex = new RegExp(this.keywordsToRegexp(KEYWORDS[unitType]) + '[.]*', 'ig')
if (!detectedType && unitTypeRegex.test(unitInput)) {
const clearUnitTypeRegex = new RegExp(this.keywordsToRegexp(KEYWORDS[unitType]) + '[.\\s]+', 'ig')
const checkUnitTypeRegex = new RegExp(this.keywordsToRegexp(KEYWORDS[unitType]) + '[.]*', 'ig')
if (!detectedType && checkUnitTypeRegex.test(unitInput)) {
detectedType = unitType
}
unitInput = this.trim(unitInput.replace(unitTypeRegex, '').replace(/\s+/g, ' '))
unitInput = this.trim(unitInput.replace(clearUnitTypeRegex, '').replace(/\s+/g, ' '))
}
return {
unitName: unitInput,
Expand All @@ -79,7 +80,7 @@ class AddressFromStringParser {
splitByKeyword (input = '') {
const [housePart, unitPart = ''] = input
.replace(new RegExp(`[${SPLIT_SYMBOL}]`, 'g'), '')
.replace(this.splitRegexp, ` $1$2${SPLIT_SYMBOL}$3`)
.replace(this.splitRegexp, ` $1$2${SPLIT_SYMBOL}$3.`)
.split(SPLIT_SYMBOL)
return {
housePart: this.trim(housePart),
Expand All @@ -92,6 +93,12 @@ class AddressFromStringParser {
* @returns {{housePart: string, unitPart: string}}
*/
splitByComma (input = '') {
if (input.indexOf(',') === -1) {
return {
housePart: input,
unitPart: '',
}
}
const addressParts = input.split(',').map(part => part.trim())
const unit = addressParts.pop()
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ const ADDRESS_USE_CASES = [
['Свердловская обл, Сысертский р-н, Асбест п, Ключевская ул, д. 1 кв 000', 'Свердловская обл, Сысертский р-н, Асбест п, Ключевская ул, д. 1', 'flat', '000'],
['Свердловская обл, Сысертский р-н, Асбест п, Ключевская ул, д. 1 кв 0', 'Свердловская обл, Сысертский р-н, Асбест п, Ключевская ул, д. 1', 'flat', '0'],
['Свердловская обл, Сысертский р-н, Асбест п, Ключевская ул, д. 1 кв 0-1', 'Свердловская обл, Сысертский р-н, Асбест п, Ключевская ул, д. 1', 'flat', '0-1'],
['пр-т 100-летия Владивостока, д.32Д, НП10', 'пр-т 100-летия Владивостока, д.32Д', 'warehouse', 'НП10'],
['пр-т 100-летия Владивостока, д.32Д, НП 10', 'пр-т 100-летия Владивостока, д.32Д', 'warehouse', '10'],
['пр-т 100-летия Владивостока, домовладение 32Д клад. 10', 'пр-т 100-летия Владивостока, домовладение 32Д', 'warehouse', '10'],
['не-распознаваемая-ерунда-без-ничего', 'не-распознаваемая-ерунда-без-ничего', 'flat', ''],
]

describe('AddressFromStringParser', () => {
Expand Down Expand Up @@ -86,7 +90,7 @@ describe('AddressFromStringParser', () => {
const input = 'г. Казань, ул. Кремлевская, д. 18, кв. 25'
const result = parser.splitToUnitAndAddress(input)
expect(result.housePart).toEqual('г. Казань, ул. Кремлевская, д. 18')
expect(result.unitPart).toEqual('кв 25')
expect(result.unitPart).toEqual('кв. 25')
})
})
})
Expand Down
Loading