From fdf38af4e969fd6315647ab21dbe845bbe4896a3 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Thu, 26 Oct 2023 16:49:15 +0200 Subject: [PATCH] unit tests for ISO format of event dates --- backend/src/schema/resolvers/posts.spec.ts | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/backend/src/schema/resolvers/posts.spec.ts b/backend/src/schema/resolvers/posts.spec.ts index 7a549449f..b816e25aa 100644 --- a/backend/src/schema/resolvers/posts.spec.ts +++ b/backend/src/schema/resolvers/posts.spec.ts @@ -374,6 +374,31 @@ describe('CreatePost', () => { }) }) + describe('with event start in no ISO format', () => { + it('throws an error', async () => { + const now = new Date() + const eventStart = new Date(now.getFullYear(), now.getMonth() - 1).toISOString() + await expect( + mutate({ + mutation: createPostMutation(), + variables: { + ...variables, + postType: 'Event', + eventInput: { + eventStart: eventStart.split('T')[0], + }, + }, + }), + ).resolves.toMatchObject({ + errors: [ + { + message: 'Event start date must be in ISO format!', + }, + ], + }) + }) + }) + describe('with event start date in the past', () => { it('throws an error', async () => { const now = new Date() @@ -423,6 +448,32 @@ describe('CreatePost', () => { }) }) + describe('with valid start date and not ISO formated end date', () => { + it('throws an error', async () => { + const now = new Date() + const eventEnd = new Date(now.getFullYear(), now.getMonth() + 2).toISOString() + await expect( + mutate({ + mutation: createPostMutation(), + variables: { + ...variables, + postType: 'Event', + eventInput: { + eventStart: new Date(now.getFullYear(), now.getMonth() + 1).toISOString(), + eventEnd: eventEnd.split('T')[0], + }, + }, + }), + ).resolves.toMatchObject({ + errors: [ + { + message: 'Event end date must be in ISO format!', + }, + ], + }) + }) + }) + describe('with valid start date and end date before start date', () => { it('throws an error', async () => { const now = new Date()