Skip to content

Commit

Permalink
🧪 test(mutations): add mutations tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thrownullexception committed Feb 20, 2024
1 parent 8bc3507 commit 82c9929
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 7 deletions.
19 changes: 18 additions & 1 deletion src/__tests__/_/api-handlers/integrations-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,24 @@ export const integrationsListApiHandlers = [
key: "non-activated-actions",
title: "Non Activated Actions",
description: "Some Non Activated Actions Description",
configurationSchema: {},
configurationSchema: {
username: {
type: "text",
validations: [
{
validationType: "required",
},
],
},
password: {
type: "text",
validations: [
{
validationType: "required",
},
],
},
},
},
{
key: "smtp",
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/_/forCodeCoverage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { FOR_CODE_COV as $16 } from "backend/integrations/libs/slack/types";
import { FOR_CODE_COV as $17 } from "backend/integrations/libs/smtp/types";
import { FOR_CODE_COV as $18 } from "backend/integrations/libs/twilio/types";
import { FOR_CODE_COV as $19 } from "backend/storage/types";
import { FOR_CODE_COV as $20 } from "frontend/design-system/theme/types";
import { FOR_CODE_COV as $21 } from "shared/form-schemas/roles/permissions/base";
import { FOR_CODE_COV as $22 } from "backend/lib/config-persistence/portal/index";
import { FOR_CODE_COV as $23 } from "backend/lib/config-persistence/portal/main/types";
Expand Down Expand Up @@ -63,6 +64,7 @@ noop(
$17,
$18,
$19,
$20,
$21,
$22,
$23,
Expand Down
2 changes: 2 additions & 0 deletions src/frontend/design-system/theme/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ export type IRootColors =
| keyof IColorMode
| "primary-shade-color"
| "primary-color";

export const FOR_CODE_COV = 1;
82 changes: 82 additions & 0 deletions src/frontend/lib/data/useMutate/__tests__/mutation-helpers.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { MutationHelpers } from "../mutation-helpers";

describe("MutationHelpers", () => {
it("append", () => {
const old = ["a", "b"];
const formData = "c";
expect(MutationHelpers.append(old, formData)).toEqual(["a", "b", "c"]);
});

it("remove", () => {
const old = ["a", "b", "c"];
const formData = "b";
expect(MutationHelpers.remove(old, formData)).toEqual(["a", "c"]);
});

it("deleteByKey", () => {
const old = [{ id: "a" }, { id: "b" }, { id: "c" }];
const key = "id";
const currentDataId = "b";
expect(MutationHelpers.deleteByKey(key)(old, currentDataId)).toEqual([
{ id: "a" },
{ id: "c" },
]);
});

it("mergeArray", () => {
const old = ["a", "b"];
const formData = ["c", "d"];
expect(MutationHelpers.mergeArray(old, formData)).toEqual([
"a",
"b",
"c",
"d",
]);
});

it("mergeObject", () => {
const old = { a: "a", b: "old" };
const formData = { b: "b" };
expect(MutationHelpers.mergeObject(old, formData)).toEqual({
a: "a",
b: "b",
});
});

it("replace", () => {
const old = "a";
const formData = "b";
expect(MutationHelpers.replace(old, formData)).toEqual("b");
});

it("update", () => {
const old = [{ id: "a" }, { id: "b" }];
const formData = { id: "b", data: "c" };
expect(MutationHelpers.update(old, formData)).toEqual([
{ id: "a" },
{ id: "b", data: "c" },
]);
});

it("delete", () => {
const old = [{ id: "a" }, { id: "b" }];
const currentDataId = "b";
expect(MutationHelpers.delete(old, currentDataId)).toEqual([{ id: "a" }]);
});

it("sortOrder", () => {
const old = [{ id: "a" }, { id: "b" }, { id: "c" }];
const order = ["c", "a", "b"];
expect(MutationHelpers.sortOrder(old, order)).toEqual([
{ id: "c" },
{ id: "a" },
{ id: "b" },
]);
});

it("removeMany", () => {
const old = ["a", "b", "c"];
const formData = ["b", "c"];
expect(MutationHelpers.removeMany(old, formData)).toEqual(["a"]);
});
});
6 changes: 0 additions & 6 deletions src/frontend/lib/numbers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,3 @@ export function abbreviateNumber(value: number) {
newValueString += suffixes[suffixNum];
return newValueString;
}

export const randomNumber = ($min: number, $max: number) => {
const min = Math.ceil($min);
const max = Math.floor($max);
return Math.floor(Math.random() * (max - min + 1)) + min;
};

0 comments on commit 82c9929

Please sign in to comment.