Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ensure consistent handling of "not found" errors #1520

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix: fix failing api test
  • Loading branch information
Junjiequan committed Nov 26, 2024
commit da84a99b3507e8b1c402d56d178d4b2679d11448
4 changes: 3 additions & 1 deletion src/origdatablocks/origdatablocks.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
8 changes: 4 additions & 4 deletions test/DerivedDatasetOrigDatablock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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({
Expand Down
4 changes: 2 additions & 2 deletions test/OrigDatablockForRawDataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
6 changes: 3 additions & 3 deletions test/RawDatasetOrigDatablock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions test/TestData.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const TestData = {
BadRequestStatusCode: 400,
AccessForbiddenStatusCode: 403,
UnauthorizedStatusCode: 401,
NotFoundStatusCode: 404,
CreationUnauthorizedStatusCode: 401,
ConflictStatusCode: 409,
ApplicationErrorStatusCode: 500,
Expand Down
Loading