Skip to content

Commit

Permalink
feat: geo 567 integrate delete reports teardown in the playwright tes…
Browse files Browse the repository at this point in the history
…ts (#507)

Co-authored-by: Sukanya Rath <[email protected]>
  • Loading branch information
goemen and sukanya-rath authored May 29, 2024
1 parent 7aac138 commit 219ef95
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/.e2e-admin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
runs-on: ubuntu-22.04
timeout-minutes: ${{ inputs.timeout-minutes }}
strategy:
max-parallel: 3
max-parallel: 1
matrix:
project: [chromium, Google Chrome, firefox, safari, Microsoft Edge]
steps:
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/.e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ on:
required: true
E2E_PASSWORD:
required: true
EXTERNAL_CONSUMER_DELETE_REPORTS_API_KEY:
required: true
inputs:
frontend-url:
description: "Frontend URL of the application"
required: true
type: string
external-api-base-url :
description: "Base URL to the external service API"
required: true
type: string
environment:
description: "Environment to read secrets from GitHub secrets"
required: false
Expand All @@ -29,6 +35,8 @@ on:
required: true
E2E_PASSWORD:
required: true
EXTERNAL_CONSUMER_DELETE_REPORTS_API_KEY:
required: true
inputs:
frontend-url:
description: "Frontend URL of the application"
Expand All @@ -39,6 +47,10 @@ on:
required: false
default: dev
type: string
external-api-base-url :
description: "Base URL to the external service API"
required: true
type: string
timeout-minutes:
description: 'Timeout minutes'
default: 8
Expand Down Expand Up @@ -74,6 +86,8 @@ jobs:
E2E_BASE_URL: ${{ inputs.frontend-url }}
E2E_USERNAME: ${{ secrets.E2E_USERNAME }}
E2E_PASSWORD: ${{ secrets.E2E_PASSWORD }}
EXTERNAL_CONSUMER_DELETE_REPORTS_API_KEY: ${{ secrets.EXTERNAL_CONSUMER_DELETE_REPORTS_API_KEY }}
EXTERNAL_API_BASE_URL: ${{ inputs.external-api-base-url }}
run: |
npx playwright test --project="${{ matrix.project }}" --reporter=html
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci_cd_on_pr_dev_sandbox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ jobs:
secrets: inherit
with:
frontend-url: https://pay-transparency-pr-${{ github.event.number }}-frontend.apps.silver.devops.gov.bc.ca
external-api-base-url: https://pay-transparency-pr-${{ github.event.number }}-backend-external.apps.silver.devops.gov.bc.ca
test-e2e-admin:
name: E2E-Admin
needs: [builds, check-quota, deploys]
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,12 @@ jobs:
secrets: inherit
with:
backend-external-url: https://pay-transparency-dev-backend-external.apps.silver.devops.gov.bc.ca/api
test-e2e:
name: E2E
needs: [deploys]
uses: ./.github/workflows/.e2e.yml
secrets: inherit
with:
frontend-url: https://dev.paytransparency.fin.gov.bc.ca
external-api-base-url: https://pay-transparency-dev-backend-external.apps.silver.devops.gov.bc.ca

11 changes: 10 additions & 1 deletion backend-external/src/v1/routes/pay-transparency-routes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ describe('pay-transparency-routes', () => {
return request(app)
.delete('/')
.set('x-api-key', 'api-delete-reports-key')
.query({ companyName: '' })
.query({ companyName: "1234567890" })
.expect(400);
});

it('should fail if request fails to get reports', () => {
mockDeleteReports.mockRejectedValue({ message: 'Error happened' });
return request(app)
Expand All @@ -95,5 +96,13 @@ describe('pay-transparency-routes', () => {
.set('x-api-key', 'api-delete-reports-key')
.expect(500);
});

it('should fail if company name is not supplied', () => {
mockDeleteReports.mockRejectedValue({ message: 'Error happened' });
return request(app)
.delete('/')
.set('x-api-key', 'api-delete-reports-key')
.expect(404);
});
});
});
6 changes: 6 additions & 0 deletions backend-external/src/v1/routes/pay-transparency-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,12 @@ router.delete(
),
async (req, res) => {
try {
if (!req.query.companyName) {
return res
.status(404)
.json({ message: 'companyName query parameter is missing.' });
}

const { data } = await payTransparencyService.deleteReports(req);
if (data.error) {
return res.status(400).json({ message: data.message });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('pay-transparency-service', () => {
it('should delete reports', async () => {
mockDelete.mockReturnValue({});
await payTransparencyService.deleteReports({
params: { companyName: '1234567890' },
query: { companyName: '1234567890' },
} as any);

expect(mockDelete).toHaveBeenCalledWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const payTransparencyService = {
},
async deleteReports(req: Request) {
const axiosConfig: AxiosRequestConfig = {
params: req.params,
params: req.query,
headers: {
'x-api-key': config.get('backend:apiKey'),
},
Expand Down
31 changes: 27 additions & 4 deletions frontend/e2e/auth.teardown.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
import { test } from '@playwright/test';
import { PagePaths } from './utils';
import { PTPage } from './pages/page';
import {
EXTERNAL_API_BASE_URL,
EXTERNAL_CONSUMER_DELETE_REPORTS_API_KEY,
PagePaths,
} from './utils';
import { PTPage, User } from './pages/page';
import { waitForApiResponses } from './utils/report';

test('logout', async ({ page }) => {
await page.goto(PagePaths.DASHBOARD);
test('logout', async ({ page, request }) => {
const { user } = await waitForApiResponses(
{
user: page.waitForResponse(
(res) => res.url().includes('/api/user') && res.status() === 200,
),
},
async () => {
await page.goto(PagePaths.DASHBOARD);
},
);
const instance = new PTPage(page);
await instance.setup();

await request.delete(
`${EXTERNAL_API_BASE_URL}/api/v1/pay-transparency/reports`,
{
params: { companyName: (user as User).legalName },
headers: { 'x-api-key': EXTERNAL_CONSUMER_DELETE_REPORTS_API_KEY },
},
);

await instance.logout();
});
3 changes: 3 additions & 0 deletions frontend/e2e/pages/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export class LoginPage extends PTPage {
const html = await this.instance.locator('body').innerHTML();
if (html.includes('Use a Business BCeID')) {
expect(this.instance.getByText('Use a Business BCeID'));
/**
* Make sure to use test account to prevent the teardown from all deleting your local development reports
*/
await this.instance.fill('#user', process.env.E2E_USERNAME!);
await this.instance.click('#password');
await this.instance.fill('#password', process.env.E2E_PASSWORD!);
Expand Down
3 changes: 3 additions & 0 deletions frontend/e2e/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ export const PagePaths = {
VIEW_REPORT: `${baseURL}/published-report`,
DRAFT_REPORT: `${baseURL}/draft-report`,
};

export const EXTERNAL_API_BASE_URL = process.env.EXTERNAL_API_BASE_URL;
export const EXTERNAL_CONSUMER_DELETE_REPORTS_API_KEY =process.env.EXTERNAL_CONSUMER_API_KEY;

0 comments on commit 219ef95

Please sign in to comment.