From 19ac9ba00288baaae8fa900679be14ed04c5ed44 Mon Sep 17 00:00:00 2001 From: Weronika Ciesielska Date: Wed, 24 Jan 2024 18:27:45 +0100 Subject: [PATCH] add example tests --- __test__/app.test.ts | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/__test__/app.test.ts b/__test__/app.test.ts index a9d9a3e..9bcafa1 100644 --- a/__test__/app.test.ts +++ b/__test__/app.test.ts @@ -1,13 +1,31 @@ import request from 'supertest'; import app from '../src/app'; -describe('App Endpoints', () => { - it('GET / should return Hello world!', async () => { - const response = await request(app) - .get('/') - .expect('Content-Type', /text/) - .expect(200); - - expect(response.text).toEqual('Hello world!'); - }); -}); \ No newline at end of file +describe('Dogs API', () => { + it('GET /dogs - should return all dogs', async () => { + const response = await request(app).get('/dogs').expect(200); + expect(response.body).toBeInstanceOf(Array); + }); + + it('POST /dogs - should create a new dog', async () => { + const newDog = { name: 'Dash', breed: 'Corgi', age: 6, favoriteToy: 'Frisbee' }; + const response = await request(app).post('/dogs').send(newDog).expect(201); + expect(response.body).toMatchObject(newDog); + }); + + it('GET /dogs/:id - should return a dog by id', async () => { + const response = await request(app).get('/dogs/1').expect(200); + expect(response.body.id).toBe(1); + }); + + it('PUT /dogs/:id - should update a dog', async () => { + const updatedInfo = { age: 4 }; + const response = await request(app).put('/dogs/1').send(updatedInfo).expect(200); + expect(response.body.age).toBe(4); + }); + + it('DELETE /dogs/:id - should delete a dog', async () => { + await request(app).delete('/dogs/1').expect(204); + await request(app).get('/dogs/1').expect(404); + }); + }); \ No newline at end of file