more unit testing

This commit is contained in:
lesion
2022-06-18 01:14:51 +02:00
parent 4cb790c471
commit 3e33252d06

View File

@@ -125,6 +125,7 @@ describe('Events', () => {
.send(event)
.expect(200)
.expect('Content-Type', /json/)
expect(response.body.tags[0]).toBe('test tag')
})
})
@@ -132,47 +133,97 @@ describe('Events', () => {
describe('Tags', () => {
test('should create event with tags', async () => {
const event = await request(app).post('/api/event')
.send({ title: 'test tags', place_id: 2, start_datetime: new Date().getTime() * 1000, tags: ['tag1', 'tag2', 'tag3'] })
.send({ title: 'test tags', place_id: 2, start_datetime: new Date().getTime() * 1000, tags: ['tag1', 'Tag2', 'tAg3'] })
.auth(token.access_token, { type: 'bearer' })
.expect(200)
expect(event.body.tags.length).toBe(3)
})
test('should create event trimming tags / ignore sensitiviness', async () => {
const event = await request(app).post('/api/event')
.send({ title: 'test trimming tags', place_id: 2, start_datetime: new Date().getTime() * 1000, tags: ['Tag1', 'taG2 '] })
.auth(token.access_token, { type: 'bearer' })
.expect(200)
expect(event.body.tags.length).toBe(2)
expect(event.body.tags[0]).toBe('tag1')
expect(event.body.tags[1]).toBe('Tag2')
})
test('should return events searching for tags', async () => {
const response = await request(app).get('/api/events?tags=tag1')
const response = await request(app).get('/api/events?tags=tAg3')
.expect(200)
console.error(response.body)
console.error(response.body[0].tags)
// console.error(response.body)
// console.error(response.body[0].tags)
expect(response.body.length).toBe(1)
expect(response.body[0].title).toBe('test tags')
// expect(response.body[0].title).toBe('test tags')
expect(response.body[0].tags.length).toBe(3)
})
})
describe ('Cohort', () => {
test('should not create a new cohort if not allowed', () => {
return request(app).post('/api/cohorts')
.send({ name: 'test cohort' })
describe('Place', () => {
test('should get events by place', async () => {
const response = await request(app).get('/api/place/place name 2')
.expect(200)
expect(response.body.place.name).toBe('place name 2')
expect(response.body.events.length).toBe(2)
expect(response.body.events[0].place.name).toBe('place name 2')
})
test('admin should get all places', async () => {
await request(app).get('/api/place/all')
.expect(403)
const response = await request(app).get('/api/place/all')
.auth(token.access_token, { type: 'bearer' })
.expect(200)
expect(response.body.length).toBe(2)
})
test('should search for a place', async () => {
const response = await request(app).get('/api/place?search=place')
.expect(200)
expect(response.body.length).toBe(2)
})
})
describe ('Collection', () => {
test('should not create a new collection if not allowed', () => {
return request(app).post('/api/collections')
.send({ name: 'test collection' })
.expect(403)
})
test('should create a new cohort', async () => {
const response = await request(app).post('/api/cohorts')
.send({ name: 'test cohort' })
test('should create a new collection', async () => {
const response = await request(app).post('/api/collections')
.send({ name: 'test collection' })
.auth(token.access_token, { type: 'bearer' })
.expect(200)
expect(response.body.id).toBe(1)
})
test('should do not have any event when no filters', async () => {
const response = await request(app).get('/api/collections/test collection')
.expect(200)
expect(response.body.length).toBe(0)
})
test('should add a new filter', async () => {
await request(app)
.post('/api/filter')
.expect(403)
const response = await request(app).post('/api/filter')
.send({ cohortId: 1, tags: ['test'] })
.send({ collectionId: 1, tags: ['test'] })
.auth(token.access_token, { type: 'bearer' })
.expect(200)
@@ -180,9 +231,9 @@ describe ('Cohort', () => {
})
test('should get cohort events', async () => {
test('should get collection events', async () => {
const response = await request(app)
.get(`/api/cohorts/test cohort`)
.get(`/api/collections/test collection`)
.expect(200)
expect(response.body.length).toBe(1)
@@ -209,7 +260,7 @@ describe ('Cohort', () => {
test('shoud filter for tags', async () => {
await request(app)
.post('/api/filter')
.send({ cohortId: 1, tags: ['test'] })
.send({ collectionId: 1, tags: ['test'] })
.auth(token.access_token, { type: 'bearer' })
.expect(200)
@@ -221,7 +272,7 @@ describe ('Cohort', () => {
expect(response.body.length).toBe(1)
response = await request(app)
.get(`/api/cohorts/test cohort`)
.get(`/api/collections/test collection`)
.expect(200)
expect(response.body.length).toBe(1)