unit tests for ISO format of event dates

This commit is contained in:
Moriz Wahl 2023-10-26 16:49:15 +02:00
parent 44d6f31574
commit fdf38af4e9

View File

@ -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', () => { describe('with event start date in the past', () => {
it('throws an error', async () => { it('throws an error', async () => {
const now = new Date() 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', () => { describe('with valid start date and end date before start date', () => {
it('throws an error', async () => { it('throws an error', async () => {
const now = new Date() const now = new Date()