Skip to content

Commit

Permalink
refactor: remove isPI method and its associated tests from DatasetDet…
Browse files Browse the repository at this point in the history
…ailComponent
  • Loading branch information
Junjiequan committed Nov 28, 2024
1 parent 0d37dfb commit 29f2e66
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 135 deletions.
110 changes: 0 additions & 110 deletions src/app/datasets/dataset-detail/dataset-detail.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,114 +358,4 @@ describe("DatasetDetailComponent", () => {
);
});
});

describe("#isPI()", () => {
it("should return true if user username is admin", () => {
component.user = new User({
username: "admin",
email: "[email protected]",
});

const isPI = component.isPI();

expect(isPI).toEqual(true);
});

it("should return true if user email equals principalInvestigator of a raw dataset", () => {
component.user = new User({ email: "[email protected]" });
component.dataset = {
owner: "test",
contactEmail: "test",
sourceFolder: "test",
creationTime: new Date(),
type: "raw",
ownerGroup: "test",
principalInvestigator: "[email protected]",
creationLocation: "test",
} as unknown as Dataset;

const isPI = component.isPI();

expect(isPI).toEqual(true);
});

it("should return false if user email does not equal principalInvestigator of a raw dataset", () => {
component.user = new User({ email: "[email protected]" });
component.dataset = {
owner: "test",
contactEmail: "test",
sourceFolder: "test",
creationTime: new Date(),
type: "raw",
ownerGroup: "test",
principalInvestigator: "[email protected]",
creationLocation: "test",
} as unknown as Dataset;
const isPI = component.isPI();

expect(isPI).toEqual(false);
});

it("should return true if user email equals investigator of a derived dataset", () => {
component.user = new User({ email: "[email protected]" });
component.dataset = {
owner: "test",
contactEmail: "test",
sourceFolder: "test",
creationTime: new Date(),
type: "derived",
ownerGroup: "test",
investigator: "[email protected]",
inputDatasets: ["test"],
usedSoftware: ["test"],
} as unknown as Dataset;

const isPI = component.isPI();

expect(isPI).toEqual(true);
});

it("should return false if user email does not equal investigator of a derived dataset", () => {
component.user = new User({ email: "[email protected]" });
component.dataset = {
owner: "test",
contactEmail: "test",
sourceFolder: "test",
creationTime: new Date(),
type: "derived",
ownerGroup: "test",
investigator: "[email protected]",
inputDatasets: ["test"],
usedSoftware: ["test"],
} as unknown as Dataset;
const isPI = component.isPI();

expect(isPI).toEqual(false);
});

it("should return false if dataset type is neither 'raw' or 'derived'", () => {
component.user = new User({ email: "[email protected]" });
component.dataset = {
owner: "test",
contactEmail: "test",
sourceFolder: "test",
creationTime: new Date(),
type: "failTest",
ownerGroup: "test",
principalInvestigator: "[email protected]",
creationLocation: "test",
} as unknown as Dataset;
const isPI = component.isPI();

expect(isPI).toEqual(false);
});

it("should return false if no user is provided", () => {
component.user = undefined;

const isPI = component.isPI();

expect(isPI).toEqual(false);
});
});
});
25 changes: 0 additions & 25 deletions src/app/datasets/dataset-detail/dataset-detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,31 +165,6 @@ export class DatasetDetailComponent
return this._hasUnsavedChanges;
}

isPI(): boolean {
if (this.user && this.dataset) {
if (this.user.username === "admin") {
return true;
}
if (this.dataset.type === "raw") {
return (
this.user.email.toLowerCase() ===
(this.dataset as unknown as RawDataset)[
"principalInvestigator"
].toLowerCase()
);
}
if (this.dataset.type === "derived") {
return (
this.user.email.toLowerCase() ===
(this.dataset as unknown as DerivedDataset)[
"investigator"
].toLowerCase()
);
}
}
return false;
}

onClickKeyword(keyword: string) {
this.store.dispatch(clearFacetsAction());
this.store.dispatch(addKeywordFilterAction({ keyword }));
Expand Down

0 comments on commit 29f2e66

Please sign in to comment.