From 0b5d662322fd6c7db49d906f56199ae3d949a695 Mon Sep 17 00:00:00 2001 From: junjiequan Date: Mon, 25 Nov 2024 14:56:26 +0100 Subject: [PATCH] fix: fix failing api test --- src/origdatablocks/origdatablocks.controller.ts | 4 +++- test/DerivedDatasetOrigDatablock.js | 8 ++++---- test/OrigDatablockForRawDataset.js | 4 ++-- test/RawDatasetOrigDatablock.js | 6 +++--- test/TestData.js | 1 + 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/origdatablocks/origdatablocks.controller.ts b/src/origdatablocks/origdatablocks.controller.ts index 5dafc179e..93f4f52b1 100644 --- a/src/origdatablocks/origdatablocks.controller.ts +++ b/src/origdatablocks/origdatablocks.controller.ts @@ -125,7 +125,9 @@ export class OrigDatablocksController { const user: JWTUser = request.user as JWTUser; if (!dataset) { - throw new NotFoundException(`Dataset: ${id} not found`); + throw new NotFoundException( + `Dataset: ${id} not found for attaching an origdatablock`, + ); } const origDatablockInstance = diff --git a/test/DerivedDatasetOrigDatablock.js b/test/DerivedDatasetOrigDatablock.js index 8dcc066e3..27fef4c29 100644 --- a/test/DerivedDatasetOrigDatablock.js +++ b/test/DerivedDatasetOrigDatablock.js @@ -15,7 +15,7 @@ describe("0800: DerivedDatasetOrigDatablock: Test OrigDatablocks and their relat db.collection("Dataset").deleteMany({}); db.collection("OrigDatablock").deleteMany({}); }); - beforeEach(async() => { + beforeEach(async () => { accessTokenAdminIngestor = await utils.getToken(appUrl, { username: "adminIngestor", password: TestData.Accounts["adminIngestor"]["password"], @@ -384,20 +384,20 @@ describe("0800: DerivedDatasetOrigDatablock: Test OrigDatablocks and their relat }); }); - it("0200: add a new origDatablock with invalid pid should fail", async () => { + it("0200: add a new origDatablock to the non-existent dataset should fail", async () => { return request(appUrl) .post(`/api/v3/origdatablocks`) .send({ ...TestData.OrigDataBlockCorrect1, datasetId: "wrong" }) .set("Accept", "application/json") .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - .expect(TestData.BadRequestStatusCode) + .expect(TestData.NotFoundStatusCode) .expect("Content-Type", /json/) .then((res) => { res.body.should.have.property("error"); }); }); - it("0210: add a new origDatablock with valid pid should success", async () => { + it("0210: add a new origDatablock to the existent dataset should success", async () => { return request(appUrl) .post(`/api/v3/origdatablocks`) .send({ diff --git a/test/OrigDatablockForRawDataset.js b/test/OrigDatablockForRawDataset.js index d329d5867..ca59bc854 100644 --- a/test/OrigDatablockForRawDataset.js +++ b/test/OrigDatablockForRawDataset.js @@ -745,13 +745,13 @@ describe("1200: OrigDatablockForRawDataset: Test OrigDatablocks and their relati }); }); - it("0400: add a new origDatablock with invalid pid should fail", async () => { + it("0400: add a new origDatablock to the non-existent dataset should fail", async () => { return request(appUrl) .post(`/api/v3/origdatablocks`) .send({ ...origDatablockData1, datasetId: "wrong" }) .set("Accept", "application/json") .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - .expect(TestData.BadRequestStatusCode) + .expect(TestData.NotFoundStatusCode) .expect("Content-Type", /json/) .then((res) => { res.body.should.have.property("error"); diff --git a/test/RawDatasetOrigDatablock.js b/test/RawDatasetOrigDatablock.js index 553d5bbb0..f86bd5e03 100644 --- a/test/RawDatasetOrigDatablock.js +++ b/test/RawDatasetOrigDatablock.js @@ -18,7 +18,7 @@ describe("2000: RawDatasetOrigDatablock: Test OrigDatablocks and their relation db.collection("Dataset").deleteMany({}); db.collection("OrigDatablock").deleteMany({}); }); - beforeEach(async() => { + beforeEach(async () => { accessTokenAdminIngestor = await utils.getToken(appUrl, { username: "adminIngestor", password: TestData.Accounts["adminIngestor"]["password"], @@ -448,13 +448,13 @@ describe("2000: RawDatasetOrigDatablock: Test OrigDatablocks and their relation }); }); - it("0240: add a new origDatablock with invalid pid should fail", async () => { + it("0240: add a new origDatablock to the non-existent dataset should fail", async () => { return request(appUrl) .post(`/api/v3/origdatablocks`) .send({ ...origDatablockData1, datasetId: "wrong" }) .set("Accept", "application/json") .set({ Authorization: `Bearer ${accessTokenAdminIngestor}` }) - .expect(TestData.BadRequestStatusCode) + .expect(TestData.NotFoundStatusCode) .expect("Content-Type", /json/) .then((res) => { res.body.should.have.property("error"); diff --git a/test/TestData.js b/test/TestData.js index 641103e16..09f1541d1 100644 --- a/test/TestData.js +++ b/test/TestData.js @@ -24,6 +24,7 @@ const TestData = { BadRequestStatusCode: 400, AccessForbiddenStatusCode: 403, UnauthorizedStatusCode: 401, + NotFoundStatusCode: 404, CreationUnauthorizedStatusCode: 401, ConflictStatusCode: 409, ApplicationErrorStatusCode: 500,