generated from 8iq/nodejs-hackathon-boilerplate-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/condo/doma 8371/support state organisations (#4375)
* feat(condo): DOMA-8371 add classificationCode field to BankAccount * feat(condo): DOMA-8371 add classificationCode test utils * refactor(condo): DOMA-8371 change validationFailureError to throw new GQLError in tests * feat(condo): DOMA-8371 add classificationCode field to BillingRecipient * feat(condo): DOMA-8371 add validations for routingNumber and classificationCode * feat(condo): DOMA-8371 add mutation and schema * feat(condo): DOMA-8371 add validation and tests for classificationCode * feat(condo): DOMA-8371 support '01..' routingNumber in FinanceInfoClient * feat(condo): DOMA-8371 fix test * fix(condo): DOMA-8371 pr fixes * fix(condo): DOMA-8371 fix test * feat(condo): DOMA-8371 remove validations for 01 bics
- Loading branch information
Showing
16 changed files
with
465 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
apps/condo/domains/banking/utils/validate/classificationCode.utils.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const { getCountrySpecificValidator } = require('./countrySpecificValidators') | ||
|
||
/* | ||
* Classification code validator | ||
* | ||
* The following check is performed: | ||
* 1) Сhecking for emptiness | ||
* | ||
* Example: | ||
* RU - 90205039900060030131 | ||
*/ | ||
|
||
const EMPTY = 'Classification code is empty' | ||
const NOT_NUMERIC = 'Classification code can contain only digits' | ||
|
||
const validateClassificationCode = (routingNumber, country) => { | ||
const errors = [] | ||
|
||
const classificationCodeWithoutSpaces = routingNumber.toString().trim() | ||
if (!classificationCodeWithoutSpaces.length) { | ||
errors.push(EMPTY) | ||
} | ||
if (!/^[0-9]*$/.test(classificationCodeWithoutSpaces)) { | ||
errors.push(NOT_NUMERIC) | ||
} | ||
|
||
getCountrySpecificValidator('classificationCode', country)(classificationCodeWithoutSpaces, errors) | ||
|
||
return { | ||
result: !errors.length, | ||
errors: errors, | ||
} | ||
} | ||
|
||
module.exports = { | ||
validateClassificationCode, | ||
} |
54 changes: 54 additions & 0 deletions
54
apps/condo/domains/banking/utils/validate/classificationCode.utils.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const { createValidRuClassificationCode } = require('@condo/domains/banking/utils/testSchema/bankAccount') | ||
const { validateClassificationCode } = require('@condo/domains/banking/utils/validate/classificationCode.utils') | ||
const { SPACE_SYMBOLS, SPACE_SYMBOL_LABLES } = require('@condo/domains/common/utils/string.utils') | ||
|
||
const SPACES = SPACE_SYMBOLS.split('') | ||
|
||
|
||
describe('validateClassificationCode', () => { | ||
describe('Ru', () => { | ||
|
||
const COUNTRY_CODE_RU = 'ru' | ||
const VALID_RU_CLASSIFICATION_CODE = ['90205039900060030131', '18205049900160030200', '15305036900250030200'] | ||
const WRONG_LENGTH_RU_CLASSIFICATION_CODE = '902050399000600301311' | ||
const WRONG_FORMAT_RU_CLASSIFICATION_CODE = 'A0205039900060030131' | ||
|
||
VALID_RU_CLASSIFICATION_CODE.forEach(code => { | ||
test(`should pass if valid: (${code})`, () => { | ||
const { result } = validateClassificationCode(code, COUNTRY_CODE_RU) | ||
expect(result).toBe(true) | ||
}) | ||
|
||
SPACES.forEach(spaceSymbol => { | ||
test(`should pass if valid: (${code}) with spaces symbol (${SPACE_SYMBOL_LABLES[spaceSymbol] || spaceSymbol})`, () => { | ||
const classificationCodeValue = `${spaceSymbol}${code}${spaceSymbol}` | ||
|
||
const { result } = validateClassificationCode(classificationCodeValue, COUNTRY_CODE_RU) | ||
expect(result).toBe(true) | ||
}) | ||
}) | ||
}) | ||
|
||
test('classification code from generator should pass', () => { | ||
const code = createValidRuClassificationCode() | ||
const { result } = validateClassificationCode(code, COUNTRY_CODE_RU) | ||
expect(result).toBe(true) | ||
}) | ||
|
||
test('should fail if has wrong length', () => { | ||
const { result, errors } = validateClassificationCode(WRONG_LENGTH_RU_CLASSIFICATION_CODE, COUNTRY_CODE_RU) | ||
expect(result).toBe(false) | ||
expect(errors[0]).toBe('Classification code length was expected to be 20, but received 21') | ||
}) | ||
test('should fail if contain invalid chars', () => { | ||
const { result, errors } = validateClassificationCode(WRONG_FORMAT_RU_CLASSIFICATION_CODE, COUNTRY_CODE_RU) | ||
expect(result).toBe(false) | ||
expect(errors[0]).toBe('Classification code can contain only digits') | ||
}) | ||
test('should fail if empty', () => { | ||
const { result, errors } = validateClassificationCode('', COUNTRY_CODE_RU) | ||
expect(result).toBe(false) | ||
expect(errors[0]).toBe('Classification code is empty') | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.