From 8646f352baf1e70bbc161edfde8a4319614d20bd Mon Sep 17 00:00:00 2001 From: ElliotMurphyGDS Date: Tue, 29 Oct 2024 12:24:26 +0000 Subject: [PATCH] LIME-1273 - Adding new call to personInfo endpoint Signed-off-by: ElliotMurphyGDS --- .secrets.baseline | 10 +- deploy/template.yaml | 88 ++-- src/app/drivingLicence/controllers/root.js | 186 +++++++- .../drivingLicence/controllers/root.test.js | 416 +++++++++++++++--- .../drivingLicence/controllers/validate.js | 3 + src/lib/config.js | 6 +- 6 files changed, 620 insertions(+), 89 deletions(-) diff --git a/.secrets.baseline b/.secrets.baseline index ee2a71cc..2981ac77 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -288,30 +288,30 @@ "filename": "deploy/template.yaml", "hashed_secret": "690de9fd42add772818ae392cb68a4f81d1511e3", "is_verified": false, - "line_number": 105 + "line_number": 109 }, { "type": "Secret Keyword", "filename": "deploy/template.yaml", "hashed_secret": "b63bf00edb07af6ffba7f7ceb7ed573a913271f7", "is_verified": false, - "line_number": 587 + "line_number": 629 }, { "type": "Secret Keyword", "filename": "deploy/template.yaml", "hashed_secret": "42af5cf9fcf4f09147c032a0fb4877f5cf626bbc", "is_verified": false, - "line_number": 588 + "line_number": 630 }, { "type": "Secret Keyword", "filename": "deploy/template.yaml", "hashed_secret": "7584a31168b8e8f62d9b84b7b95d239b99fad815", "is_verified": false, - "line_number": 590 + "line_number": 632 } ] }, - "generated_at": "2024-10-25T12:58:37Z" + "generated_at": "2024-10-31T12:03:06Z" } diff --git a/deploy/template.yaml b/deploy/template.yaml index 224c5cca..b584aeba 100644 --- a/deploy/template.yaml +++ b/deploy/template.yaml @@ -75,6 +75,7 @@ Mappings: ga4Disabled: "false" uaDisabled: "false" languageToggleDisabled: "false" + authSourceEnabled: "true" build: logLevel: "info" dynatraceSecretArn: arn:aws:secretsmanager:eu-west-2:216552277552:secret:DynatraceNonProductionVariables @@ -83,6 +84,7 @@ Mappings: ga4Disabled: "false" uaDisabled: "false" languageToggleDisabled: "false" + authSourceEnabled: "true" staging: logLevel: "warn" dynatraceSecretArn: arn:aws:secretsmanager:eu-west-2:216552277552:secret:DynatraceNonProductionVariables @@ -92,6 +94,7 @@ Mappings: ga4Disabled: "false" uaDisabled: "false" languageToggleDisabled: "false" + authSourceEnabled: "false" integration: logLevel: "warn" dynatraceSecretArn: arn:aws:secretsmanager:eu-west-2:216552277552:secret:DynatraceNonProductionVariables @@ -100,6 +103,7 @@ Mappings: ga4Disabled: "false" uaDisabled: "false" languageToggleDisabled: "false" + authSourceEnabled: "false" production: logLevel: "warn" dynatraceSecretArn: arn:aws:secretsmanager:eu-west-2:216552277552:secret:DynatraceProductionVariables @@ -108,6 +112,7 @@ Mappings: ga4Disabled: "false" uaDisabled: "false" languageToggleDisabled: "false" + authSourceEnabled: "false" # see https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-access-logs.html ElasticLoadBalancerAccountIds: @@ -203,7 +208,7 @@ Resources: !FindInMap [ ElasticLoadBalancerAccountIds, !Ref AWS::Region, - AccountId, + AccountId ] Action: - s3:PutObject @@ -482,20 +487,47 @@ Resources: - Name: GOOGLE_ANALYTICS_4_GTM_CONTAINER_ID Value: !If [IsProduction, "GTM-K4PBJH3", "GTM-KD86CMZ"] - Name: GA4_DISABLED - Value: !FindInMap [ EnvironmentConfiguration, !Ref "Environment", ga4Disabled ] + Value: + !FindInMap [ + EnvironmentConfiguration, + !Ref "Environment", + ga4Disabled + ] - Name: UA_DISABLED - Value: !FindInMap [ EnvironmentConfiguration, !Ref "Environment", uaDisabled ] + Value: + !FindInMap [ + EnvironmentConfiguration, + !Ref "Environment", + uaDisabled + ] - Name: LANGUAGE_TOGGLE_DISABLED - Value: !FindInMap [ EnvironmentConfiguration, !Ref "Environment", languageToggleDisabled ] + Value: + !FindInMap [ + EnvironmentConfiguration, + !Ref "Environment", + languageToggleDisabled + ] - Name: ANALYTICS_DOMAIN Value: !If [ IsProduction, "account.gov.uk", - !Sub "${Environment}.account.gov.uk", + !Sub "${Environment}.account.gov.uk" ] - Name: LOG_LEVEL - Value: !FindInMap [ EnvironmentConfiguration, !Ref "Environment", logLevel ] + Value: + !FindInMap [ + EnvironmentConfiguration, + !Ref "Environment", + logLevel + ] + - Name: AUTH_SOURCE_ENABLED + Value: + !FindInMap [ + EnvironmentConfiguration, + !Ref "Environment", + authSourceEnabled + ] Secrets: - Name: DT_TENANT ValueFrom: !Join @@ -503,7 +535,7 @@ Resources: - - !FindInMap [ EnvironmentConfiguration, !Ref Environment, - dynatraceSecretArn, + dynatraceSecretArn ] - ":DT_TENANT::" - Name: DT_TENANTTOKEN @@ -512,7 +544,7 @@ Resources: - - !FindInMap [ EnvironmentConfiguration, !Ref Environment, - dynatraceSecretArn, + dynatraceSecretArn ] - ":DT_TENANTTOKEN::" - Name: DT_CONNECTION_POINT @@ -521,7 +553,7 @@ Resources: - - !FindInMap [ EnvironmentConfiguration, !Ref Environment, - dynatraceSecretArn, + dynatraceSecretArn ] - ":DT_CONNECTION_POINT::" PortMappings: @@ -533,9 +565,19 @@ Resources: awslogs-group: !Ref ECSAccessLogsGroup awslogs-region: !Sub ${AWS::Region} awslogs-stream-prefix: !Sub driving-permit-front-${Environment} - Cpu: !FindInMap [ EnvironmentConfiguration, !Ref "Environment", fargateCPUsize ] + Cpu: + !FindInMap [ + EnvironmentConfiguration, + !Ref "Environment", + fargateCPUsize + ] ExecutionRoleArn: !GetAtt ECSTaskExecutionRole.Arn - Memory: !FindInMap [ EnvironmentConfiguration, !Ref "Environment", fargateRAMsize ] + Memory: + !FindInMap [ + EnvironmentConfiguration, + !Ref "Environment", + fargateRAMsize + ] NetworkMode: awsvpc RequiresCompatibilities: - FARGATE @@ -845,8 +887,7 @@ Resources: # with <5% utilisation - MetricIntervalLowerBound: -15 # 5% MetricIntervalUpperBound: 0 # 20% - ScalingAdjustment: - -50 # Scale down 50% of containers if the metric is breached + ScalingAdjustment: -50 # Scale down 50% of containers if the metric is breached # with <20% utilisation EcsStepScaleOutAlarm: @@ -1012,7 +1053,6 @@ Resources: Period: 60 Stat: Sum - #################################################################### # # # Alarm setup # @@ -1065,8 +1105,7 @@ Resources: LogGroupName: !Ref ECSAccessLogsGroup FilterPattern: '{ $.level = "FATAL" || $.message = "Unhandled Exception:*" }' MetricTransformations: - - - MetricValue: "1" + - MetricValue: "1" MetricNamespace: !Sub "${AWS::StackName}/LogMessages" MetricName: "ECSFatalerror-message" @@ -1082,11 +1121,11 @@ Resources: - !ImportValue platform-alarm-warning-alert-topic AlarmActions: - !ImportValue platform-alarm-warning-alert-topic - InsufficientDataActions: [ ] + InsufficientDataActions: [] MetricName: ECSFatalerror-message Namespace: !Sub "${AWS::StackName}/LogMessages" Statistic: Sum - Dimensions: [ ] + Dimensions: [] Period: 60 EvaluationPeriods: 1 DatapointsToAlarm: 1 @@ -1100,8 +1139,7 @@ Resources: LogGroupName: !Ref APIGWAccessLogsGroup FilterPattern: '{ $.level = "FATAL" || $.message = "Unhandled Exception:*" }' MetricTransformations: - - - MetricValue: "1" + - MetricValue: "1" MetricNamespace: !Sub "${AWS::StackName}/LogMessages" MetricName: "APIGWFatalerror-message" @@ -1117,11 +1155,11 @@ Resources: - !ImportValue platform-alarm-warning-alert-topic AlarmActions: - !ImportValue platform-alarm-warning-alert-topic - InsufficientDataActions: [ ] + InsufficientDataActions: [] MetricName: APIGWFatalerror-message Namespace: !Sub "${AWS::StackName}/LogMessages" Statistic: Sum - Dimensions: [ ] + Dimensions: [] Period: 60 EvaluationPeriods: 1 DatapointsToAlarm: 1 @@ -1189,7 +1227,7 @@ Resources: - !ImportValue platform-alarm-warning-alert-topic AlarmActions: - !ImportValue platform-alarm-warning-alert-topic - InsufficientDataActions: [ ] + InsufficientDataActions: [] EvaluationPeriods: 5 DatapointsToAlarm: 2 Threshold: 5 @@ -1238,7 +1276,7 @@ Resources: - !ImportValue platform-alarm-warning-alert-topic AlarmActions: - !ImportValue platform-alarm-warning-alert-topic - InsufficientDataActions: [ ] + InsufficientDataActions: [] EvaluationPeriods: 5 DatapointsToAlarm: 2 Threshold: 1000 @@ -1283,7 +1321,7 @@ Resources: - !ImportValue platform-alarm-warning-alert-topic AlarmActions: - !ImportValue platform-alarm-warning-alert-topic - InsufficientDataActions: [ ] + InsufficientDataActions: [] EvaluationPeriods: 5 DatapointsToAlarm: 2 Threshold: 2500 diff --git a/src/app/drivingLicence/controllers/root.js b/src/app/drivingLicence/controllers/root.js index 16cd27a4..5f1ffbd7 100644 --- a/src/app/drivingLicence/controllers/root.js +++ b/src/app/drivingLicence/controllers/root.js @@ -1,21 +1,191 @@ const { Controller: BaseController } = require("hmpo-form-wizard"); +const { + API: { + BASE_URL, + PATHS: { PERSON_INFO } + } +} = require("../../../lib/config"); + class RootController extends BaseController { async saveValues(req, res, next) { - const sharedClaims = req.session?.shared_claims; + req.sessionModel.reset(); + req.sessionModel.set("isAuthSourceRoute", false); - if (sharedClaims) { - if (sharedClaims?.names?.length > 0) { - req.journeyModel.set("surname", sharedClaims.names[0]?.familyName); - req.journeyModel.set("givenNames", sharedClaims.names[0]?.givenNames); - } + const headers = { + session_id: req.session?.tokenId + }; + + if (process.env.AUTH_SOURCE_ENABLED === "true") { + //axios.post to new personInfo endpoint, put licence details into req.session.shared_claims shared claims + const personInfoApiResponse = await req.axios.get( + `${BASE_URL}/${PERSON_INFO}`, + { headers: headers } + ); + + req.sessionModel.set( + "isAuthSourceRoute", + this.checkForValidSharedClaimsData(req, personInfoApiResponse) + ); + + if (req.sessionModel.get("isAuthSourceRoute") === true) { + req.sessionModel.set( + "drivingLicenceNumber", + personInfoApiResponse.data.drivingPermit[0].personalNumber + ); + + req.sessionModel.set( + "expiryDate", + personInfoApiResponse.data.drivingPermit[0].expiryDate + ); + + req.sessionModel.set( + "issueDate", + personInfoApiResponse.data.drivingPermit[0].issueDate + ); + + req.sessionModel.set( + "licenceIssuer", + personInfoApiResponse.data.drivingPermit[0].issuedBy + ); + + req.sessionModel.set( + "postcode", + personInfoApiResponse.data.address[0].postalCode + ); + + if (personInfoApiResponse.data.drivingPermit[0]?.issuedBy === "DVLA") { + req.sessionModel.set( + "issueNumber", + personInfoApiResponse.data.drivingPermit[0].issueNumber + ); + } - if (sharedClaims?.dateOfBirths?.length > 0) { - req.journeyModel.set("dateOfBirth", sharedClaims.dateOfBirths[0]); + this.setNames(req, personInfoApiResponse.data.name[0].nameParts); + + req.sessionModel.set( + "dateOfBirth", + personInfoApiResponse.data.birthDate[0].value + ); } } super.saveValues(req, res, next); } + + checkForValidSharedClaimsData(req, personInfoApiResponse) { + if ( + undefined === personInfoApiResponse?.data?.drivingPermit || + "" === personInfoApiResponse?.data?.drivingPermit + ) { + return false; + } else { + const drivingPermit = personInfoApiResponse?.data?.drivingPermit[0]; + if ( + undefined === drivingPermit?.personalNumber || + "" === drivingPermit?.personalNumber + ) { + return false; + } + + if ( + undefined === drivingPermit?.expiryDate || + "" === drivingPermit?.expiryDate + ) { + return false; + } + + if ( + undefined === drivingPermit?.issueDate || + "" === drivingPermit?.issueDate + ) { + return false; + } + + if ( + undefined === drivingPermit?.issuedBy || + "" === drivingPermit?.issuedBy + ) { + return false; + } + + if (drivingPermit?.issuedBy === "DVLA") { + if ( + undefined === drivingPermit?.issueNumber || + "" === drivingPermit?.issueNumber + ) { + return false; + } + } + } + + if ( + undefined === personInfoApiResponse?.data?.address || + "" === personInfoApiResponse?.data?.address + ) { + return false; + } else { + const address = personInfoApiResponse?.data?.address[0]; + if (undefined === address?.postalCode || "" === address?.postalCode) { + return false; + } + } + + if ( + undefined === personInfoApiResponse?.data?.birthDate || + "" === personInfoApiResponse?.data?.birthDate + ) { + return false; + } else { + const birthDate = personInfoApiResponse?.data?.birthDate[0]; + if (undefined === birthDate.value || "" === birthDate.value) { + return false; + } + } + + if ( + undefined === personInfoApiResponse?.data?.name || + "" === personInfoApiResponse?.data?.name + ) { + return false; + } else { + const name = personInfoApiResponse?.data?.name[0]; + if (undefined === name?.nameParts || "" === name?.nameParts) { + return false; + } else { + const namePart = name?.nameParts[0]; + if (undefined === namePart || "" === namePart) { + return false; + } + for (let i = 0; i < namePart.length; i++) { + if (undefined === namePart[i] || "" === namePart[i]) { + return false; + } + } + } + } + + return true; + } + + async setNames(req, nameParts) { + const givenNames = nameParts + .filter((part) => part.type === "GivenName") + .map((part) => part.value); + + const familyNames = nameParts + .filter((part) => part.type === "FamilyName") + .map((part) => part.value) + .join(" "); + + req.sessionModel.set("firstName", givenNames[0]); + + givenNames.shift(); + const middleNames = givenNames.join(" "); + + req.sessionModel.set("middleNames", middleNames); + + req.sessionModel.set("surname", familyNames); + } } module.exports = RootController; diff --git a/src/app/drivingLicence/controllers/root.test.js b/src/app/drivingLicence/controllers/root.test.js index 18e2bd3c..4b8f2bb1 100644 --- a/src/app/drivingLicence/controllers/root.test.js +++ b/src/app/drivingLicence/controllers/root.test.js @@ -1,49 +1,48 @@ const RootController = require("./root"); const { Controller: BaseController } = require("hmpo-form-wizard"); +let personInfoApiResponse = { + data: { + name: [ + { + nameParts: [ + { type: "GivenName", value: "KENNETH" }, + { type: "FamilyName", value: "DECERQUEIRA" } + ] + } + ], + birthDate: [{ value: "1965-07-08" }], + address: [ + { + postalCode: "BA2 5AA" + } + ], + drivingPermit: [ + { + personalNumber: "DOE99751010AL9OD", + expiryDate: "2022-02-02", + issueNumber: "13", + issuedBy: "DVLA", + issueDate: "2012-02-02", + fullAddress: "8 HADLEY ROAD BATH BA2 5AA" + } + ] + } +}; describe("root controller", () => { const root = new RootController({ route: "/test" }); - let req; let res; let next; let sandbox; - beforeEach(() => { sandbox = sinon.createSandbox(); + const setup = setupDefaultMocks(); + req = setup.req; + res = setup.res; + next = setup.next; - res = { - status: sinon.fake(), - redirect: sinon.fake(), - send: sinon.fake(), - render: sinon.fake() - }; - - req = { - query: { - client_id: "s6BhdRkqt3" - }, - session: { - shared_claims: { - names: [ - { givenNames: ["Dan John"], familyName: "Watson" }, - { givenNames: ["Daniel"], familyName: "Watson" }, - { givenNames: ["Danny, Dan"], familyName: "Watson" } - ], - dateOfBirths: ["2021-03-01", "1991-03-01"] - } - }, - sessionModel: { - get: sinon.fake(), - set: sinon.fake(), - unset: sinon.fake() - }, - journeyModel: { - set: sinon.fake() - }, - form: {} - }; - + process.env.AUTH_SOURCE_ENABLED = "false"; next = sinon.fake(); }); afterEach(() => sandbox.restore()); @@ -52,33 +51,352 @@ describe("root controller", () => { expect(root).to.be.an.instanceof(BaseController); }); - it("should retrieve shared_claims from session and store it in the journeyModel", async () => { + it("should updated SessionModel when middleName is Present", async () => { + process.env.AUTH_SOURCE_ENABLED = "true"; + + personInfoApiResponse = { + data: { + name: [ + { + nameParts: [ + { type: "GivenName", value: "KENNETH" }, + { type: "GivenName", value: "MiddleName" }, + { type: "FamilyName", value: "DECERQUEIRA" } + ] + } + ], + birthDate: [{ value: "1965-07-08" }], + address: [ + { + postalCode: "BA2 5AA" + } + ], + drivingPermit: [ + { + personalNumber: "DOE99751010AL9OD", + expiryDate: "2022-02-02", + issueNumber: "13", + issuedBy: "DVLA", + issueDate: "2012-02-02", + fullAddress: "8 HADLEY ROAD BATH BA2 5AA" + } + ] + } + }; + + const resolvedPromise = new Promise((resolve) => + resolve(personInfoApiResponse) + ); + sandbox.stub(req.axios, "get").returns(resolvedPromise); + + await root.saveValues(req, res, next); + expect(req.sessionModel.get("drivingLicenceNumber")).to.equal( + personInfoApiResponse.data.drivingPermit[0].personalNumber + ); + expect(req.sessionModel.get("expiryDate")).to.equal( + personInfoApiResponse.data.drivingPermit[0].expiryDate + ); + expect(req.sessionModel.get("issueDate")).to.equal( + personInfoApiResponse.data.drivingPermit[0].issueDate + ); + expect(req.sessionModel.get("licenceIssuer")).to.equal( + personInfoApiResponse.data.drivingPermit[0].issuedBy + ); + expect(req.sessionModel.get("postcode")).to.equal( + personInfoApiResponse.data.address[0].postalCode + ); + expect(req.sessionModel.get("issueNumber")).to.equal( + personInfoApiResponse.data.drivingPermit[0].issueNumber + ); + expect(req.sessionModel.get("firstName")).to.equal( + personInfoApiResponse.data.name[0].nameParts[0].value + ); + expect(req.sessionModel.get("middleNames")).to.equal( + personInfoApiResponse.data.name[0].nameParts[1].value + ); + expect(req.sessionModel.get("surname")).to.equal( + personInfoApiResponse.data.name[0].nameParts[2].value + ); + expect(req.sessionModel.get("dateOfBirth")).to.equal( + personInfoApiResponse.data.birthDate[0].value + ); + expect(req.sessionModel.get("isAuthSourceRoute")).to.equal(true); + }); + + it("should retrieve shared_claims from session and store it in the sessionModel", async () => { + personInfoApiResponse = { + data: { + name: [ + { + nameParts: [ + { type: "GivenName", value: "KENNETH" }, + { type: "FamilyName", value: "DECERQUEIRA" } + ] + } + ], + birthDate: [{ value: "1965-07-08" }], + address: [ + { + postalCode: "BA2 5AA" + } + ], + drivingPermit: [ + { + personalNumber: "DOE99751010AL9OD", + expiryDate: "2022-02-02", + issueNumber: "13", + issuedBy: "DVLA", + issueDate: "2012-02-02", + fullAddress: "8 HADLEY ROAD BATH BA2 5AA" + } + ] + } + }; + + const resolvedPromise = new Promise((resolve) => + resolve(personInfoApiResponse) + ); + sandbox.stub(req.axios, "get").returns(resolvedPromise); + + process.env.AUTH_SOURCE_ENABLED = "true"; + + await root.saveValues(req, res, next); + + expect(req.sessionModel.get("isAuthSourceRoute")).to.equal(true); + expect(req.sessionModel.get("drivingLicenceNumber")).to.equal( + personInfoApiResponse.data.drivingPermit[0].personalNumber + ); + expect(req.sessionModel.get("expiryDate")).to.equal( + personInfoApiResponse.data.drivingPermit[0].expiryDate + ); + expect(req.sessionModel.get("issueDate")).to.equal( + personInfoApiResponse.data.drivingPermit[0].issueDate + ); + expect(req.sessionModel.get("licenceIssuer")).to.equal( + personInfoApiResponse.data.drivingPermit[0].issuedBy + ); + expect(req.sessionModel.get("postcode")).to.equal( + personInfoApiResponse.data.address[0].postalCode + ); + expect(req.sessionModel.get("issueNumber")).to.equal( + personInfoApiResponse.data.drivingPermit[0].issueNumber + ); + expect(req.sessionModel.get("firstName")).to.equal( + personInfoApiResponse.data.name[0].nameParts[0].value + ); + expect(req.sessionModel.get("surname")).to.equal( + personInfoApiResponse.data.name[0].nameParts[1].value + ); + expect(req.sessionModel.get("dateOfBirth")).to.equal( + personInfoApiResponse.data.birthDate[0].value + ); + }); + + it("should not update sessionModel if personInfo response is empty", async () => { + personInfoApiResponse = {}; + + const resolvedPromise = new Promise((resolve) => + resolve(personInfoApiResponse) + ); + + sandbox.stub(req.axios, "get").returns(resolvedPromise); await root.saveValues(req, res, next); + expect(req.sessionModel.get("isAuthSourceRoute")).to.equal(false); + expect(req.sessionModel.get("drivingLicenceNumber")).to.equal(undefined); + expect(req.sessionModel.get("expiryDate")).to.equal(undefined); + expect(req.sessionModel.get("issueDate")).to.equal(undefined); + expect(req.sessionModel.get("licenceIssuer")).to.equal(undefined); + expect(req.sessionModel.get("postcode")).to.equal(undefined); + expect(req.sessionModel.get("issueNumber")).to.equal(undefined); + expect(req.sessionModel.get("firstName")).to.equal(undefined); + expect(req.sessionModel.get("surname")).to.equal(undefined); + expect(req.sessionModel.get("dateOfBirth")).to.equal(undefined); + }); - expect(req.journeyModel.set.getCall(0).args[0]).to.eq("surname"); - expect(req.journeyModel.set.getCall(0).args[1]).to.eq( - req.session.shared_claims.names[0].familyName + it("should not update sessionModel if personInfo response is empty", async () => { + personInfoApiResponse = { + data: { + name: [ + { + nameParts: [] + } + ], + address: [], + drivingPermit: [ + { + personalNumber: "DOE99751010AL9OD", + expiryDate: "2022-02-02", + issueNumber: "13", + issuedBy: "DVLA", + issueDate: "2012-02-02", + fullAddress: "8 HADLEY ROAD BATH BA2 5AA" + } + ] + } + }; + + const resolvedPromise = new Promise((resolve) => + resolve(personInfoApiResponse) ); - expect(req.journeyModel.set.getCall(1).args[0]).to.eq("givenNames"); - expect(req.journeyModel.set.getCall(1).args[1]).to.eq( - req.session.shared_claims.names[0].givenNames + sandbox.stub(req.axios, "get").returns(resolvedPromise); + await root.saveValues(req, res, next); + expect(req.sessionModel.get("isAuthSourceRoute")).to.equal(false); + expect(req.sessionModel.get("drivingLicenceNumber")).to.equal(undefined); + expect(req.sessionModel.get("expiryDate")).to.equal(undefined); + expect(req.sessionModel.get("issueDate")).to.equal(undefined); + expect(req.sessionModel.get("licenceIssuer")).to.equal(undefined); + expect(req.sessionModel.get("postcode")).to.equal(undefined); + expect(req.sessionModel.get("issueNumber")).to.equal(undefined); + expect(req.sessionModel.get("firstName")).to.equal(undefined); + expect(req.sessionModel.get("surname")).to.equal(undefined); + expect(req.sessionModel.get("dateOfBirth")).to.equal(undefined); + }); + + it("should not update sessionModel if personInfo response is empty", async () => { + personInfoApiResponse = { + data: { + name: [ + { + nameParts: [] + } + ], + birthDate: [], + address: [], + drivingPermit: [] + } + }; + + const resolvedPromise = new Promise((resolve) => + resolve(personInfoApiResponse) ); - expect(req.journeyModel.set.getCall(2).args[0]).to.eq("dateOfBirth"); - expect(req.journeyModel.set.getCall(2).args[1]).to.eq( - req.session.shared_claims.dateOfBirths[0] + sandbox.stub(req.axios, "get").returns(resolvedPromise); + await root.saveValues(req, res, next); + expect(req.sessionModel.get("isAuthSourceRoute")).to.equal(false); + expect(req.sessionModel.get("drivingLicenceNumber")).to.equal(undefined); + expect(req.sessionModel.get("expiryDate")).to.equal(undefined); + expect(req.sessionModel.get("issueDate")).to.equal(undefined); + expect(req.sessionModel.get("licenceIssuer")).to.equal(undefined); + expect(req.sessionModel.get("postcode")).to.equal(undefined); + expect(req.sessionModel.get("issueNumber")).to.equal(undefined); + expect(req.sessionModel.get("firstName")).to.equal(undefined); + expect(req.sessionModel.get("surname")).to.equal(undefined); + expect(req.sessionModel.get("dateOfBirth")).to.equal(undefined); + }); + + it("should not update sessionModel if personInfo response is empty", async () => { + personInfoApiResponse = { + data: { + birthDate: [], + drivingPermit: [] + } + }; + + const resolvedPromise = new Promise((resolve) => + resolve(personInfoApiResponse) ); + + sandbox.stub(req.axios, "get").returns(resolvedPromise); + await root.saveValues(req, res, next); + expect(req.sessionModel.get("isAuthSourceRoute")).to.equal(false); + expect(req.sessionModel.get("drivingLicenceNumber")).to.equal(undefined); + expect(req.sessionModel.get("expiryDate")).to.equal(undefined); + expect(req.sessionModel.get("issueDate")).to.equal(undefined); + expect(req.sessionModel.get("licenceIssuer")).to.equal(undefined); + expect(req.sessionModel.get("postcode")).to.equal(undefined); + expect(req.sessionModel.get("issueNumber")).to.equal(undefined); + expect(req.sessionModel.get("firstName")).to.equal(undefined); + expect(req.sessionModel.get("surname")).to.equal(undefined); + expect(req.sessionModel.get("dateOfBirth")).to.equal(undefined); }); - it("should not update journeyModel if no shared attributes present", async () => { - req.session.shared_claims = { - names: [], - dateOfBirths: [] + it("should retrieve shared_claims from session and store it in the sessionModel", async () => { + personInfoApiResponse = { + data: { + name: [ + { + nameParts: [] + } + ], + birthDate: [{ value: "1965-07-08" }], + address: [ + { + postalCode: "BA2 5AA" + } + ], + drivingPermit: [ + { + personalNumber: "DOE99751010AL9OD", + expiryDate: "2022-02-02", + issueNumber: "13", + issuedBy: "DVA", + issueDate: "2012-02-02", + fullAddress: "8 HADLEY ROAD BATH BA2 5AA" + } + ] + } }; + const resolvedPromise = new Promise((resolve) => + resolve(personInfoApiResponse) + ); + sandbox.stub(req.axios, "get").returns(resolvedPromise); + + process.env.AUTH_SOURCE_ENABLED = "true"; + await root.saveValues(req, res, next); - expect(req.journeyModel.set.called).to.be.false; + expect(req.sessionModel.get("isAuthSourceRoute")).to.equal(false); + expect(req.sessionModel.get("drivingLicenceNumber")).to.equal(undefined); + expect(req.sessionModel.get("expiryDate")).to.equal(undefined); + expect(req.sessionModel.get("issueDate")).to.equal(undefined); + expect(req.sessionModel.get("licenceIssuer")).to.equal(undefined); + expect(req.sessionModel.get("postcode")).to.equal(undefined); + expect(req.sessionModel.get("issueNumber")).to.equal(undefined); + expect(req.sessionModel.get("firstName")).to.equal(undefined); + expect(req.sessionModel.get("surname")).to.equal(undefined); + expect(req.sessionModel.get("dateOfBirth")).to.equal(undefined); + }); + + it("should not update sessionModel if personInfo response is empty", async () => { + personInfoApiResponse = { + data: { + name: [], + birthDate: undefined, + address: [ + { + postalCode: "BA2 5AA" + } + ], + drivingPermit: [ + { + personalNumber: "", + expiryDate: "2022-02-02", + issueNumber: "13", + issuedBy: "DVLA", + issueDate: "2012-02-02", + fullAddress: "8 HADLEY ROAD BATH BA2 5AA" + } + ] + } + }; + + const resolvedPromise = new Promise((resolve) => + resolve(personInfoApiResponse) + ); + + sandbox.stub(req.axios, "get").returns(resolvedPromise); + await root.saveValues(req, res, next); + expect(req.sessionModel.get("isAuthSourceRoute")).to.equal(false); + expect(req.sessionModel.get("drivingLicenceNumber")).to.equal(undefined); + expect(req.sessionModel.get("expiryDate")).to.equal(undefined); + expect(req.sessionModel.get("issueDate")).to.equal(undefined); + expect(req.sessionModel.get("licenceIssuer")).to.equal(undefined); + expect(req.sessionModel.get("postcode")).to.equal(undefined); + expect(req.sessionModel.get("issueNumber")).to.equal(undefined); + expect(req.sessionModel.get("firstName")).to.equal(undefined); + expect(req.sessionModel.get("surname")).to.equal(undefined); + expect(req.sessionModel.get("dateOfBirth")).to.equal(undefined); }); }); diff --git a/src/app/drivingLicence/controllers/validate.js b/src/app/drivingLicence/controllers/validate.js index f503ae9e..f3d3b824 100644 --- a/src/app/drivingLicence/controllers/validate.js +++ b/src/app/drivingLicence/controllers/validate.js @@ -60,6 +60,9 @@ class ValidateController extends BaseController { if (checkDrivingLicenceResponse.data?.retry === true) { logger.info("validate: driving licence retry", { req, res }); req.sessionModel.set("showRetryMessage", true); + if (req.sessionModel.get("isAuthSourceRoute") === false) { + req.sessionModel.set("showRetryMessage", false); + } return callback(); } diff --git a/src/lib/config.js b/src/lib/config.js index 0a0c3a36..d2875889 100644 --- a/src/lib/config.js +++ b/src/lib/config.js @@ -6,7 +6,8 @@ module.exports = { PATHS: { SESSION: "session", CHECK: "check-driving-licence", - AUTHORIZATION: "authorization" + AUTHORIZATION: "authorization", + PERSON_INFO: "person-info" } }, APP: { @@ -21,7 +22,8 @@ module.exports = { GA4_DISABLED: process.env.GA4_DISABLED || false, UA_DISABLED: process.env.UA_DISABLED || true }, - LANGUAGE_TOGGLE_DISABLED: process.env.LANGUAGE_TOGGLE_DISABLED || "true" + LANGUAGE_TOGGLE_DISABLED: process.env.LANGUAGE_TOGGLE_DISABLED || "true", + AUTH_SOURCE_ENABLED: process.env.AUTH_SOURCE_ENABLED || "true" }, PORT: process.env.PORT || 5030, SESSION_SECRET: process.env.SESSION_SECRET,