Extract API mocks to their own file
All checks were successful
Check usage of free licenses / build-static-assets (pull_request) Successful in 1m11s
Add copyright notice / copyright_notice (pull_request) Successful in 1m27s
Build Nginx-based docker image / build-static-assets (push) Successful in 4m12s
Playwright Tests / test (pull_request) Successful in 4m18s
All checks were successful
Check usage of free licenses / build-static-assets (pull_request) Successful in 1m11s
Add copyright notice / copyright_notice (pull_request) Successful in 1m27s
Build Nginx-based docker image / build-static-assets (push) Successful in 4m12s
Playwright Tests / test (pull_request) Successful in 4m18s
This commit is contained in:
parent
2ebd9796e3
commit
02760e5068
@ -1,104 +1,6 @@
|
|||||||
import { test, expect, Page } from '@playwright/test'
|
import { expect, test } from '@playwright/test';
|
||||||
import { mock } from 'node:test';
|
import mockGroupsAPI from './mocks/groups';
|
||||||
|
import mockGuestsAPI from './mocks/guests';
|
||||||
const mockGuestsAPI = ({ page }: { page: Page }) => {
|
|
||||||
page.route('*/**/api/default/guests', async route => {
|
|
||||||
if (route.request().method() === 'GET') {
|
|
||||||
const json = [
|
|
||||||
{
|
|
||||||
"id": "f4a09c28-40ea-4553-90a5-96935a59cac6",
|
|
||||||
"status": "tentative",
|
|
||||||
"name": "Kristofer Rohan DVM",
|
|
||||||
"group": {
|
|
||||||
"id": "ee44ffb9-1147-4842-a378-9eaeb0f0871a",
|
|
||||||
"name": "Pam's family",
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "bd585c40-0937-4cde-960a-bb23acfd6f18",
|
|
||||||
"status": "invited",
|
|
||||||
"name": "Olevia Quigley Jr.",
|
|
||||||
"group": {
|
|
||||||
"id": "c8bda6ca-d8af-4bb8-b2bf-e6ec1c21b1e6",
|
|
||||||
"name": "Pam's work",
|
|
||||||
}
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
await route.fulfill({ json })
|
|
||||||
} else if (route.request().method() === 'POST') {
|
|
||||||
const json = {
|
|
||||||
"id": "ff58aa2d-643d-4c29-be9c-50e10ae6853c",
|
|
||||||
"name": "John Snow",
|
|
||||||
"status": "invited",
|
|
||||||
"group": {
|
|
||||||
"id": "c8bda6ca-d8af-4bb8-b2bf-e6ec1c21b1e6",
|
|
||||||
"name": "Pam's work",
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
await route.fulfill({ json });
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
page.route("*/**/api/default/guests/*", async route => {
|
|
||||||
if (route.request().method() === 'PUT') {
|
|
||||||
const json = {
|
|
||||||
"id": "ff58aa2d-643d-4c29-be9c-50e10ae6853c",
|
|
||||||
"name": "John Fire",
|
|
||||||
"status": "declined",
|
|
||||||
"group": {
|
|
||||||
"id": "ee44ffb9-1147-4842-a378-9eaeb0f0871a",
|
|
||||||
"name": "Pam's family",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await route.fulfill({ json });
|
|
||||||
|
|
||||||
} else if (route.request().method() === 'DELETE') {
|
|
||||||
const json = {}
|
|
||||||
await route.fulfill({ json });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const mockGroupsAPI = ({ page }: { page: Page }) => {
|
|
||||||
page.route('*/**/api/default/groups', async route => {
|
|
||||||
const json = [
|
|
||||||
{
|
|
||||||
"id": "ee44ffb9-1147-4842-a378-9eaeb0f0871a",
|
|
||||||
"name": "Pam's family",
|
|
||||||
"icon": "pi pi-users",
|
|
||||||
"parent_id": null,
|
|
||||||
"color": "#ff0000",
|
|
||||||
"attendance": {
|
|
||||||
"total": 3,
|
|
||||||
"considered": 2,
|
|
||||||
"invited": 1,
|
|
||||||
"confirmed": 0,
|
|
||||||
"declined": 0,
|
|
||||||
"tentative": 0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "c8bda6ca-d8af-4bb8-b2bf-e6ec1c21b1e6",
|
|
||||||
"name": "Pam's work",
|
|
||||||
"icon": "pi pi-desktop",
|
|
||||||
"parent_id": null,
|
|
||||||
"color": "#00ff00",
|
|
||||||
"attendance": {
|
|
||||||
"total": 2,
|
|
||||||
"considered": 0,
|
|
||||||
"invited": 0,
|
|
||||||
"confirmed": 0,
|
|
||||||
"declined": 0,
|
|
||||||
"tentative": 2
|
|
||||||
}
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
await route.fulfill({ json })
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
test('should allow CRUD on guests', async ({ page }) => {
|
test('should allow CRUD on guests', async ({ page }) => {
|
||||||
await mockGuestsAPI({ page });
|
await mockGuestsAPI({ page });
|
||||||
|
40
tests/mocks/groups.tsx
Normal file
40
tests/mocks/groups.tsx
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import { Page } from "@playwright/test";
|
||||||
|
|
||||||
|
export default async function mockGroupsAPI({ page }: { page: Page }): Promise<void> {
|
||||||
|
page.route('*/**/api/default/groups', async route => {
|
||||||
|
const json = [
|
||||||
|
{
|
||||||
|
"id": "ee44ffb9-1147-4842-a378-9eaeb0f0871a",
|
||||||
|
"name": "Pam's family",
|
||||||
|
"icon": "pi pi-users",
|
||||||
|
"parent_id": null,
|
||||||
|
"color": "#ff0000",
|
||||||
|
"attendance": {
|
||||||
|
"total": 3,
|
||||||
|
"considered": 2,
|
||||||
|
"invited": 1,
|
||||||
|
"confirmed": 0,
|
||||||
|
"declined": 0,
|
||||||
|
"tentative": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "c8bda6ca-d8af-4bb8-b2bf-e6ec1c21b1e6",
|
||||||
|
"name": "Pam's work",
|
||||||
|
"icon": "pi pi-desktop",
|
||||||
|
"parent_id": null,
|
||||||
|
"color": "#00ff00",
|
||||||
|
"attendance": {
|
||||||
|
"total": 2,
|
||||||
|
"considered": 0,
|
||||||
|
"invited": 0,
|
||||||
|
"confirmed": 0,
|
||||||
|
"declined": 0,
|
||||||
|
"tentative": 2
|
||||||
|
}
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
await route.fulfill({ json })
|
||||||
|
})
|
||||||
|
}
|
61
tests/mocks/guests.tsx
Normal file
61
tests/mocks/guests.tsx
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
import { Page } from "@playwright/test";
|
||||||
|
|
||||||
|
export default async function mockGuestsAPI({ page }: { page: Page }): Promise<void> {
|
||||||
|
page.route('*/**/api/default/guests', async route => {
|
||||||
|
if (route.request().method() === 'GET') {
|
||||||
|
const json = [
|
||||||
|
{
|
||||||
|
"id": "f4a09c28-40ea-4553-90a5-96935a59cac6",
|
||||||
|
"status": "tentative",
|
||||||
|
"name": "Kristofer Rohan DVM",
|
||||||
|
"group": {
|
||||||
|
"id": "ee44ffb9-1147-4842-a378-9eaeb0f0871a",
|
||||||
|
"name": "Pam's family",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "bd585c40-0937-4cde-960a-bb23acfd6f18",
|
||||||
|
"status": "invited",
|
||||||
|
"name": "Olevia Quigley Jr.",
|
||||||
|
"group": {
|
||||||
|
"id": "c8bda6ca-d8af-4bb8-b2bf-e6ec1c21b1e6",
|
||||||
|
"name": "Pam's work",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
await route.fulfill({ json })
|
||||||
|
} else if (route.request().method() === 'POST') {
|
||||||
|
const json = {
|
||||||
|
"id": "ff58aa2d-643d-4c29-be9c-50e10ae6853c",
|
||||||
|
"name": "John Snow",
|
||||||
|
"status": "invited",
|
||||||
|
"group": {
|
||||||
|
"id": "c8bda6ca-d8af-4bb8-b2bf-e6ec1c21b1e6",
|
||||||
|
"name": "Pam's work",
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
await route.fulfill({ json });
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
page.route("*/**/api/default/guests/*", async route => {
|
||||||
|
if (route.request().method() === 'PUT') {
|
||||||
|
const json = {
|
||||||
|
"id": "ff58aa2d-643d-4c29-be9c-50e10ae6853c",
|
||||||
|
"name": "John Fire",
|
||||||
|
"status": "declined",
|
||||||
|
"group": {
|
||||||
|
"id": "ee44ffb9-1147-4842-a378-9eaeb0f0871a",
|
||||||
|
"name": "Pam's family",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await route.fulfill({ json });
|
||||||
|
|
||||||
|
} else if (route.request().method() === 'DELETE') {
|
||||||
|
const json = {}
|
||||||
|
await route.fulfill({ json });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user