Skip to content
Closed
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
15 changes: 5 additions & 10 deletions playwright-tests/api-tests/documents.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const ENDPOINT = `/api/documents`;
test.describe(`Documents response tests`, () => {
test.beforeEach(async ({ apiRequest }) => {
await deleteDocument({
title: DOCUMENT_TITLE,
apiRequest
});

Expand All @@ -27,7 +26,6 @@ test.describe(`Documents response tests`, () => {
});

await deleteDocument({
title: DOCUMENT_TITLE,
apiRequest
});
});
Expand Down Expand Up @@ -111,23 +109,20 @@ async function createDocuments({
}

async function deleteDocument({
title,
apiRequest
}: {
title: string;
apiRequest: ApiTestFixtures['apiRequest'];
}) {
try {
const documentsResponse = await apiRequest(`${ENDPOINT}?populate=*`);
const documentsData = await documentsResponse.json();

const document = getDocumentByTitle({
documents: documentsData,
title
});
const toDelete = documentsData.data.filter((item: any) =>
item.title?.startsWith(API_SMOKE_NAME_PREFIX)
);

if (document) {
const response = await apiRequest(`${ENDPOINT}/${document.documentId}`, {
for (const item of toDelete) {
const response = await apiRequest(`${ENDPOINT}/${item.documentId}`, {
method: 'DELETE'
});

Expand Down
23 changes: 8 additions & 15 deletions playwright-tests/api-tests/news.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,15 @@ const ENDPOINT = '/api/news';

test.describe(`News response tests`, () => {
test.beforeEach(async ({ apiRequest }) => {
await deleteNewsByTitle({
title: NEWS_TITLE,
await deleteNewsByPrefix({
apiRequest
});

await createNews({ apiRequest });
});

test.afterEach(async ({ apiRequest }) => {
await deleteNewsByTitle({
title: NEWS_TITLE,
apiRequest
});
await deleteNewsByPrefix({ apiRequest });
});

test(`
Expand Down Expand Up @@ -97,24 +93,21 @@ async function createNews({
}
}

async function deleteNewsByTitle({
title,
async function deleteNewsByPrefix({
apiRequest
}: {
title: string;
apiRequest: ApiTestFixtures['apiRequest'];
}) {
try {
const newsResponse = await apiRequest(`${ENDPOINT}?populate=*`);
const newsData = await newsResponse.json();

const news = getNewsByTitle({
news: newsData,
title
});
const toDelete = newsData.data.filter((item: any) =>
item.title?.startsWith(API_SMOKE_NAME_PREFIX)
);

if (news) {
const response = await apiRequest(`${ENDPOINT}/${news.documentId}`, {
for (const item of toDelete) {
const response = await apiRequest(`${ENDPOINT}/${item.documentId}`, {
method: 'DELETE'
});

Expand Down
45 changes: 8 additions & 37 deletions playwright-tests/api-tests/other-pages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@ const ENDPOINT = '/api/other-pages';

test.describe(`Other pages response tests`, () => {
test.beforeEach(async ({ apiRequest }) => {
await deleteOtherPagesByTitle({
title: OTHER_PAGE_TITLE,
apiRequest
});
await deleteOtherPagesByPrefix({ apiRequest });

await createOtherPages({ apiRequest });
});

test.afterEach(async ({ apiRequest }) => {
await deleteOtherPagesByTitle({
title: OTHER_PAGE_TITLE,
apiRequest
});
await deleteOtherPagesByPrefix({ apiRequest });
});

test(`
Expand Down Expand Up @@ -92,24 +86,21 @@ async function createOtherPages({
}
}

async function deleteOtherPagesByTitle({
title,
async function deleteOtherPagesByPrefix({
apiRequest
}: {
title: string;
apiRequest: ApiTestFixtures['apiRequest'];
}) {
try {
const response = await apiRequest(`${ENDPOINT}?populate=*`);
const responseData = await response.json();

const otherPage = getOtherPageByTitle({
otherPage: responseData,
title
});
const toDelete = responseData.data.filter((item: any) =>
item.title?.startsWith(API_SMOKE_NAME_PREFIX)
);

if (otherPage) {
const response = await apiRequest(`${ENDPOINT}/${otherPage.documentId}`, {
for (const item of toDelete) {
const response = await apiRequest(`${ENDPOINT}/${item.documentId}`, {
method: 'DELETE'
});

Expand All @@ -119,24 +110,4 @@ async function deleteOtherPagesByTitle({
} catch (error: any) {
throw new Error(`Failed to delete test other page: ${error.message}`)
}
}

function getOtherPageByTitle({
otherPage,
title,
}: {
otherPage: OtherPageResponse;
title: string;
}) {
return otherPage.data.find((item) => item.title === title);
}

type OtherPageResponse = {
data: {
id?: number;
documentId: string;
title: string;
slug: string;
blocks: unknown[]
}[]
}