Skip to content

Commit

Permalink
ATO-1237: fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
isaac-GDS committed Jan 9, 2025
1 parent a4dd928 commit 14f88b4
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 56 deletions.
20 changes: 10 additions & 10 deletions backend/api/src/handlers/types/client-config-request.ts
Original file line number Diff line number Diff line change
@@ -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[];
}
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[];
};
44 changes: 22 additions & 22 deletions backend/api/src/handlers/types/client-registry-response.ts
Original file line number Diff line number Diff line change
@@ -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;
};
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;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand All @@ -24,6 +24,8 @@ describe("ClientRegistryProvider", () => {
});

describe("When a POST request is made to create a client", () => {
const contactEmail = "[email protected]";
const serviceName = "My test service";
const postEvent: RegisterClientPayload = {
contactEmail: "[email protected]",
service: {
Expand All @@ -33,23 +35,23 @@ 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",
sector_identifier_uri: "http://gov.uk",
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;
Expand Down Expand Up @@ -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",
Expand All @@ -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;
Expand All @@ -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",

Check failure on line 118 in backend/api/tests/contract-tests/tests/testClientRegistryContract.spec.ts

View workflow job for this annotation

GitHub Actions / Linting

Delete `,`
})
.willRespondWith({
status: 200,
Expand All @@ -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")

Check failure on line 137 in backend/api/tests/contract-tests/tests/testClientRegistryContract.spec.ts

View workflow job for this annotation

GitHub Actions / Linting

Insert `;`
});
});
});
Expand All @@ -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
}

};
}
});
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 14f88b4

Please sign in to comment.