Skip to content

Commit

Permalink
SDK-2453 include requirements_not_met_details in scheme compliance (#472
Browse files Browse the repository at this point in the history
)

* Created class IdentityProfileRequirementsNotMetDetailResponse to parse/expose the RequirementsNotMetDetail object.
Updated IdentityProfileFailureReasonResponse to use IdentityProfileRequirementsNotMetDetailResponse
Modified IdentityProfileReportSchemesComplianceResponse to include conditionally requirementsNotMetDetails, as a list of IdentityProfileRequirementsNotMetDetailResponse

* Fixes for JSDoc/Typescript
  • Loading branch information
laurent-yoti authored May 22, 2024
1 parent d507f4a commit 4cccee3
Show file tree
Hide file tree
Showing 9 changed files with 220 additions and 82 deletions.
Original file line number Diff line number Diff line change
@@ -1,61 +1,32 @@
'use strict';

const Validation = require('../../../yoti_common/validation');

/**
* @typedef {Object} RequirementsNotMetDetail
* @property {string} [failureType]
* @property {string} [documentType]
* @property {string} [documentCountryIsoCode]
* @property {string} [auditId]
* @property {string} [details]
*/
const IdentityProfileRequirementsNotMetDetailResponse = require('./identity.profile.requirements.not.met.detail.response');

class IdentityProfileFailureReasonResponse {
constructor(failureReason) {
Validation.isString(failureReason.reason_code, 'reason code');
/** @private */
/** @private @type {string} */
this.reasonCode = failureReason.reason_code;

/** @private */
/** @private @type {IdentityProfileRequirementsNotMetDetailResponse[]} */
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,
});
});
this.requirementsNotMetDetails = requirementsNotMetDetails
// eslint-disable-next-line max-len
.map((requirementsNotMetDetail) => new IdentityProfileRequirementsNotMetDetailResponse(requirementsNotMetDetail));
}
/** @private */
}

/**
* @returns {string}
*/
getReasonCode() {
return this.reasonCode;
}

/**
* @returns {RequirementsNotMetDetail[]}
*/
getRequirementsNotMetDetails() {
return this.requirementsNotMetDetails;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const Validation = require('../../../yoti_common/validation');
const IdentityProfileRequirementsNotMetDetailResponse = require('./identity.profile.requirements.not.met.detail.response');

class IdentityProfileReportSchemesComplianceResponse {
constructor(schemesCompliance) {
Expand All @@ -9,13 +10,24 @@ class IdentityProfileReportSchemesComplianceResponse {
this.scheme = schemesCompliance.scheme;

Validation.isBoolean(schemesCompliance.requirements_met, 'requirements_met');
/** @private */
/** @private @type {boolean} */
this.requirementsMet = schemesCompliance.requirements_met;

if (schemesCompliance.requirements_not_met_info) {
Validation.isString(schemesCompliance.requirements_not_met_info, 'requirements_not_met_info');
/** @private */
/** @private @type {string|undefined} */
this.requirementsNotMetInfo = schemesCompliance.requirements_not_met_info;

/** @private @type {IdentityProfileRequirementsNotMetDetailResponse[]|undefined} */
this.requirementsNotMetDetails = [];

if (schemesCompliance.requirements_not_met_details) {
Validation.isArray(schemesCompliance.requirements_not_met_details, 'requirements not met details');

this.requirementsNotMetDetails = schemesCompliance.requirements_not_met_details
// eslint-disable-next-line max-len
.map((requirementsNotMetDetail) => new IdentityProfileRequirementsNotMetDetailResponse(requirementsNotMetDetail));
}
}
}

Expand All @@ -26,19 +38,17 @@ class IdentityProfileReportSchemesComplianceResponse {
return this.scheme;
}

/**
* @returns {boolean}
*/
isRequirementsMet() {
return this.requirementsMet;
}

/**
* @returns {string}
*/
getRequirementsNotMetInfo() {
return this.requirementsNotMetInfo;
}

getRequirementsNotMetDetails() {
return this.requirementsNotMetDetails;
}
}

module.exports = IdentityProfileReportSchemesComplianceResponse;
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'use strict';

const Validation = require('../../../yoti_common/validation');

class IdentityProfileRequirementsNotMetDetailResponse {
constructor(requirementsNotMetDetail) {
Validation.isString(requirementsNotMetDetail.failure_type, 'failure_type');
/** @private @type {string} */
this.failureType = requirementsNotMetDetail.failure_type;

Validation.isString(requirementsNotMetDetail.document_type, 'document_type');
/** @private @type {string} */
this.documentType = requirementsNotMetDetail.document_type;

Validation.isString(requirementsNotMetDetail.document_country_iso_code, 'document_country_iso_code');
/** @private @type {string} */
this.documentCountryIsoCode = requirementsNotMetDetail.document_country_iso_code;

Validation.isString(requirementsNotMetDetail.audit_id, 'audit_id', true);
/** @private @type {string|undefined} */
this.auditId = requirementsNotMetDetail.audit_id;

Validation.isString(requirementsNotMetDetail.details, 'details');
/** @private @type {string} */
this.details = requirementsNotMetDetail.details;
}

getFailureType() {
return this.failureType;
}

getDocumentType() {
return this.documentType;
}

getDocumentCountryIsoCode() {
return this.documentCountryIsoCode;
}

getAuditId() {
return this.auditId;
}

getDetails() {
return this.details;
}
}

module.exports = IdentityProfileRequirementsNotMetDetailResponse;
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const IdentityProfileReportSchemesComplianceResponse = require('../../../../src/idv_service/session/retrieve/identity.profile.report.schemes.compliance.response');
const IdentityProfileRequirementsNotMetDetailResponse = require('../../../../src/idv_service/session/retrieve/identity.profile.requirements.not.met.detail.response');

describe('IdentityProfileReportSchemesComplianceResponse', () => {
let identityProfileReportSchemesComplianceResponse;
Expand All @@ -11,7 +12,6 @@ describe('IdentityProfileReportSchemesComplianceResponse', () => {
objective: 'STANDARD',
},
requirements_met: true,
requirements_not_met_info: 'some string here',
});
});

Expand All @@ -30,9 +30,63 @@ describe('IdentityProfileReportSchemesComplianceResponse', () => {
});
});

describe('#getRequirementsNotMetInfo', () => {
it('Should return requirements_not_met_info string', () => {
expect(identityProfileReportSchemesComplianceResponse.getRequirementsNotMetInfo()).toBe('some string here');
describe('with requirements not met', () => {
beforeAll(() => {
identityProfileReportSchemesComplianceResponse = new
IdentityProfileReportSchemesComplianceResponse({
scheme: {
type: 'DBS',
objective: 'STANDARD',
},
requirements_met: false,
requirements_not_met_info: 'some string here',
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',
},
],
});
});
describe('#getRequirementsNotMetInfo', () => {
it('Should return requirements_not_met_info string', () => {
expect(identityProfileReportSchemesComplianceResponse.getRequirementsNotMetInfo()).toBe('some string here');
});
});

describe('#getRequirementsNotMetDetails', () => {
it('Should return the list of RequirementsNotMetDetail', () => {
// eslint-disable-next-line max-len
const requirementsNotMetDetails = identityProfileReportSchemesComplianceResponse.getRequirementsNotMetDetails();
expect(requirementsNotMetDetails).toHaveLength(2);
const [firstDetail, secondDetail] = requirementsNotMetDetails;
expect(firstDetail).toBeInstanceOf(IdentityProfileRequirementsNotMetDetailResponse);
expect(firstDetail).toEqual(expect.objectContaining({
failureType: 'ID_DOCUMENT_EXTRACTION',
documentType: 'PASSPORT',
documentCountryIsoCode: 'GBR',
auditId: 'audit-123',
details: 'something not right',
}));
expect(firstDetail).toBeInstanceOf(IdentityProfileRequirementsNotMetDetailResponse);
expect(secondDetail).toEqual(expect.objectContaining({
failureType: 'ID_DOCUMENT_AUTHENTICITY',
documentType: 'PASSPORT',
documentCountryIsoCode: 'GBR',
auditId: 'audit-456',
details: 'something still not right',
}));
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const IdentityProfileRequirementsNotMetDetailResponse = require('../../../../src/idv_service/session/retrieve/identity.profile.requirements.not.met.detail.response');

describe('IdentityProfileRequirementsNotMetDetailResponse', () => {
let requirementsNotMetDetailResponse;

beforeEach(() => {
requirementsNotMetDetailResponse = new IdentityProfileRequirementsNotMetDetailResponse({
failure_type: 'ID_DOCUMENT_EXTRACTION',
document_type: 'PASSPORT',
document_country_iso_code: 'GBR',
audit_id: 'audit-123',
details: 'something not right',
});
});

describe('#getFailureType', () => {
it('Should return the failure type', () => {
expect(requirementsNotMetDetailResponse.getFailureType()).toBe('ID_DOCUMENT_EXTRACTION');
});
});

describe('#getDocumentType', () => {
it('Should return the document type', () => {
expect(requirementsNotMetDetailResponse.getDocumentType()).toBe('PASSPORT');
});
});

describe('#getDocumentCountryIsoCode', () => {
it('Should return the document country iso code', () => {
expect(requirementsNotMetDetailResponse.getDocumentCountryIsoCode()).toBe('GBR');
});
});

describe('#getAuditId', () => {
it('Should return the audit ID', () => {
expect(requirementsNotMetDetailResponse.getAuditId()).toBe('audit-123');
});
});

describe('#getDetails', () => {
it('Should return the details', () => {
expect(requirementsNotMetDetailResponse.getDetails()).toBe('something not right');
});
});

describe('default instance object', () => {
it('Should return an object with all the fields', () => {
expect(requirementsNotMetDetailResponse).toEqual(expect.objectContaining({
failureType: 'ID_DOCUMENT_EXTRACTION',
documentType: 'PASSPORT',
documentCountryIsoCode: 'GBR',
auditId: 'audit-123',
details: 'something not right',
}));
});
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const IdentityProfileResponse = require('../../../../src/idv_service/session/retrieve/identity.profile.response');
const IdentityProfileReportResponse = require('../../../../src/idv_service/session/retrieve/identity.profile.report.response');
const IdentityProfileFailureReasonResponse = require('../../../../src/idv_service/session/retrieve/identity.profile.failure.reason.response');
const IdentityProfileRequirementsNotMetDetailResponse = require('../../../../src/idv_service/session/retrieve/identity.profile.requirements.not.met.detail.response');

describe('IdentityProfileResponse', () => {
let identityProfileResponse;
Expand Down Expand Up @@ -71,13 +72,15 @@ describe('IdentityProfileResponse', () => {
expect(failureReason.getReasonCode()).toBe('MANDATORY_DOCUMENT_NOT_PROVIDED');
expect(failureReason.getRequirementsNotMetDetails()).toHaveLength(2);
const [firstDetail, secondDetail] = failureReason.getRequirementsNotMetDetails();
expect(firstDetail).toBeInstanceOf(IdentityProfileRequirementsNotMetDetailResponse);
expect(firstDetail).toEqual(expect.objectContaining({
failureType: 'ID_DOCUMENT_EXTRACTION',
documentType: 'PASSPORT',
documentCountryIsoCode: 'GBR',
auditId: 'audit-123',
details: 'something not right',
}));
expect(firstDetail).toBeInstanceOf(IdentityProfileRequirementsNotMetDetailResponse);
expect(secondDetail).toEqual(expect.objectContaining({
failureType: 'ID_DOCUMENT_AUTHENTICITY',
documentType: 'PASSPORT',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,34 +1,11 @@
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 @type {string} */
private reasonCode;
/** @private */
/** @private @type {IdentityProfileRequirementsNotMetDetailResponse[]} */
private requirementsNotMetDetails;
/**
* @returns {string}
*/
getReasonCode(): string;
/**
* @returns {RequirementsNotMetDetail[]}
*/
getRequirementsNotMetDetails(): RequirementsNotMetDetail[];
getRequirementsNotMetDetails(): IdentityProfileRequirementsNotMetDetailResponse[];
}
declare namespace IdentityProfileFailureReasonResponse {
export { RequirementsNotMetDetail };
}
type RequirementsNotMetDetail = {
failureType?: string;
documentType?: string;
documentCountryIsoCode?: string;
auditId?: string;
details?: string;
};
import IdentityProfileRequirementsNotMetDetailResponse = require("./identity.profile.requirements.not.met.detail.response");
Loading

0 comments on commit 4cccee3

Please sign in to comment.