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

fix: create origdatablock with empty chkAlg causing 500 error #414

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions src/origdatablocks/dto/create-origdatablock.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
IsInt,
IsOptional,
IsString,
IsNotEmpty,
ValidateNested,
} from "class-validator";
import { DataFileDto } from "src/common/dto/datafile.dto";
Expand All @@ -20,6 +21,7 @@ export class CreateOrigDatablockDto extends OwnableDto {

@IsOptional()
@IsString()
@IsNotEmpty()
readonly chkAlg: string;

@IsArray()
Expand Down
2 changes: 1 addition & 1 deletion src/origdatablocks/schemas/origdatablock.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class OrigDatablock extends OwnableClass {
description: "Algorithm used to compute the file chksum",
})
@Prop({
type: Number,
type: String,
required: false,
})
chkAlg: string;
Expand Down
14 changes: 10 additions & 4 deletions test/Instrument.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let accessToken = null,
accessTokenArchiveManager = null,
instrumentId = null;

const newName="ESS2.5";
const newName = "ESS2.5";

describe("Instrument: Instrument management", () => {
beforeEach((done) => {
Expand Down Expand Up @@ -44,7 +44,9 @@ describe("Instrument: Instrument management", () => {
.expect(201)
.expect("Content-Type", /json/)
.then((res) => {
res.body.should.have.property("name").and.be.equal(TestData.InstrumentCorrect.name);
res.body.should.have
.property("name")
.and.be.equal(TestData.InstrumentCorrect.name);
res.body.should.have.property("pid").and.be.string;
instrumentId = res.body["pid"];
});
Expand All @@ -58,7 +60,9 @@ describe("Instrument: Instrument management", () => {
.expect(200)
.expect("Content-Type", /json/)
.then((res) => {
res.body.should.have.property("name").and.be.equal(TestData.InstrumentCorrect.name);
res.body.should.have
.property("name")
.and.be.equal(TestData.InstrumentCorrect.name);
res.body.should.have.property("pid").and.be.equal(instrumentId);
});
});
Expand All @@ -72,7 +76,9 @@ describe("Instrument: Instrument management", () => {
.expect("Content-Type", /json/)
.then((res) => {
res.body.should.be.an("array").to.have.length(1);
res.body[0].should.have.property("name").and.be.equal(TestData.InstrumentCorrect.name);
res.body[0].should.have
.property("name")
.and.be.equal(TestData.InstrumentCorrect.name);
res.body[0].should.have.property("pid").and.be.equal(instrumentId);
});
});
Expand Down
96 changes: 77 additions & 19 deletions test/RawDatasetOrigDatablock.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/* eslint-disable @typescript-eslint/no-var-requires */
var utils = require("./LoginUtils");
const utils = require("./LoginUtils");
const { TestData } = require("./TestData");

describe("RawDatasetOrigDatablock: Test OrigDatablocks and their relation to raw Datasets", () => {
var accessTokenIngestor = null;
var accessTokenArchiveManager = null;

var datasetPid = null;

var origDatablockId1 = null;
var origDatablockId2 = null;

var origDatablockData1 = null;
var origDatablockData2 = null;
let accessTokenIngestor = null,
accessTokenArchiveManager = null,
datasetPid = null,
origDatablockId1 = null,
origDatablockId2 = null,
origDatablockId3 = null,
origDatablockData1 = null,
origDatablockData2 = null,
origDatablockWithEmptyChkAlg = null,
origDatablockWithValidChkAlg = null;

beforeEach((done) => {
utils.getToken(
Expand All @@ -39,6 +39,8 @@ describe("RawDatasetOrigDatablock: Test OrigDatablocks and their relation to raw

origDatablockData1 = { ...TestData.OrigDataBlockCorrect1 };
origDatablockData2 = { ...TestData.OrigDataBlockCorrect2 };
origDatablockWithEmptyChkAlg = { ...TestData.OrigDataBlockWrongChkAlg };
origDatablockWithValidChkAlg = { ...TestData.OrigDataBlockCorrect3 };
});

it("adds a new raw dataset", async () => {
Expand Down Expand Up @@ -102,6 +104,36 @@ describe("RawDatasetOrigDatablock: Test OrigDatablocks and their relation to raw
.expect("Content-Type", /json/);
});

it("add a new origDatablock with empty chkAlg should fail", async () => {
return request(appUrl)
.post(`/api/v3/datasets/${datasetPid}/OrigDatablocks`)
.send(origDatablockWithEmptyChkAlg)
.set("Accept", "application/json")
.set({ Authorization: `Bearer ${accessTokenIngestor}` })
.expect(400)
.expect("Content-Type", /json/)
.then((res) => {
res.body.should.have.property("error");
});
});

it("add a new origDatablock with valid chkAlg should success", async () => {
return request(appUrl)
.post(`/api/v3/datasets/${datasetPid}/OrigDatablocks`)
.send(origDatablockWithValidChkAlg)
.set("Accept", "application/json")
.set({ Authorization: `Bearer ${accessTokenIngestor}` })
.expect(201)
.expect("Content-Type", /json/)
.then((res) => {
res.body.should.have
.property("chkAlg")
.and.equal(TestData.OrigDataBlockCorrect3.chkAlg);
res.body.should.have.property("id").and.be.string;
origDatablockId3 = encodeURIComponent(res.body["id"]);
});
});

it("adds a new origDatablock with correct account", async () => {
return request(appUrl)
.post(`/api/v3/datasets/${datasetPid}/OrigDatablocks`)
Expand Down Expand Up @@ -144,9 +176,22 @@ describe("RawDatasetOrigDatablock: Test OrigDatablocks and their relation to raw
.expect(200)
.expect("Content-Type", /json/)
.then((res) => {
res.body.should.be.instanceof(Array).and.to.have.length(2);
res.body[0]["id"].should.be.oneOf([origDatablockId1, origDatablockId2]);
res.body[1]["id"].should.be.oneOf([origDatablockId1, origDatablockId2]);
res.body.should.be.instanceof(Array).and.to.have.length(3);
res.body[0]["id"].should.be.oneOf([
origDatablockId1,
origDatablockId2,
origDatablockId3,
]);
res.body[1]["id"].should.be.oneOf([
origDatablockId1,
origDatablockId2,
origDatablockId3,
]);
res.body[2]["id"].should.be.oneOf([
origDatablockId1,
origDatablockId2,
origDatablockId3,
]);
});
});

Expand All @@ -160,7 +205,8 @@ describe("RawDatasetOrigDatablock: Test OrigDatablocks and their relation to raw
.then((res) => {
res.body["size"].should.be.equal(
TestData.OrigDataBlockCorrect1.size +
TestData.OrigDataBlockCorrect2.size,
TestData.OrigDataBlockCorrect2.size +
TestData.OrigDataBlockCorrect3.size,
);
});
});
Expand Down Expand Up @@ -196,8 +242,8 @@ describe("RawDatasetOrigDatablock: Test OrigDatablocks and their relation to raw
res.body["pid"].should.be.equal(decodeURIComponent(datasetPid));
res.body.origdatablocks.should.be
.instanceof(Array)
.and.to.have.length(2);
res.body.origdatablocks[0].should.have
.and.to.have.length(3);
res.body.origdatablocks[1].should.have
.property("dataFileList")
.and.be.instanceof(Array)
.and.to.have.length(
Expand Down Expand Up @@ -318,13 +364,15 @@ describe("RawDatasetOrigDatablock: Test OrigDatablocks and their relation to raw
.property("size")
.and.equal(
TestData.OrigDataBlockCorrect1.size +
TestData.OrigDataBlockCorrect2.size,
TestData.OrigDataBlockCorrect2.size +
TestData.OrigDataBlockCorrect3.size,
);
res.body.should.have
.property("numberOfFiles")
.and.equal(
TestData.OrigDataBlockCorrect1.dataFileList.length +
TestData.OrigDataBlockCorrect2.dataFileList.length,
TestData.OrigDataBlockCorrect2.dataFileList.length +
TestData.OrigDataBlockCorrect3.dataFileList.length,
);
});
});
Expand All @@ -349,6 +397,16 @@ describe("RawDatasetOrigDatablock: Test OrigDatablocks and their relation to raw
.expect(200);
});

it("should delete third OrigDatablock", async () => {
return request(appUrl)
.delete(
`/api/v3/datasets/${datasetPid}/OrigDatablocks/${origDatablockId3}`,
)
.set("Accept", "application/json")
.set({ Authorization: `Bearer ${accessTokenArchiveManager}` })
.expect(200);
});

it("Should fetch no origdatablocks belonging to the new dataset", async () => {
return request(appUrl)
.get(`/api/v3/Datasets/${datasetPid}/OrigDatablocks`)
Expand Down
30 changes: 30 additions & 0 deletions test/TestData.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-var-requires */
const { faker } = require("@faker-js/faker");

const TestData = {
Expand Down Expand Up @@ -565,9 +566,38 @@ const TestData = {
],
},

OrigDataBlockCorrect3: {
chkAlg: "Test-chkAlg",
size: 41780189,
dataFileList: [
{
path: "N1039-1.tif",
size: 8356037,
time: "2017-07-24T13:56:30.000Z",
uid: "egon.meiera@psi.ch",
gid: "p16738",
perm: "-rw-rw-r--",
},
],
},

OrigDataBlockWrong: {
size: "This is wrong",
},
OrigDataBlockWrongChkAlg: {
chkAlg: "",
size: 41780189,
dataFileList: [
{
path: "N1039-1.tif",
size: 8356037,
time: "2017-07-24T13:56:30.000Z",
uid: "egon.meiera@psi.ch",
gid: "p16738",
perm: "-rw-rw-r--",
},
],
},

DatasetLifecycle_query_1: {
fields: {
Expand Down