Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion tests/constants/api_constants.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
export const SUPPLIER_LETTERS = 'letters';
export const SUPPLIER_API_URL_SANDBOX = 'https://internal-dev-sandbox.api.service.nhs.uk/nhs-notify-supplier';
export const AWS_REGION = 'eu-west-2';
export const envName = process.env.PR_NUMBER ?? 'main';
export const API_NAME = `nhs-${envName}-supapi`;
export const LETTERSTABLENAME = `nhs-${envName}-supapi-letters`;
export const SUPPLIERID = 'TestSupplier1';
export const MI_ENDPOINT = 'mi';

const formattedPr = process.env.PR_NUMBER
? process.env.PR_NUMBER.replace(/^pr(\d+)$/i, "PR-$1")
: null;

// Build sandbox environment name
const sandboxEnv = formattedPr
? `nhs-notify-supplier-${formattedPr}`
: "nhs-notify-supplier";
export const SUPPLIER_API_URL_SANDBOX = `https://internal-dev-sandbox.api.service.nhs.uk/${sandboxEnv}`;
1 change: 1 addition & 0 deletions tests/helpers/generate_fetch_testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export async function createTestData(supplierId: string): Promise<void> {
supplierId: supplierId,
environment: envName,
awsAccountId: '820178564574',
letterId: 'letterId',
groupId: 'TestGroupID',
specificationId: 'TestSpecificationID',
status: 'PENDING',
Expand Down
4 changes: 4 additions & 0 deletions tests/helpers/pnpmHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export async function runCreateLetter(options: {
supplierId: string;
environment: string;
awsAccountId: string;
letterId: string;
groupId: string;
specificationId: string;
status: string;
Expand All @@ -21,6 +22,7 @@ export async function runCreateLetter(options: {
supplierId,
environment,
awsAccountId,
letterId,
groupId,
specificationId,
status,
Expand All @@ -46,6 +48,8 @@ export async function runCreateLetter(options: {
environment,
'--awsAccountId',
awsAccountId,
'--letter-id',
letterId,
'--group-id',
groupId,
'--specification-id',
Expand Down
38 changes: 8 additions & 30 deletions tests/sandbox/testCases/updateLetterStatus_testCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export type ApiSandboxUpdateLetterStatusTestData = {

export const apiSandboxUpdateLetterStatusTestData: ApiSandboxUpdateLetterStatusTestData[] = [
{
testCase: '200 response if record is updated with status PENDING',
id: '2WL5eYSWGzCHlGmzNxuqVusPxDg',
testCase: '202 response if record is updated with status PENDING',
id: '24L5eYSWGzCHlGmzNxuqVusPxDg',
header: sandBoxHeader,
body: {
data: {
Expand All @@ -28,47 +28,25 @@ export const apiSandboxUpdateLetterStatusTestData: ApiSandboxUpdateLetterStatusT
},
}
},
expectedStatus: 200,
expectedResponse: {
data: {
type: 'Letter',
id: '2WL5eYSWGzCHlGmzNxuqVusPxDg',
attributes: {
status: 'PENDING',
specificationId:'2WL5eYSWGzCHlGmzNxuqVusPxDg',
},
}
},
expectedStatus: 202,
},

{
testCase: '200 response if record is updated with status REJECTED',
id: '2WL5eYSWGzCHlGmzNxuqVusPxDg',
testCase: '202 response if record is updated with status REJECTED',
id: '24L5eYSWGzCHlGmzNxuqVusPxDg',
header: sandBoxHeader,
body: {
data: {
type: 'Letter',
id: '2WL5eYSWGzCHlGmzNxuqVusPxDg',
attributes: {
status: 'REJECTED',
reasonCode: 'R01',
reasonText: 'failed validation',
},
}
},
expectedStatus: 200,
expectedResponse: {
data: {
type: 'Letter',
id: '2WL5eYSWGzCHlGmzNxuqVusPxDg',
attributes: {
reasonCode: 'R01',
reasonText: 'failed validation',
status: 'REJECTED',
specificationId:'2WL5eYSWGzCHlGmzNxuqVusPxDg',
reasonCode: 'R07',
reasonText: 'No such address',
},
}
},
expectedStatus: 202,
},
{
testCase: '404 response if no resource is found for the given id',
Expand Down
4 changes: 2 additions & 2 deletions tests/sandbox/testCases/updateMultipleStatus_testCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type postRequest = {

export const apiSandboxMultipleLetterStatusTestData: ApiSandboxUpdateLetterStatusTestData[] =
[{
testCase: '200 response if records are updated',
testCase: '202 response if records are updated',
header: sandBoxHeader,
body:{
data :
Expand Down Expand Up @@ -106,7 +106,7 @@ export const apiSandboxMultipleLetterStatusTestData: ApiSandboxUpdateLetterStatu
type: 'Letter'
}
]},
expectedStatus: 200
expectedStatus: 202
},
{
testCase: '404 response if invalid request is passed',
Expand Down
10 changes: 6 additions & 4 deletions tests/sandbox/updateLetterStatus.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@ test.describe('Sandbox Tests To Update Letter Status', () =>
{
apiSandboxUpdateLetterStatusTestData.forEach(({ testCase, header, id, body, expectedStatus, expectedResponse }) => {
test(`Patch /Letters endpoint returns ${testCase}`, async ({ request }) => {

const response = await request.patch(`${SUPPLIER_API_URL_SANDBOX}/${SUPPLIER_LETTERS}/${id}` ,{
headers: header,
data: body
});

const res = await response.json();
expect(response.status()).toBe(expectedStatus);
expect(res).toEqual(expectedResponse);
console.log("URL", `${SUPPLIER_API_URL_SANDBOX}/${SUPPLIER_LETTERS}/${id}`);

expect(response.status()).toBe(expectedStatus);
if (response.status() != 202){
const res = await response.json();
expect(res).toEqual(expectedResponse);
}
});
});
});
Loading