Skip to content

Commit

Permalink
Surface the 'requirements not met details' within the IdentityProfile…
Browse files Browse the repository at this point in the history
…FailureReasonResponse.
  • Loading branch information
laurent-yoti committed Apr 10, 2024
1 parent 545777a commit a1c81e9
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
}));
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
};

0 comments on commit a1c81e9

Please sign in to comment.