Skip to content

Commit

Permalink
OJ-2837: Feat - update tests to use multiple names scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
MarieseMikely committed Nov 26, 2024
1 parent a7a1b1a commit ec38843
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 3 deletions.
63 changes: 63 additions & 0 deletions integration-tests/api-gateway/check/check-multiple-name.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
32 changes: 29 additions & 3 deletions integration-tests/api-gateway/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand All @@ -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<Response> => {
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",
Expand All @@ -60,7 +71,7 @@ export const createSession = async (): Promise<Response> => {
};

export const createInvalidSession = async (): Promise<Response> => {
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",
Expand All @@ -74,6 +85,21 @@ export const createInvalidSession = async (): Promise<Response> => {
return sessionResponse;
};

export const createMultipleNamesSession = async (): Promise<Response> => {
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
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit ec38843

Please sign in to comment.