sentence component test

This commit is contained in:
JasterV 2021-07-25 16:55:22 +02:00
parent d6c514328b
commit 58855c361a
2 changed files with 120 additions and 3 deletions

View file

@ -3,6 +3,7 @@ import supertest from 'supertest'
import app from './setup/app'
import { mockDb } from './mock/firebase'
import { mockConfig } from './mock/config'
import { mockAxios } from './mock/axios'
const request = supertest(app)
@ -12,7 +13,6 @@ beforeAll(() => {
})
describe('Test sentences api', () => {
it('returns unauthorized if no auth provided', async () => {
expect.assertions(1)
const result = await request.get('/api/v1/sentences').expect(401)
@ -45,4 +45,115 @@ describe('Test sentences api', () => {
})
})
it('lists all sentences', async () => {
expect.assertions(2)
const result = await request
.get('/api/v1/sentences')
.set('Authorization', `Bearer ${mockConfig.secret}`)
expect(result.body).toMatchObject({
success: true,
data: expect.any(Array)
})
expect(result.body.data.length).toBe(Object.values(sentencesData).length)
})
it('lists all sentences order by category asc', async () => {
expect.assertions(1)
const result = await request
.get('/api/v1/sentences?orderBy=category&order=asc')
.set('Authorization', `Bearer ${mockConfig.secret}`)
expect(result.body).toMatchObject({
success: true,
data: [
expect.objectContaining({ category: 'beautiful' }),
expect.objectContaining({ category: 'benefit' }),
expect.objectContaining({ category: 'experience' }),
expect.objectContaining({ category: 'humor' }),
expect.objectContaining({ category: 'none' }),
expect.objectContaining({ category: 'responsibility' }),
expect.objectContaining({ category: 'soft' }),
expect.objectContaining({ category: 'tech' }),
]
})
})
it('lists all sentences order by category desc', async () => {
expect.assertions(1)
const result = await request
.get('/api/v1/sentences?orderBy=category&order=desc')
.set('Authorization', `Bearer ${mockConfig.secret}`)
expect(result.body).toMatchObject({
success: true,
data: [
expect.objectContaining({ category: 'tech' }),
expect.objectContaining({ category: 'soft' }),
expect.objectContaining({ category: 'responsibility' }),
expect.objectContaining({ category: 'none' }),
expect.objectContaining({ category: 'humor' }),
expect.objectContaining({ category: 'experience' }),
expect.objectContaining({ category: 'benefit' }),
expect.objectContaining({ category: 'beautiful' }),
]
})
})
it('create new sentence', async () => {
expect.assertions(1)
const result = await request
.post('/api/v1/sentences')
.set('Authorization', `Bearer ${mockConfig.secret}`)
.send({ text: 'new sentence', category: 'terror' })
.expect(201)
expect(result.body).toMatchObject({
success: true,
data: expect.any(String)
})
})
it('create new sentence wrong body', async () => {
expect.assertions(1)
const result = await request
.post('/api/v1/sentences')
.set('Authorization', `Bearer ${mockConfig.secret}`)
.send({ wrong: 'new sentence' })
.expect(400)
expect(result.body).toMatchObject({
success: false,
errors: expect.arrayContaining([
expect.objectContaining({ field: 'text', type: 'required' }),
expect.objectContaining({ field: 'category', type: 'required' }),
])
})
})
it('update sentence', async () => {
expect.assertions(1)
const newSentence = { text: 'Hello world', category: 'terror' }
const result = await request
.put('/api/v1/sentences/abc123')
.set('Authorization', `Bearer ${mockConfig.secret}`)
.send(newSentence)
.expect(201)
expect(result.body).toMatchObject({
success: true,
data: {
id: 'abc123',
...newSentence
}
})
})
it('delete sentence', async () => {
expect.assertions(1)
const result = await request
.delete('/api/v1/sentences/abc123')
.set('Authorization', `Bearer ${mockConfig.secret}`)
.expect(201)
expect(result.body).toMatchObject({
success: true,
data: 'abc123'
})
})
});

View file

@ -1,4 +1,10 @@
export default {
export default {
'abc123': { text: 'Homer Simpson', category: 'humor' },
'abc456': { text: 'Lisa Simpson', category: 'humor' },
'abc456': { text: 'Lisa Simpson', category: 'beautiful' },
"WecSQpPO2aN99TQARAc0": { text: "Agile Strukturen, flache Hierarchien und kontinuierliche Weiterbildungsmöglichkeiten, die Deine persönliche Entwicklung bei uns fördern.", category: "benefit" },
"Wf5GZ6QkIWRyUiO6sfLE": { text: "Sie besitzen idealerweise Berufserfahrung im IT-Service-Desk-Betrieb und IT-Prozessen (ITIL)", category: "experience" },
"Wf70KaTTLdgalr4aVNvC": { text: "Anfertigung standardisierter und individueller Holzbauteile für unsere Reisemobile und Caravans", category: "responsibility" },
"WfoqJAEfpbeabVvjfmBP": { text: "„Beste Auswahl.", category: "none" },
"WftulLcIf4K8Bs3bmPH3": { text: "Sicherer Umgang mit den gängigen MS-Office-Anwendungen.", category: "tech" },
"Wg8HlIWCrgkd17LvyJVt": { text: "Ausgeprägte Dienstleistungsmentalität", category: "soft" },
}