Skip to content

Commit 008c689

Browse files
committed
SDK-2557 Fix validation in IDV responses
- "subject_id" optional in AdvancedIdentityProfileResponse - "details" optional in IdentityProfileRequirementsNotMetDetailResponse
1 parent e8f3b6a commit 008c689

File tree

4 files changed

+40
-30
lines changed

4 files changed

+40
-30
lines changed

src/idv_service/session/retrieve/identity_profile/advanced/advanced.identity.profile.response.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ const IdentityProfileFailureReasonResponse = require('../identity.profile.failur
66

77
class AdvancedIdentityProfileResponse {
88
constructor(response) {
9-
Validation.isString(response.subject_id, 'subject_id');
9+
Validation.isString(response.subject_id, 'subject_id', true);
1010
/** @private {string} */
11-
this.subjectId = response.subject_id;
11+
this.subjectId = response.subject_id || '';
1212

1313
Validation.isString(response.result, 'result');
1414
/** @private {string} */

src/idv_service/session/retrieve/identity_profile/identity.profile.requirements.not.met.detail.response.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class IdentityProfileRequirementsNotMetDetailResponse {
2020
/** @private {string|undefined} */
2121
this.auditId = requirementsNotMetDetail.audit_id;
2222

23-
Validation.isString(requirementsNotMetDetail.details, 'details');
24-
/** @private {string} */
23+
Validation.isString(requirementsNotMetDetail.details, 'details', true);
24+
/** @private {string|undefined} */
2525
this.details = requirementsNotMetDetail.details;
2626
}
2727

tests/idv_service/session/retrieve/identity_profile/advanced/advanced.identity.profile.response.spec.js

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -52,42 +52,52 @@ const reportResponse = {
5252
media: {},
5353
};
5454

55+
const response = {
56+
subject_id: 'some-subject',
57+
result: 'DONE',
58+
failure_reason: {
59+
reason_code: 'MANDATORY_DOCUMENT_NOT_PROVIDED',
60+
requirements_not_met_details: [
61+
{
62+
failure_type: 'ID_DOCUMENT_EXTRACTION',
63+
document_type: 'PASSPORT',
64+
document_country_iso_code: 'GBR',
65+
audit_id: 'audit-123',
66+
details: 'something not right',
67+
},
68+
{
69+
failure_type: 'ID_DOCUMENT_AUTHENTICITY',
70+
document_type: 'PASSPORT',
71+
document_country_iso_code: 'GBR',
72+
audit_id: 'audit-456',
73+
details: 'something still not right',
74+
},
75+
],
76+
},
77+
identity_profile_report: reportResponse,
78+
};
79+
5580
describe('AdvancedIdentityProfileResponse', () => {
5681
let advancedIdentityProfileResponse;
5782

5883
beforeEach(() => {
59-
const response = {
60-
subject_id: 'some-subject',
61-
result: 'DONE',
62-
failure_reason: {
63-
reason_code: 'MANDATORY_DOCUMENT_NOT_PROVIDED',
64-
requirements_not_met_details: [
65-
{
66-
failure_type: 'ID_DOCUMENT_EXTRACTION',
67-
document_type: 'PASSPORT',
68-
document_country_iso_code: 'GBR',
69-
audit_id: 'audit-123',
70-
details: 'something not right',
71-
},
72-
{
73-
failure_type: 'ID_DOCUMENT_AUTHENTICITY',
74-
document_type: 'PASSPORT',
75-
document_country_iso_code: 'GBR',
76-
audit_id: 'audit-456',
77-
details: 'something still not right',
78-
},
79-
],
80-
},
81-
identity_profile_report: reportResponse,
82-
};
83-
8484
advancedIdentityProfileResponse = new AdvancedIdentityProfileResponse(response);
8585
});
8686

8787
describe('#getSubjectId', () => {
8888
it('Should return ID', () => {
8989
expect(advancedIdentityProfileResponse.getSubjectId()).toBe('some-subject');
9090
});
91+
92+
describe('with a non existing "subject_id"', () => {
93+
it('should still parse the response and return empty string for #getSubjectId', () => {
94+
const responseWithoutSubjectId = { ...response };
95+
delete responseWithoutSubjectId.subject_id;
96+
// eslint-disable-next-line max-len
97+
advancedIdentityProfileResponse = new AdvancedIdentityProfileResponse(responseWithoutSubjectId);
98+
expect(advancedIdentityProfileResponse.getSubjectId()).toBe('');
99+
});
100+
});
91101
});
92102

93103
describe('#getResult', () => {

types/src/idv_service/session/retrieve/identity_profile/identity.profile.requirements.not.met.detail.response.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ declare class IdentityProfileRequirementsNotMetDetailResponse {
99
private documentCountryIsoCode;
1010
/** @private {string|undefined} */
1111
private auditId;
12-
/** @private {string} */
12+
/** @private {string|undefined} */
1313
private details;
1414
/**
1515
* @returns {string}

0 commit comments

Comments
 (0)