diff --git a/integration-tests/api-gateway/check/check-multiple-name.test.ts b/integration-tests/api-gateway/check/check-multiple-name.test.ts index e69de29b..024d20b3 100644 --- a/integration-tests/api-gateway/check/check-multiple-name.test.ts +++ b/integration-tests/api-gateway/check/check-multiple-name.test.ts @@ -0,0 +1,63 @@ +import { checkEndpoint, createMultipleNamesSession } from "../endpoints"; +import { + clearAttemptsTable, + clearItemsFromTables, +} from "../../resources/dynamodb-helper"; +import { NINO } from "../env-variables"; +import { stackOutputs } from "../../resources/cloudformation-helper"; + +jest.setTimeout(30000); + +describe("Given the session and NINO is valid", () => { + let sessionId: string; + let personIDTableName: string; + let sessionTableName: string; + let output: Partial<{ + CommonStackName: string; + StackName: string; + NinoUsersTable: string; + UserAttemptsTable: string; + }>; + + afterEach(async () => { + output = await stackOutputs(process.env.STACK_NAME); + personIDTableName = `person-identity-${output.CommonStackName}`; + sessionTableName = `session-${output.CommonStackName}`; + await clearItemsFromTables( + { + tableName: personIDTableName, + items: { sessionId: sessionId }, + }, + { + tableName: `${output.NinoUsersTable}`, + items: { sessionId: sessionId }, + }, + { + tableName: sessionTableName, + items: { sessionId: sessionId }, + } + ); + await clearAttemptsTable(sessionId, `${output.UserAttemptsTable}`); + }); + + it("Should receive a 200 response when /check endpoint is called without optional headers", async () => { + const session = await createMultipleNamesSession(); + const sessionData = await session.json(); + sessionId = sessionData.session_id; + const check = await checkEndpoint({ "session-id": sessionId }, NINO); + const checkData = check.status; + expect(checkData).toEqual(200); + }); + + it("Should receive a 200 response when /check endpoint is called with optional headers", async () => { + const session = await createMultipleNamesSession(); + const sessionData = await session.json(); + sessionId = sessionData.session_id; + const check = await checkEndpoint( + { "session-id": sessionId, "txma-audit-encoded": "test encoded header" }, + NINO + ); + const checkData = check.status; + expect(checkData).toEqual(200); + }); +}); diff --git a/integration-tests/api-gateway/endpoints.ts b/integration-tests/api-gateway/endpoints.ts index 7fb88c13..9d647776 100644 --- a/integration-tests/api-gateway/endpoints.ts +++ b/integration-tests/api-gateway/endpoints.ts @@ -18,7 +18,7 @@ let preOutput: Partial<{ PrivateApiGatewayId: string; }>; -export const createPayload = async () => { +export const createPayload = async (useMultipleNames: boolean = false) => { publicEncryptionKeyBase64 = (await getSSMParameter( "/check-hmrc-cri-api/test/publicEncryptionKeyBase64" @@ -29,6 +29,16 @@ export const createPayload = async () => { preOutput = await stackOutputs(process.env.STACK_NAME); privateAPI = `${preOutput.PrivateApiGatewayId}`; const correctClaimSet = await getClaimSet(); + + if (useMultipleNames = true){ + const name = correctClaimSet.shared_claims.name[0].nameParts + name.push( + { type: "GivenName", value: "Keith"}, + { type: "GivenName", value: "Ambrose William"}, + { type: "FamilyName", value: "Egan"} + ) + } + const audience = correctClaimSet.aud; const payload = { clientId: CLIENT_ID, @@ -40,12 +50,13 @@ export const createPayload = async () => { issuer: CLIENT_URL, claimSet: correctClaimSet, } as unknown as Payload; + // await new Promise((resolve) => setTimeout(resolve, 10)) const ipvCoreAuthorizationUrl = await getJarAuthorizationPayload(payload); return ipvCoreAuthorizationUrl; }; export const createSession = async (): Promise => { - const ipvCoreAuthorizationUrl = await createPayload(); + const ipvCoreAuthorizationUrl = await createPayload(false); const sessionApiUrl = `https://${privateAPI}.execute-api.eu-west-2.amazonaws.com/${environment}/session`; const sessionResponse = await fetch(sessionApiUrl, { method: "POST", @@ -60,7 +71,7 @@ export const createSession = async (): Promise => { }; export const createInvalidSession = async (): Promise => { - const ipvCoreAuthorizationUrl = await createPayload(); + const ipvCoreAuthorizationUrl = await createPayload(false); const sessionApiUrl = `https://${privateAPI}.execute-api.eu-west-2.amazonaws.com/${environment}/session`; const sessionResponse = await fetch(sessionApiUrl, { method: "POST", @@ -74,6 +85,21 @@ export const createInvalidSession = async (): Promise => { return sessionResponse; }; +export const createMultipleNamesSession = async (): Promise => { + const ipvCoreAuthorizationUrl = await createPayload(true); + const sessionApiUrl = `https://${privateAPI}.execute-api.eu-west-2.amazonaws.com/${environment}/session`; + const sessionResponse = await fetch(sessionApiUrl, { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-Forwarded-For": "localhost", + }, + body: JSON.stringify(ipvCoreAuthorizationUrl), + }); + + return sessionResponse; +}; + export const checkEndpoint = async ( headers: { "session-id"?: string; "txma-audit-encoded"?: string }, nino: string diff --git a/integration-tests/api-gateway/session/session-multiple-names-test.ts b/integration-tests/api-gateway/session/session-multiple-names-test.ts index e69de29b..9612696e 100644 --- a/integration-tests/api-gateway/session/session-multiple-names-test.ts +++ b/integration-tests/api-gateway/session/session-multiple-names-test.ts @@ -0,0 +1,27 @@ +import { createMultipleNamesSession } from "../endpoints"; +import { clearItemsFromTables } from "../../resources/dynamodb-helper"; +describe("Given the session is valid", () => { + let sessionId: string; + + afterEach(async () => { + await clearItemsFromTables( + { + tableName: "person-identity-common-cri-api", + items: { sessionId: sessionId }, + }, + { + tableName: "session-common-cri-api", + items: { sessionId: sessionId }, + } + ); + }); + + it("Should receive a valid session id when /session endpoint is called", async () => { + const sessionResponse = await createMultipleNamesSession(); + const jsonSession = await sessionResponse.json(); + sessionId = jsonSession.session_id; + + expect(sessionId).toBeDefined(); + expect(sessionResponse.status).toEqual(201); + }); +});