Skip to content

Commit 12be555

Browse files
committed
Merge remote-tracking branch 'origin/main' into feature/CCM-11600-API-GW-Authorizer
2 parents d184791 + c9dc802 commit 12be555

File tree

12 files changed

+402
-33
lines changed

12 files changed

+402
-33
lines changed

scripts/utilities/letter-test-data/src/helpers/create_letter_helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export function createLetterDto(params: {
6565
url,
6666
} = params;
6767

68-
const letter: Omit<Letter, "ttl" | "supplierStatus"> = {
68+
const letter: Omit<Letter, "ttl" | "supplierStatus" | "supplierStatusSk"> = {
6969
id: letterId,
7070
supplierId,
7171
specificationId,
564 KB
Binary file not shown.
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import {test, expect} from '@playwright/test';
2+
import { getRestApiGatewayBaseUrl } from "../../helpers/awsGatewayHelper";
3+
import { MI_ENDPOINT } from '../../constants/api_constants';
4+
import { createHeaderWithNoCorrelationId, createHeaderWithNoRequestId, createInvalidRequestHeaders, createValidRequestHeaders } from '../../constants/request_headers';
5+
import { miInvalidDateRequest, miInvalidRequest, miValidRequest } from './testCases/createMi';
6+
import { time } from 'console';
7+
import { error400InvalidDate, error400ResponseBody, error403ResponseBody, error404ResponseBody, requestId500Error } from '../../helpers/commonTypes';
8+
9+
let baseUrl: string;
10+
11+
test.beforeAll(async () => {
12+
baseUrl = await getRestApiGatewayBaseUrl();
13+
});
14+
15+
test.describe('API Gateway Tests to Verify Mi Endpoint', () => {
16+
test(`Post /mi returns 200 when a valid request is passed`, async ({ request }) => {
17+
18+
const headers = createValidRequestHeaders();
19+
const body = miValidRequest();
20+
21+
const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, {
22+
headers: headers,
23+
data: body
24+
});
25+
26+
const responseBody = await response.json();
27+
expect(response.status()).toBe(201);
28+
expect(responseBody.data.attributes).toMatchObject({
29+
groupId: 'group123',
30+
lineItem: 'envelope-business-standard',
31+
quantity: 10,
32+
specificationId: 'Test-Spec-Id',
33+
stockRemaining: 100,
34+
timestamp: body.data.attributes.timestamp,
35+
});
36+
expect(responseBody.data.type).toBe('ManagementInformation');
37+
});
38+
39+
test(`Post /mi returns 400 when a invalid request is passed`, async ({ request }) => {
40+
const headers = createValidRequestHeaders();
41+
const body = miInvalidRequest();
42+
43+
const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, {
44+
headers: headers,
45+
data: body
46+
});
47+
48+
const responseBody = await response.json();
49+
expect(response.status()).toBe(400);
50+
expect(responseBody).toMatchObject(error400ResponseBody());
51+
});
52+
53+
test(`Post /mi returns 403 when a authentication header is not passed`, async ({ request }) => {
54+
const headers = createInvalidRequestHeaders();
55+
const body = miValidRequest();
56+
57+
const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, {
58+
headers: headers,
59+
data: body
60+
});
61+
62+
const responseBody = await response.json();
63+
expect(response.status()).toBe(403);
64+
expect(responseBody).toMatchObject(error403ResponseBody());
65+
});
66+
67+
test(`Post /mi returns 500 when a correlationId is not passed`, async ({ request }) => {
68+
const headers = createHeaderWithNoCorrelationId();
69+
const body = miValidRequest();
70+
71+
const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, {
72+
headers: headers,
73+
data: body
74+
});
75+
76+
const res = await response.json();
77+
expect(response.status()).toBe(500);
78+
expect(res.errors[0].detail).toBe("The request headers don't contain the APIM correlation id");
79+
});
80+
81+
test(`Post /mi returns 500 when a x-request-id is not passed`, async ({ request }) => {
82+
const headers = createHeaderWithNoRequestId();
83+
const body = miValidRequest();
84+
85+
const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, {
86+
headers: headers,
87+
data: body
88+
});
89+
90+
const responseBody = await response.json();
91+
expect(response.status()).toBe(500);
92+
expect(responseBody).toMatchObject(requestId500Error());
93+
});
94+
95+
test(`Post /mi returns 400 when a invalid Date is passed`, async ({ request }) => {
96+
const headers = createValidRequestHeaders();
97+
const body = miInvalidDateRequest();
98+
99+
const response = await request.post(`${baseUrl}/${MI_ENDPOINT}`, {
100+
headers: headers,
101+
data: body
102+
});
103+
104+
const responseBody = await response.json();
105+
expect(response.status()).toBe(400);
106+
expect(responseBody).toMatchObject(error400InvalidDate());
107+
});
108+
109+
110+
});
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { test, expect } from '@playwright/test';
2+
import { getRestApiGatewayBaseUrl } from '../../helpers/awsGatewayHelper';
3+
import { getLettersBySupplier } from '../../helpers/generate_fetch_testData';
4+
import { SUPPLIER_LETTERS, SUPPLIERID } from '../../constants/api_constants';
5+
import { createValidRequestHeaders } from '../../constants/request_headers';
6+
import { error404ResponseBody, error500ResponseBody } from '../../helpers/commonTypes';
7+
8+
let baseUrl: string;
9+
10+
test.beforeAll(async () => {
11+
baseUrl = await getRestApiGatewayBaseUrl();
12+
});
13+
14+
test.describe('API Gateway Tests to Verify Get Letter Status Endpoint', () => {
15+
test(`Get /letters/{id} returns 200 and valid response for a given id`, async ({ request }) => {
16+
17+
const letters = await getLettersBySupplier(SUPPLIERID, 'PENDING', 1);
18+
19+
if (!letters?.length) {
20+
test.fail(true, `No PENDING letters found for supplier ${SUPPLIERID}`);
21+
return;
22+
}
23+
const letter = letters[0];
24+
const headers = createValidRequestHeaders();
25+
const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}/${letter.id}`, {
26+
headers: headers,
27+
});
28+
29+
const responseBody = await response.json();
30+
31+
expect(response.status()).toBe(200);
32+
expect(responseBody).toMatchObject({
33+
data:{
34+
attributes: {
35+
status: 'PENDING',
36+
specificationId: letter.specificationId,
37+
groupId: letter.groupId,
38+
},
39+
id: letter.id,
40+
type: 'Letter'
41+
}
42+
});
43+
});
44+
45+
test(`Get /letters/{id} returns 404 if no resource is found for id`, async ({ request }) =>
46+
{
47+
const id = '11';
48+
const headers = createValidRequestHeaders();
49+
const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}/${id}`, {
50+
headers: headers,
51+
});
52+
53+
const responseBody = await response.json();
54+
expect(response.status()).toBe(404);
55+
expect(responseBody).toMatchObject(error404ResponseBody());
56+
});
57+
58+
test(`Get /letters/{id} returns 500 if letter is not found for supplierId ${SUPPLIERID}`, async ({ request }) =>
59+
{
60+
const id = 'non-existing-id-12345';
61+
const headers = createValidRequestHeaders();
62+
const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}/${id}`, {
63+
headers: headers,
64+
});
65+
66+
const responseBody = await response.json();
67+
expect(response.status()).toBe(500);
68+
expect(responseBody).toMatchObject(error500ResponseBody(id));
69+
});
70+
71+
});

tests/component-tests/apiGateway-tests/getLetters.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { SUPPLIER_LETTERS } from '../../constants/api_constants';
33
import { createHeaderWithNoCorrelationId, createInvalidRequestHeaders, createValidRequestHeaders } from '../../constants/request_headers';
44
import { getRestApiGatewayBaseUrl } from '../../helpers/awsGatewayHelper';
55
import { validateApiResponse } from '../../helpers/validateJsonSchema';
6-
import { link } from 'fs';
76

87
let baseUrl: string;
98

tests/component-tests/apiGateway-tests/testCases/UpdateLetterStatus.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
import { RequestHeaders } from '../../../constants/request_headers';
3-
import { supplierId } from '../../../constants/api_constants';
3+
import { SUPPLIERID } from '../../../constants/api_constants';
44
import { ErrorMessageBody } from '../../../helpers/commonTypes';
55

66
export type PatchMessageRequestBody = {
@@ -33,7 +33,7 @@ export function patchRequestHeaders(): RequestHeaders {
3333
let requestHeaders: RequestHeaders;
3434
requestHeaders = {
3535
headerauth1: process.env.HEADERAUTH || '',
36-
'NHSD-Supplier-ID': supplierId,
36+
'NHSD-Supplier-ID': SUPPLIERID,
3737
'NHSD-Correlation-ID': '12344',
3838
'X-Request-ID': 'requestId1'
3939
};
@@ -106,7 +106,7 @@ export function patch500ErrorResponseBody (id: string) : ErrorMessageBody{
106106
},
107107
status: "500",
108108
title: "Internal server error",
109-
detail: `Letter with id ${id} not found for supplier ${supplierId}`
109+
detail: `Letter with id ${id} not found for supplier ${SUPPLIERID}`
110110
}
111111
]
112112
};
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
2+
3+
4+
export type MiRequestBody = {
5+
data: {
6+
type: string;
7+
attributes: {
8+
groupId: string;
9+
lineItem: string;
10+
quantity: number;
11+
specificationId: string;
12+
stockRemaining: number;
13+
timestamp: string;
14+
};
15+
};
16+
};
17+
18+
export function miValidRequest() : MiRequestBody{
19+
let requestBody: MiRequestBody;
20+
21+
requestBody = {
22+
data: {
23+
 attributes: {
24+
groupId: 'group123',
25+
lineItem: 'envelope-business-standard',
26+
quantity: 10,
27+
specificationId: 'Test-Spec-Id',
28+
stockRemaining: 100,
29+
timestamp: new Date().toISOString(),
30+
},
31+
type: 'ManagementInformation',
32+
}};
33+
return requestBody;
34+
}
35+
36+
export function miInvalidRequest() : MiRequestBody{
37+
let requestBody: MiRequestBody;
38+
39+
requestBody = {
40+
data: {
41+
 attributes: {
42+
groupId: 'group123',
43+
lineItem: 'envelope-business-standard',
44+
quantity: 10,
45+
specificationId: 'Test-Spec-Id',
46+
stockRemaining: 100,
47+
timestamp: new Date().toISOString(),
48+
},
49+
type: '?',
50+
}};
51+
return requestBody;
52+
}
53+
54+
export function miInvalidDateRequest() : MiRequestBody{
55+
let requestBody: MiRequestBody;
56+
57+
requestBody = {
58+
data: {
59+
 attributes: {
60+
groupId: 'group123',
61+
lineItem: 'envelope-business-standard',
62+
quantity: 10,
63+
specificationId: 'Test-Spec-Id',
64+
stockRemaining: 100,
65+
timestamp: '2021-10-28T',
66+
},
67+
type: 'ManagementInformation',
68+
}};
69+
return requestBody;
70+
}

0 commit comments

Comments
 (0)