From 2fdc9804183da59c9569e6336bb5fcae7a1c25a3 Mon Sep 17 00:00:00 2001 From: Ulises Gascon Date: Sat, 28 Oct 2023 23:09:31 +0200 Subject: [PATCH] test: added specs for getRefinedChecks function --- src/utils/comparator/getRefinedChecks.test.ts | 42 +++++++++++++++++++ ...tRefinedChecks.tsx => getRefinedChecks.ts} | 0 2 files changed, 42 insertions(+) create mode 100644 src/utils/comparator/getRefinedChecks.test.ts rename src/utils/comparator/{getRefinedChecks.tsx => getRefinedChecks.ts} (100%) diff --git a/src/utils/comparator/getRefinedChecks.test.ts b/src/utils/comparator/getRefinedChecks.test.ts new file mode 100644 index 0000000..afdbf8e --- /dev/null +++ b/src/utils/comparator/getRefinedChecks.test.ts @@ -0,0 +1,42 @@ +import { getRefinedChecks } from "./getRefinedChecks.ts"; +import { CHECKS_LIST_NAMES } from "../../constants/checks"; +import sample1 from "../../../cypress/fixtures/2ac5e9889aba461f5a54d320973d2574980d206b.json"; +import sample2 from "../../../cypress/fixtures/077fd7d83d7d41695137c1af5b9be1d72250e69e.json"; + +describe("util: getRefinedChecks", () => { + it("Should handle empty checks", () => { + expect(getRefinedChecks([], [])).toEqual({ + common: [], + discrepancies: [], + }); + }); + + it("Should handle an empty check", () => { + expect(getRefinedChecks(sample1.checks, [])).toEqual({ + common: [], + discrepancies: CHECKS_LIST_NAMES, + }); + + expect(getRefinedChecks([], sample1.checks)).toEqual({ + common: [], + discrepancies: CHECKS_LIST_NAMES, + }); + }); + + it("Should generate a refined valid result", () => { + expect(getRefinedChecks(sample1.checks, sample2.checks)).toEqual({ + common: CHECKS_LIST_NAMES, + discrepancies: [], + }); + }); + + it("Should handle discrepancies and provide a valid result", () => { + const filteredList = sample1.checks.filter( + (item) => item.name !== "Binary-Artifacts", + ); + expect(getRefinedChecks(filteredList, sample2.checks)).toEqual({ + common: filteredList.map((item) => item.name), + discrepancies: ["Binary-Artifacts"], + }); + }); +}); diff --git a/src/utils/comparator/getRefinedChecks.tsx b/src/utils/comparator/getRefinedChecks.ts similarity index 100% rename from src/utils/comparator/getRefinedChecks.tsx rename to src/utils/comparator/getRefinedChecks.ts