Skip to content

Commit

Permalink
Added more test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
nroh555 committed Jun 30, 2024
1 parent 2c29726 commit 5a2ba7d
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 0 deletions.
27 changes: 27 additions & 0 deletions web/__test__/utils/MapToExec.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, expect, it } from "vitest";
import { Exec } from "../../src/types/types";
import { Mapper } from "../../src/utils/Mapper";
import { NoDataError } from "../../src/classes/NoDataError";

describe("mapToExec", () => {
it("should map valid data correctly", () => {
Expand Down Expand Up @@ -250,4 +251,30 @@ describe("mapToExec", () => {

expect(Mapper.mapToExec(data)).toEqual(expected);
});
it("should throw NoDataError when execs.data is empty", () => {
const data = {
execs: {
data: [],
},
};

expect(() => Mapper.mapToExec(data)).toThrow(NoDataError);
expect(() => Mapper.mapToExec(data)).toThrow("No data");
});

it("should throw NoDataError when execs is missing", () => {
const data = {};

expect(() => Mapper.mapToExec(data)).toThrow(NoDataError);
expect(() => Mapper.mapToExec(data)).toThrow("No data");
});

it("should throw NoDataError when execs.data is missing", () => {
const data = {
execs: {},
};

expect(() => Mapper.mapToExec(data)).toThrow(NoDataError);
expect(() => Mapper.mapToExec(data)).toThrow("No data");
});
});
27 changes: 27 additions & 0 deletions web/__test__/utils/MapToIntroduction.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, expect, it } from "vitest";
import { Introduction } from "../../src/types/types";
import { Mapper } from "../../src/utils/Mapper";
import { NoDataError } from "../../src/classes/NoDataError";

describe("mapToIntroduction", () => {
it("should map valid data correctly", () => {
Expand Down Expand Up @@ -202,4 +203,30 @@ describe("mapToIntroduction", () => {

expect(Mapper.mapToIntroduction(data)).toEqual(expected);
});
it("should throw NoDataError when introductions.data is empty", () => {
const data = {
introductions: {
data: [],
},
};

expect(() => Mapper.mapToIntroduction(data)).toThrow(NoDataError);
expect(() => Mapper.mapToIntroduction(data)).toThrow("No data");
});

it("should throw NoDataError when introductions is missing", () => {
const data = {};

expect(() => Mapper.mapToIntroduction(data)).toThrow(NoDataError);
expect(() => Mapper.mapToIntroduction(data)).toThrow("No data");
});

it("should throw NoDataError when introductions.data is missing", () => {
const data = {
execs: {},
};

expect(() => Mapper.mapToIntroduction(data)).toThrow(NoDataError);
expect(() => Mapper.mapToIntroduction(data)).toThrow("No data");
});
});
27 changes: 27 additions & 0 deletions web/__test__/utils/MapToPartner.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, expect, it } from "vitest";
import { Partner } from "../../src/types/types";
import { Mapper } from "../../src/utils/Mapper";
import { NoDataError } from "../../src/classes/NoDataError";

describe("mapToPartner", () => {
it("should map valid data correctly", () => {
Expand Down Expand Up @@ -249,4 +250,30 @@ describe("mapToPartner", () => {

expect(Mapper.mapToPartner(data)).toEqual(expected);
});
it("should throw NoDataError when partners.data is empty", () => {
const data = {
partners: {
data: [],
},
};

expect(() => Mapper.mapToPartner(data)).toThrow(NoDataError);
expect(() => Mapper.mapToPartner(data)).toThrow("No data");
});

it("should throw NoDataError when partners is missing", () => {
const data = {};

expect(() => Mapper.mapToPartner(data)).toThrow(NoDataError);
expect(() => Mapper.mapToPartner(data)).toThrow("No data");
});

it("should throw NoDataError when partners.data is missing", () => {
const data = {
partners: {},
};

expect(() => Mapper.mapToPartner(data)).toThrow(NoDataError);
expect(() => Mapper.mapToPartner(data)).toThrow("No data");
});
});
27 changes: 27 additions & 0 deletions web/__test__/utils/MapToSocials.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, expect, it } from "vitest";
import { Social } from "../../src/types/types";
import { Mapper } from "../../src/utils/Mapper";
import { NoDataError } from "../../src/classes/NoDataError";

describe("mapToSocials", () => {
it("should map valid data correctly", () => {
Expand Down Expand Up @@ -115,4 +116,30 @@ describe("mapToSocials", () => {

expect(Mapper.mapToSocials(data)).toEqual(expected);
});
it("should throw NoDataError when socials.data is empty", () => {
const data = {
socials: {
data: [],
},
};

expect(() => Mapper.mapToSocials(data)).toThrow(NoDataError);
expect(() => Mapper.mapToSocials(data)).toThrow("No data");
});

it("should throw NoDataError when socials is missing", () => {
const data = {};

expect(() => Mapper.mapToSocials(data)).toThrow(NoDataError);
expect(() => Mapper.mapToSocials(data)).toThrow("No data");
});

it("should throw NoDataError when socials.data is missing", () => {
const data = {
execs: {},
};

expect(() => Mapper.mapToSocials(data)).toThrow(NoDataError);
expect(() => Mapper.mapToSocials(data)).toThrow("No data");
});
});
27 changes: 27 additions & 0 deletions web/__test__/utils/MapToSomePhotos.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, expect, it } from "vitest";
import { SomePhoto } from "../../src/types/types";
import { Mapper } from "../../src/utils/Mapper";
import { NoDataError } from "../../src/classes/NoDataError";

describe("mapToSomePhotos", () => {
it("should map valid data correctly", () => {
Expand Down Expand Up @@ -176,4 +177,30 @@ describe("mapToSomePhotos", () => {

expect(Mapper.mapToSomePhotos(data)).toEqual(expected);
});
it("should throw NoDataError when somePhotos.data is empty", () => {
const data = {
somePhotos: {
data: [],
},
};

expect(() => Mapper.mapToSomePhotos(data)).toThrow(NoDataError);
expect(() => Mapper.mapToSomePhotos(data)).toThrow("No data");
});

it("should throw NoDataError when somePhotos is missing", () => {
const data = {};

expect(() => Mapper.mapToSomePhotos(data)).toThrow(NoDataError);
expect(() => Mapper.mapToSomePhotos(data)).toThrow("No data");
});

it("should throw NoDataError when somePhotos.data is missing", () => {
const data = {
somePhotos: {},
};

expect(() => Mapper.mapToSomePhotos(data)).toThrow(NoDataError);
expect(() => Mapper.mapToSomePhotos(data)).toThrow("No data");
});
});
27 changes: 27 additions & 0 deletions web/__test__/utils/MapToValue.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, expect, it } from "vitest";
import { Value } from "../../src/types/types";
import { Mapper } from "../../src/utils/Mapper";
import { NoDataError } from "../../src/classes/NoDataError";

describe("mapToValue", () => {
it("should map valid data correctly", () => {
Expand Down Expand Up @@ -156,4 +157,30 @@ describe("mapToValue", () => {

expect(Mapper.mapToValue(data)).toEqual(expected);
});
it("should throw NoDataError when values.data is empty", () => {
const data = {
values: {
data: [],
},
};

expect(() => Mapper.mapToValue(data)).toThrow(NoDataError);
expect(() => Mapper.mapToValue(data)).toThrow("No data");
});

it("should throw NoDataError when values is missing", () => {
const data = {};

expect(() => Mapper.mapToValue(data)).toThrow(NoDataError);
expect(() => Mapper.mapToValue(data)).toThrow("No data");
});

it("should throw NoDataError when values.data is missing", () => {
const data = {
values: {},
};

expect(() => Mapper.mapToValue(data)).toThrow(NoDataError);
expect(() => Mapper.mapToValue(data)).toThrow("No data");
});
});

0 comments on commit 5a2ba7d

Please sign in to comment.