Skip to content

Commit

Permalink
style(test-data): move futureDates and pastDates arrays to date.gener…
Browse files Browse the repository at this point in the history
…ator
  • Loading branch information
kat-kan committed Jul 7, 2024
1 parent b28b926 commit 1245220
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
9 changes: 9 additions & 0 deletions test-data/shared/date.generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@ const futureDateISO = new Date(

const futureDate = futureDateISO.split('.')[0] + 'Z';

const futureDates: string[] = [];
const pastDates: string[] = [];
pastDates.push(pastDate);
pastDates.push(pastDateISO);
futureDates.push(futureDate);
futureDates.push(futureDateISO);

export const customDate = {
pastDate: pastDate,
futureDate: futureDate,
pastDateISOFormat: pastDateISO,
futureDateISOFormat: futureDateISO,
futureDates,
pastDates
};
11 changes: 3 additions & 8 deletions tests/api/articles/articles-post.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ import { createHeaders } from '@_src_helpers_api/create-token.helper';
import { APIResponse, expect, test } from '@playwright/test';
import { customDate } from 'test-data/shared/date.generator';

const futureDates: string[] = [];
const pastDates: string[] = [];
pastDates.push(customDate.pastDate);
pastDates.push(customDate.pastDateISOFormat);
futureDates.push(customDate.futureDate);
futureDates.push(customDate.futureDateISOFormat);


test.describe('POST articles tests', async () => {
const articles: string = `/api/articles`;
Expand All @@ -26,7 +21,7 @@ test.describe('POST articles tests', async () => {
setHeaders = await createHeaders();
});

for (const date of pastDates) {
for (const date of customDate.pastDates) {
test(`Returns 201 Created after creating article with date ${date}`, async ({
request,
}) => {
Expand Down Expand Up @@ -133,7 +128,7 @@ test.describe('POST articles tests', async () => {
expect(response.status()).toBe(HttpStatusCode.UnprocessableEntity);
});

for (const invalidDate of futureDates) {
for (const invalidDate of customDate.futureDates) {
test(`Returns 422 Unprocessable content after sending article JSON with date from the future ${invalidDate}`, async ({
request,
}) => {
Expand Down

0 comments on commit 1245220

Please sign in to comment.