test auth

This commit is contained in:
JasterV 2021-07-25 16:18:32 +02:00
commit d6c514328b

View file

@ -13,6 +13,15 @@ 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)
expect(result.body).toMatchObject({
success: false,
msg: 'Unauthorized'
})
})
it('can get sentence by Id', async () => {
expect.assertions(1)
const sentence = sentencesData['abc123']
@ -25,4 +34,15 @@ describe('Test sentences api', () => {
})
});
it('returns error 404 if sentence not found', async () => {
expect.assertions(1)
const result = await request
.get('/api/v1/sentences/patata')
.set('Authorization', `Bearer ${mockConfig.secret}`)
expect(result.body).toMatchObject({
success: false,
msg: 'Sentence with id patata not found'
})
})
});