-
Notifications
You must be signed in to change notification settings - Fork 2
CCM 12179: Add Component Tests #194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 26 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
345d687
test
Namitha-Prabhu 64e9995
Comp tests
Namitha-Prabhu d28f7d5
Comp tests
Namitha-Prabhu 8e56956
component tests
Namitha-Prabhu e658df2
test
Namitha-Prabhu 06f62fd
Comp tests
Namitha-Prabhu 24cc719
Comp tests
Namitha-Prabhu af781ad
component tests
Namitha-Prabhu 5c26997
Merge branch 'feature/CCM-12179-Component-tests' of https://github.co…
Namitha-Prabhu 84378d6
review comments
Namitha-Prabhu c17261e
tests on pipeline
Namitha-Prabhu e4ac798
dependencies
Namitha-Prabhu aa08f80
tests
Namitha-Prabhu a91577c
Merge branch 'main' into feature/CCM-12179-Component-tests
Namitha-Prabhu af33e9e
revert test data changes
Namitha-Prabhu 5b8ac87
fix
Namitha-Prabhu 406d529
fix-cicd
Namitha-Prabhu ed3de2e
fix
Namitha-Prabhu 8359886
to discuss schema
Namitha-Prabhu 765cb82
to discuss schema
Namitha-Prabhu bf015b7
Remove test from pipeline
Namitha-Prabhu f482da8
Merge branch 'main' into feature/CCM-12179-Component-tests
Namitha-Prabhu 5d8a6c3
Remove test from pipeline
Namitha-Prabhu 9996615
Merge branch 'feature/CCM-12179-Component-tests' of https://github.co…
Namitha-Prabhu f29c91d
amend workflow
Namitha-Prabhu 20af907
Review Changes
Namitha-Prabhu 4d5d4e7
review fix
Namitha-Prabhu 77a6544
review fixes
Namitha-Prabhu 9b56f6a
Merge branch 'main' into feature/CCM-12179-Component-tests
Namitha-Prabhu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,3 +7,5 @@ node_modules/ | |
| /playwright/.cache/ | ||
| /allure-results | ||
| /target | ||
| /playwright/.auth/ | ||
| /allure-report | ||
Namitha-Prabhu marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import { test, expect } from '@playwright/test'; | ||
| import { SUPPLIER_LETTERS, AWS_REGION } from '../../constants/api_constants'; | ||
| import { createHeaderWithNoCorrelationId, createInvalidRequestHeaders, createValidRequestHeaders } from '../../constants/request_headers'; | ||
| import { validateApiResponse } from '../../helpers/validateJsonSchema'; | ||
| import { getRestApiGatewayBaseUrl } from '../../helpers/awsGatewayHelper'; | ||
|
|
||
| let baseUrl: string; | ||
|
|
||
| test.beforeAll(async () => { | ||
| const region = AWS_REGION; | ||
Namitha-Prabhu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| baseUrl = await getRestApiGatewayBaseUrl(); | ||
| }); | ||
|
|
||
| test.describe('API Gateway Tests To Get List Of Pending ', () => | ||
Namitha-Prabhu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| test('GET /letters should return 200 and list items', async ({ request }) => | ||
| { | ||
| const header = await createValidRequestHeaders(); | ||
| const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}` ,{ | ||
| headers: header, | ||
| params: { | ||
| limit:'2'}, | ||
| }, | ||
| ); | ||
|
|
||
| expect(response.status()).toBe(200); | ||
| const responseBody = await response.json(); | ||
| }); | ||
Namitha-Prabhu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| test('GET /letters with invalid authentication should return 403', async ({ request }) => { | ||
| const header = await createInvalidRequestHeaders(); | ||
| const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}` ,{ | ||
| headers: header, | ||
| params:{ | ||
| limit:'2' | ||
| }, | ||
| }, | ||
| ); | ||
| expect(response.status()).toBe(403); | ||
| }); | ||
|
|
||
|
|
||
| test('GET /letters with empty correlationId should return 500', async ({ request }) => { | ||
| const header = await createHeaderWithNoCorrelationId(); | ||
| const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}` ,{ | ||
| headers: header, | ||
| params:{ | ||
| limit:'2' | ||
| }, | ||
| }, | ||
| ); | ||
| expect(response.status()).toBe(500); | ||
| const responseBody = await response.json(); | ||
| }); | ||
|
|
||
| test('GET /letters with invalid query param return 400', async ({ request }) => { | ||
| const header = await createValidRequestHeaders(); | ||
| const response = await request.get(`${baseUrl}/${SUPPLIER_LETTERS}` ,{ | ||
| headers: header, | ||
| params:{ | ||
| limit:'?' | ||
| }, | ||
| }); | ||
| expect(response.status()).toBe(400); | ||
| const responseBody = await response.json(); | ||
| }); | ||
|
|
||
| }); | ||
93 changes: 93 additions & 0 deletions
93
tests/component-tests/apiGateway-tests/testCases/UpdateLetterStatus.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
|
|
||
| import { RequestHeaders } from '../../../constants/request_headers'; | ||
| import { supplierId } from '../../../constants/api_constants'; | ||
|
|
||
| export type PatchMessageRequestBody = { | ||
| data: { | ||
| type: string; | ||
| id: string; | ||
| attributes: { | ||
| reasonCode?: string | number; | ||
| reasonText?: string; | ||
| status: string; | ||
| }; | ||
| }; | ||
| }; | ||
|
|
||
Namitha-Prabhu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| export type ErrorLink = { | ||
| about: string; | ||
| }; | ||
|
|
||
| type PatchErrorResponse = { | ||
| id: string; | ||
| code: string; | ||
| links: ErrorLink; | ||
| status: string; | ||
| title: string; | ||
| detail: string; | ||
| }; | ||
|
|
||
| export type PatchErrorMessageBody = { | ||
| errors: PatchErrorResponse[]; | ||
| }; | ||
Namitha-Prabhu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| export type PatchMessageResponseBody = { | ||
| data: { | ||
| type: string; | ||
| id: string; | ||
| attributes: { | ||
| reasonCode?: number; | ||
| reasonText?: string; | ||
| status: string; | ||
| specificationId:string; | ||
| groupId?:string; | ||
| }; | ||
| }; | ||
| }; | ||
|
|
||
| export async function patchRequestHeaders(): Promise<RequestHeaders> { | ||
| let requestHeaders: RequestHeaders; | ||
| requestHeaders = { | ||
| headerauth1: process.env.HEADERAUTH || '', | ||
| 'NHSD-Supplier-ID': supplierId, | ||
| 'NHSD-Correlation-ID': '12344', | ||
| 'X-Request-ID': 'requestId1' | ||
| }; | ||
| return requestHeaders; | ||
| }; | ||
Namitha-Prabhu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| export async function patchValidRequestBody (id: string, status: string) : Promise<PatchMessageRequestBody>{ | ||
Namitha-Prabhu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| let requestBody: PatchMessageRequestBody; | ||
|
|
||
| requestBody = { | ||
| data: { | ||
| attributes: { | ||
| status: status, | ||
| }, | ||
| type: 'Letter', | ||
| id: id | ||
| } | ||
|
|
||
| }; | ||
| return requestBody; | ||
| } | ||
|
|
||
| export async function patchFailureRequestBody (id: string, status: string) : Promise<PatchMessageRequestBody>{ | ||
Namitha-Prabhu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| let requestBody: PatchMessageRequestBody; | ||
|
|
||
| requestBody = { | ||
| data: { | ||
| attributes: { | ||
| status: status, | ||
| reasonCode: 123, | ||
| reasonText: 'Test Reason' | ||
| }, | ||
| type: 'Letter', | ||
| id: id | ||
| } | ||
|
|
||
| }; | ||
| return requestBody; | ||
| } | ||
117 changes: 117 additions & 0 deletions
117
tests/component-tests/apiGateway-tests/updateLetterStatus.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| import { test, expect } from '@playwright/test'; | ||
| import { SUPPLIER_LETTERS, supplierId } from '../../constants/api_constants'; | ||
| import { getRestApiGatewayBaseUrl } from '../../helpers/awsGatewayHelper'; | ||
| import { patchFailureRequestBody, patchRequestHeaders, patchValidRequestBody } from './testCases/UpdateLetterStatus'; | ||
| import { createTestData, deleteLettersBySupplier, getLettersBySupplier } from '../../helpers/generate_fetch_testData'; | ||
| import { randomUUID } from 'crypto'; | ||
| import { createInvalidRequestHeaders } from '../../constants/request_headers'; | ||
|
|
||
| let baseUrl: string; | ||
|
|
||
| test.beforeAll(async () => { | ||
| baseUrl = await getRestApiGatewayBaseUrl(); | ||
| }); | ||
|
|
||
| test.describe('API Gateway Tests to Verify Patch Status Endpoint', () => { | ||
| test(`Patch /letters returns 200 and status is updated to ACCEPTED`, async ({ request }) => { | ||
|
|
||
| await createTestData(supplierId); | ||
| const letters = await getLettersBySupplier(supplierId, 'PENDING', 1); | ||
|
|
||
| if (!letters?.length) { | ||
| test.fail(true, `No PENDING letters found for supplier ${supplierId}`); | ||
| return; | ||
| } | ||
| const letter = letters[0]; | ||
| const headers = await patchRequestHeaders(); | ||
| const body = await patchValidRequestBody(letter.id, 'ACCEPTED'); | ||
|
|
||
| const response = await request.patch(`${baseUrl}/${SUPPLIER_LETTERS}/${letter.id}`, { | ||
| headers: headers, | ||
| data: body | ||
| }); | ||
|
|
||
| const res = await response.json(); | ||
| expect(response.status()).toBe(200); | ||
| expect(res).toMatchObject({ | ||
| data:{ | ||
| attributes: { | ||
| status: 'ACCEPTED', | ||
| specificationId: letter.specificationId, | ||
| groupId: letter.groupId, | ||
| }, | ||
| id: letter.id, | ||
| type: 'Letter' | ||
| } | ||
| }); | ||
|
|
||
| await deleteLettersBySupplier(letter.id); | ||
| }); | ||
|
|
||
| test(`Patch /letters returns 200 and status is updated to REJECTED`, async ({ request }) => { | ||
|
|
||
| await createTestData(supplierId); | ||
| const letters = await getLettersBySupplier(supplierId, 'PENDING', 1); | ||
|
|
||
| if (!letters?.length) { | ||
| test.fail(true, `No PENDING letters found for supplier ${supplierId}`); | ||
| return; | ||
| } | ||
| const letter = letters[0]; | ||
| const headers = await patchRequestHeaders(); | ||
| const body = await patchFailureRequestBody(letter.id, 'REJECTED'); | ||
|
|
||
| const response = await request.patch(`${baseUrl}/${SUPPLIER_LETTERS}/${letter.id}`, { | ||
| headers: headers, | ||
| data: body | ||
| }); | ||
|
|
||
| const res = await response.json(); | ||
| expect(response.status()).toBe(200); | ||
Namitha-Prabhu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| await deleteLettersBySupplier(letter.id); | ||
| }); | ||
|
|
||
| test(`Patch /letters returns 400 if request Body is invalid`, async ({ request }) => { | ||
|
|
||
| const id = randomUUID() | ||
| const headers = await patchRequestHeaders(); | ||
| const body = await patchValidRequestBody(id, ''); | ||
|
|
||
| const response = await request.patch(`${baseUrl}/${SUPPLIER_LETTERS}/${id}`, { | ||
| headers: headers, | ||
| data: body | ||
| }); | ||
|
|
||
| const res = await response.json(); | ||
|
|
||
| expect(response.status()).toBe(400); | ||
Namitha-Prabhu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| test(`Patch /letters returns 500 if Id doesn't exist for SupplierId`, async ({ request }) => { | ||
| const headers = await patchRequestHeaders(); | ||
| const id = randomUUID() | ||
| const body = await patchValidRequestBody(id, 'PENDING'); | ||
|
|
||
| const response = await request.patch(`${baseUrl}/${SUPPLIER_LETTERS}/${id}`, { | ||
| headers: headers, | ||
| data: body | ||
| }); | ||
|
|
||
| const res = await response.json(); | ||
| expect(response.status()).toBe(500); | ||
Namitha-Prabhu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
Namitha-Prabhu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| test(`Patch /letters returns 403 for invalid headers`, async ({ request }) => { | ||
| const headers = await createInvalidRequestHeaders(); | ||
| const id = randomUUID() | ||
| const body = await patchValidRequestBody(id, 'PENDING'); | ||
|
|
||
| const response = await request.patch(`${baseUrl}/${SUPPLIER_LETTERS}/${id}`, { | ||
| headers: headers, | ||
| data: body | ||
| }); | ||
|
|
||
| const res = await response.json(); | ||
| expect(response.status()).toBe(403); | ||
| }); | ||
| }); | ||
Namitha-Prabhu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,19 @@ | ||
| import type { PlaywrightTestConfig } from '@playwright/test'; | ||
| import { config as baseConfig } from './playwright.base.config'; | ||
| import { getReporters } from './reporters'; | ||
| import {defineConfig, PlaywrightTestConfig } from '@playwright/test'; | ||
| import baseConfig from './playwright.base.config'; | ||
| import { getReporters } from './reporters'; | ||
| import path from 'path'; | ||
|
|
||
| const localConfig: PlaywrightTestConfig = { | ||
| ...baseConfig, | ||
| /* Reporter to use. See https://playwright.dev/docs/test-reporters */ | ||
| reporter: getReporters('api-test'), | ||
| ...baseConfig, | ||
| //globalSetup: require.resolve('./setup/globalSetup'), | ||
| //globalTeardown: require.resolve('./setup/globalTeardown'), | ||
| testIgnore: [], | ||
| projects: [ | ||
| { | ||
| name: 'sandbox', | ||
| testMatch: 'tests/messages/get_single_letter/*.spec.ts', | ||
| name: 'component-tests', | ||
| testDir: path.resolve(__dirname, '../component-tests'), | ||
| testMatch: '**/*.spec.ts', | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| export default localConfig; | ||
| export default defineConfig(localConfig); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.