From 14f88b453307090d98b2a86723fe14b7256abf1c Mon Sep 17 00:00:00 2001 From: Isaac Au Date: Wed, 8 Jan 2025 09:58:40 +0000 Subject: [PATCH] ATO-1237: fix test --- .../handlers/types/client-config-request.ts | 20 ++++----- .../types/client-registry-response.ts | 44 +++++++++--------- .../tests/testClientRegistryContract.spec.ts | 45 ++++++++++--------- package.json | 4 +- 4 files changed, 57 insertions(+), 56 deletions(-) diff --git a/backend/api/src/handlers/types/client-config-request.ts b/backend/api/src/handlers/types/client-config-request.ts index c669f3a76..5ad56bd57 100644 --- a/backend/api/src/handlers/types/client-config-request.ts +++ b/backend/api/src/handlers/types/client-config-request.ts @@ -1,11 +1,11 @@ export type clientConfigRequest = { - client_name: string; - public_key: string; - redirect_uris: string[]; - contacts: string[]; - scopes: string[]; - subject_type: string; - service_type: string; - sector_identifier_uri: string; - client_locs: string[]; -} \ No newline at end of file + client_name: string; + public_key: string; + redirect_uris: string[]; + contacts: string[]; + scopes: string[]; + subject_type: string; + service_type: string; + sector_identifier_uri: string; + client_locs: string[]; +}; diff --git a/backend/api/src/handlers/types/client-registry-response.ts b/backend/api/src/handlers/types/client-registry-response.ts index e3eb724d9..c96292ed8 100644 --- a/backend/api/src/handlers/types/client-registry-response.ts +++ b/backend/api/src/handlers/types/client-registry-response.ts @@ -1,23 +1,23 @@ export type clientRegistryResponse = { - client_name: string; - public_key: string; - public_key_source: null | string; - redirect_uris: string[]; - contacts: string[]; - scopes: string[]; - subject_type: string; - service_type: string; - sector_identifier_uri: string; - client_id: string; - post_logout_redirect_uris: string[]; - back_channel_logout_uri: null | string; - token_endpoint_auth_method: string; - response_type: string; - jar_validation_required: boolean; - claims: string[]; - client_type: string; - id_token_signing_algorithm: "ES256" | "RS256"; - jwks_uri: null | string; - channel: null | string; - max_age_enabled: boolean; -}; \ No newline at end of file + client_name: string; + public_key: string; + public_key_source: null | string; + redirect_uris: string[]; + contacts: string[]; + scopes: string[]; + subject_type: string; + service_type: string; + sector_identifier_uri: string; + client_id: string; + post_logout_redirect_uris: string[]; + back_channel_logout_uri: null | string; + token_endpoint_auth_method: string; + response_type: string; + jar_validation_required: boolean; + claims: string[]; + client_type: string; + id_token_signing_algorithm: "ES256" | "RS256"; + jwks_uri: null | string; + channel: null | string; + max_age_enabled: boolean; +}; diff --git a/backend/api/tests/contract-tests/tests/testClientRegistryContract.spec.ts b/backend/api/tests/contract-tests/tests/testClientRegistryContract.spec.ts index 441db691e..315a47d49 100644 --- a/backend/api/tests/contract-tests/tests/testClientRegistryContract.spec.ts +++ b/backend/api/tests/contract-tests/tests/testClientRegistryContract.spec.ts @@ -2,14 +2,14 @@ import {MatchersV3, PactV3} from "@pact-foundation/pact"; import * as path from "path"; -import { public_key, registerClientHandler, RegisterClientPayload } from "../../../src/handlers/auth/register-client"; +import {public_key, registerClientHandler, RegisterClientPayload} from "../../../src/handlers/auth/register-client"; import {clientConfigRequest} from "../../../src/handlers/types/client-config-request"; import {clientRegistryResponse} from "../../../src/handlers/types/client-registry-response"; -import { mockLambdaContext } from "../../handlers/utils"; -import { updateClientInRegistryHandler, UpdateClientPayload } from "../../../src/handlers/auth/update-client"; +import {mockLambdaContext} from "../../handlers/utils"; +import {updateClientInRegistryHandler, UpdateClientPayload} from "../../../src/handlers/auth/update-client"; beforeAll((): void => { - jest.setTimeout(200000); + jest.setTimeout(400000); }); describe("ClientRegistryProvider", () => { @@ -24,6 +24,8 @@ describe("ClientRegistryProvider", () => { }); describe("When a POST request is made to create a client", () => { + const contactEmail = "pacttest.account@digital.cabinet-office.gov.uk"; + const serviceName = "My test service"; const postEvent: RegisterClientPayload = { contactEmail: "pacttest.account@digital.cabinet-office.gov.uk", service: { @@ -33,10 +35,10 @@ describe("ClientRegistryProvider", () => { }; const client_config: clientConfigRequest = { - client_name: postEvent.service.serviceName, + client_name: serviceName, public_key: public_key, redirect_uris: ["http://localhost/"], - contacts: [postEvent.contactEmail], + contacts: [contactEmail], scopes: ["openid", "email", "phone"], subject_type: "pairwise", service_type: "MANDATORY", @@ -44,12 +46,12 @@ describe("ClientRegistryProvider", () => { client_locs: ["P2"] }; - const expected_response: clientRegistryResponse = createExpectedResponse(); - + const expected_response: clientRegistryResponse = createExpectedResponse(); + expected_response.client_name = client_config.client_name; expected_response.public_key = client_config.public_key; expected_response.redirect_uris = client_config.redirect_uris; - expected_response.contacts = client_config.contacts; + expected_response.contacts = client_config.contacts; expected_response.scopes = client_config.scopes; expected_response.subject_type = client_config.subject_type; expected_response.service_type = client_config.service_type; @@ -89,9 +91,9 @@ describe("ClientRegistryProvider", () => { describe("When a PUT request is made to update a client", () => { const updatesForClient = { - contacts: ["new.eamil@digital.cabinet-office.gov.uk"], + contacts: ["new.email@digital.cabinet-office.gov.uk"], subject_type: "pairwise" - } + }; const putEvent: UpdateClientPayload = { clientId: "testClientIdExampleText1234", @@ -100,9 +102,9 @@ describe("ClientRegistryProvider", () => { updates: { ...updatesForClient } - } + }; - let expected_response: any = createExpectedResponse(); + const expected_response: clientRegistryResponse = createExpectedResponse(); expected_response.contacts = updatesForClient.contacts; expected_response.subject_type = updatesForClient.subject_type; @@ -113,12 +115,7 @@ describe("ClientRegistryProvider", () => { .uponReceiving("configuration to update a client") .withRequest({ method: "PUT", - path: `/connect/register/${putEvent.clientId}`, - contentType: "application/json", - headers: { - "Content-Type": "application/json;" - }, - body: updatesForClient + path: "/connect/register/testClientIdExampleText1234", }) .willRespondWith({ status: 200, @@ -129,10 +126,15 @@ describe("ClientRegistryProvider", () => { } }); + console.log("Before test execution"); + await provider.executeTest(async mockProvider => { process.env.AUTH_REGISTRATION_BASE_URL = mockProvider.url; + console.log("Before lambda"); const results = await updateClientInRegistryHandler(putEvent, mockLambdaContext); + console.log("After lambda"); expect(JSON.parse(results.body)).toMatchObject(expected_response); + console.log("After json parse") }); }); }); @@ -155,12 +157,11 @@ describe("ClientRegistryProvider", () => { response_type: "code", jar_validation_required: false, claims: [], - client_type: "web", + client_type: "web", id_token_signing_algorithm: "ES256", jwks_uri: null, channel: "WEB", max_age_enabled: false - } - + }; } }); diff --git a/package.json b/package.json index 462c50985..68637c1c0 100644 --- a/package.json +++ b/package.json @@ -21,8 +21,8 @@ "list": "infrastructure/dev/deploy.sh list", "open": "infrastructure/dev/deploy.sh open", "creds": "infrastructure/aws.sh", - "test": "jest --silent", - "test:cov": "jest --silent --coverage", + "test": "jest --runInBand --detectOpenHandles", + "test:cov": "jest --coverage", "lint": "prettier . --check ; eslint '*.ts' --quiet --fix", "lint:fix": "prettier . --write ; eslint . --fix", "pii-scan": "infrastructure/dev/pii_scan.sh -p *template*.yml -i infrastructure/config/pii_scan_ignore.txt -s infrastructure/config/pii_scan_skip.txt"