From 6430c1a3cbd7392d024c5234a5ab92d26a0166ef Mon Sep 17 00:00:00 2001 From: lesion Date: Fri, 6 May 2022 23:26:30 +0200 Subject: [PATCH] add some tests for anon event --- tests/app.test.js | 52 +++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/tests/app.test.js b/tests/app.test.js index a2d2d2ed..110300ee 100644 --- a/tests/app.test.js +++ b/tests/app.test.js @@ -63,6 +63,28 @@ describe('Authentication / Authorization', () => { .expect(403) }) +}) + +describe('Events', () => { + + + test('should not allow event creation without required fields', async () => { + const required_fields = { + 'title': {}, + 'start_datetime': { title: 'test title' }, + 'place_id or place_name and place_address': { title: 'test title', start_datetime: new Date().getTime() * 1000, place_name: 'test place name'}, + } + + const promises = Object.keys(required_fields).map(async field => { + const response = await request(app).post('/api/event').send(required_fields[field]) + .expect(400) + expect(response.text).toBe(`${field} required`) + }) + + return Promise.all(promises) + }) + + test('should create anon event only when allowed', async () => { await request(app).post('/api/settings') @@ -73,42 +95,28 @@ describe('Authentication / Authorization', () => { await request(app).post('/api/event') .expect(403) + await request(app).post('/api/event') + .send({ title: 'test title', place_name: 'place name', place_address: 'address', start_datetime: new Date().getTime() * 1000 }) + .auth(token.access_token, { type: 'bearer' }) + .expect(200) + await request(app).post('/api/settings') .send({ key: 'allow_anon_event', value: true }) .auth(token.access_token, { type: 'bearer' }) .expect(200) return request(app).post('/api/event') - .send({ title: 'test title', place_name: 'place name', start_datetime: new Date().getTime() * 1000 }) + .send({ title: 'test title', place_name: 'place name', place_address: 'address', start_datetime: new Date().getTime() * 1000 }) .expect(200) - + }) -}) -describe('Events', () => { - - - test('should not allow event creation without required fields', async () => { - const required_fields = { - 'title': {}, - 'place_name': { title: 'test title' }, - 'start_datetime': { title: 'test title', 'place_name': 'test place name'} - } - - const promises = Object.keys(required_fields).map(async field => { - const response = await request(app).post('/api/event').send(required_fields[field]) - .expect(400) - expect(response.text).toBe(`${field} is required`) - }) - - return Promise.all(promises) - }) test('should trim tags', async () => { const event = { title: 'test title', - place_name: 'test place name', + place_id: 1, start_datetime: dayjs().unix(), tags: [' test tag '] }