add some tests for anon event

This commit is contained in:
lesion
2022-05-06 23:26:30 +02:00
parent c1fd18d7f0
commit 6430c1a3cb

View File

@@ -63,6 +63,28 @@ describe('Authentication / Authorization', () => {
.expect(403) .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 () => { test('should create anon event only when allowed', async () => {
await request(app).post('/api/settings') await request(app).post('/api/settings')
@@ -73,42 +95,28 @@ describe('Authentication / Authorization', () => {
await request(app).post('/api/event') await request(app).post('/api/event')
.expect(403) .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') await request(app).post('/api/settings')
.send({ key: 'allow_anon_event', value: true }) .send({ key: 'allow_anon_event', value: true })
.auth(token.access_token, { type: 'bearer' }) .auth(token.access_token, { type: 'bearer' })
.expect(200) .expect(200)
return request(app).post('/api/event') 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) .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 () => { test('should trim tags', async () => {
const event = { const event = {
title: 'test title', title: 'test title',
place_name: 'test place name', place_id: 1,
start_datetime: dayjs().unix(), start_datetime: dayjs().unix(),
tags: [' test tag '] tags: [' test tag ']
} }