From 2a54fe6dd4e27a564ca84fe6b277376e5f38935e Mon Sep 17 00:00:00 2001 From: Harshil Patel <26harshilpatel11@gmail.com> Date: Fri, 12 Jul 2024 13:48:43 -0400 Subject: [PATCH] unit test 'should return 415 if unsupported extension is requested' under GET /fragment/:id, removed post request with local Fragment save data --- tests/unit/get.test.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/unit/get.test.js b/tests/unit/get.test.js index adc06e7..469619e 100644 --- a/tests/unit/get.test.js +++ b/tests/unit/get.test.js @@ -199,6 +199,7 @@ describe('GET /v1/fragments/:id.ext', () => { fragMetadata1.save(); const md = markdownit(); const result = md.render(body); + const res = await request(app) .get(`/v1/fragments/${id}.html`) .auth('user1@email.com', 'password1'); @@ -208,19 +209,18 @@ describe('GET /v1/fragments/:id.ext', () => { // should return 415 if unsupported extension is requested test('should return 415 if unsupported extension is requested', async () => { // post a fragment + const ownerId = hash('user1@email.com'); + const id = 'rdmId'; + const fragMetadata1 = new Fragment({ id: id, ownerId: ownerId, type: 'text/plain' }); const body = 'This is a fragment'; - const res = await request(app) - .post('/v1/fragments') - .auth('user1@email.com', 'password1') - .set('Content-Type', 'text/plain') - .send(body); - const id = res.body.fragment.id; + fragMetadata1.setData(body); + fragMetadata1.save(); - const res_2 = await request(app) + const res = await request(app) .get(`/v1/fragments/${id}.png`) .auth('user1@email.com', 'password1'); - expect(res_2.statusCode).toBe(415); - expect(res_2.body).toEqual({ + expect(res.statusCode).toBe(415); + expect(res.body).toEqual({ status: 'error', error: { code: 415,