diff --git a/src/idv_service/session/retrieve/identity.profile.failure.reason.response.js b/src/idv_service/session/retrieve/identity.profile.failure.reason.response.js index dda0fb12..ecca979b 100644 --- a/src/idv_service/session/retrieve/identity.profile.failure.reason.response.js +++ b/src/idv_service/session/retrieve/identity.profile.failure.reason.response.js @@ -2,16 +2,60 @@ const Validation = require('../../../yoti_common/validation'); +/** + * @typedef {Object} RequirementsNotMetDetail + * @property {string} [failureType] + * @property {string} [documentType] + * @property {string} [documentCountryIsoCode] + * @property {string} [auditId] + * @property {string} [details] + */ + class IdentityProfileFailureReasonResponse { constructor(failureReason) { Validation.isString(failureReason.reason_code, 'reason code'); /** @private */ this.reasonCode = failureReason.reason_code; + + /** @private */ + this.requirementsNotMetDetails = []; + + // eslint-disable-next-line camelcase + const { requirements_not_met_details: requirementsNotMetDetails } = failureReason; + if (requirementsNotMetDetails) { + Validation.isArray(requirementsNotMetDetails, 'requirements not met details'); + + this.requirementsNotMetDetails = requirementsNotMetDetails.map((detail) => { + const { + failure_type: failureType, + document_type: documentType, + document_country_iso_code: documentCountryIsoCode, + audit_id: auditId, + details, + } = detail; + + return ({ + failureType, + documentType, + documentCountryIsoCode, + auditId, + details, + }); + }); + } + /** @private */ } getReasonCode() { return this.reasonCode; } + + /** + * @returns {RequirementsNotMetDetail[]} + */ + getRequirementsNotMetDetails() { + return this.requirementsNotMetDetails; + } } module.exports = IdentityProfileFailureReasonResponse; diff --git a/tests/idv_service/session/retrieve/identity.profile.response.spec.js b/tests/idv_service/session/retrieve/identity.profile.response.spec.js index ac4064bd..8f7f059f 100644 --- a/tests/idv_service/session/retrieve/identity.profile.response.spec.js +++ b/tests/idv_service/session/retrieve/identity.profile.response.spec.js @@ -10,7 +10,23 @@ describe('IdentityProfileResponse', () => { subject_id: 'someStringHere', result: 'DONE', failure_reason: { - reason_code: 'MANDATORY_DOCUMENT_COULD_NOT_BE_PROVIDED', + reason_code: 'MANDATORY_DOCUMENT_NOT_PROVIDED', + requirements_not_met_details: [ + { + failure_type: 'ID_DOCUMENT_EXTRACTION', + document_type: 'PASSPORT', + document_country_iso_code: 'GBR', + audit_id: 'audit-123', + details: 'something not right', + }, + { + failure_type: 'ID_DOCUMENT_AUTHENTICITY', + document_type: 'PASSPORT', + document_country_iso_code: 'GBR', + audit_id: 'audit-456', + details: 'something still not right', + }, + ], }, identity_profile_report: { trust_framework: 'UK_TFIDA', @@ -52,7 +68,23 @@ describe('IdentityProfileResponse', () => { expect(failureReason) .toBeInstanceOf(IdentityProfileFailureReasonResponse); - expect(failureReason.getReasonCode()).toBe('MANDATORY_DOCUMENT_COULD_NOT_BE_PROVIDED'); + expect(failureReason.getReasonCode()).toBe('MANDATORY_DOCUMENT_NOT_PROVIDED'); + expect(failureReason.getRequirementsNotMetDetails()).toHaveLength(2); + const [firstDetail, secondDetail] = failureReason.getRequirementsNotMetDetails(); + expect(firstDetail).toEqual(expect.objectContaining({ + failureType: 'ID_DOCUMENT_EXTRACTION', + documentType: 'PASSPORT', + documentCountryIsoCode: 'GBR', + auditId: 'audit-123', + details: 'something not right', + })); + expect(secondDetail).toEqual(expect.objectContaining({ + failureType: 'ID_DOCUMENT_AUTHENTICITY', + documentType: 'PASSPORT', + documentCountryIsoCode: 'GBR', + auditId: 'audit-456', + details: 'something still not right', + })); }); }); diff --git a/types/src/idv_service/session/retrieve/identity.profile.failure.reason.response.d.ts b/types/src/idv_service/session/retrieve/identity.profile.failure.reason.response.d.ts index 7aaa8d68..bb940d54 100644 --- a/types/src/idv_service/session/retrieve/identity.profile.failure.reason.response.d.ts +++ b/types/src/idv_service/session/retrieve/identity.profile.failure.reason.response.d.ts @@ -1,7 +1,31 @@ export = IdentityProfileFailureReasonResponse; +/** + * @typedef {Object} RequirementsNotMetDetail + * @property {string} [failureType] + * @property {string} [documentType] + * @property {string} [documentCountryIsoCode] + * @property {string} [auditId] + * @property {string} [details] + */ declare class IdentityProfileFailureReasonResponse { constructor(failureReason: any); /** @private */ private reasonCode; + /** @private */ + private requirementsNotMetDetails; getReasonCode(): any; + /** + * @returns {RequirementsNotMetDetail[]} + */ + getRequirementsNotMetDetails(): RequirementsNotMetDetail[]; } +declare namespace IdentityProfileFailureReasonResponse { + export { RequirementsNotMetDetail }; +} +type RequirementsNotMetDetail = { + failureType?: string; + documentType?: string; + documentCountryIsoCode?: string; + auditId?: string; + details?: string; +};