From e2bbb60d2527e6badce25ce4e3fcc782a921977e Mon Sep 17 00:00:00 2001 From: Nana Adjei Manu Date: Sun, 24 Mar 2024 00:19:28 +0000 Subject: [PATCH] chore: update some specs --- src/index.spec.ts | 43 ++++++++++++++++++++++++++++++------------- src/index.ts | 13 ++++++++----- 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/src/index.spec.ts b/src/index.spec.ts index 3c40ea8..191112e 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -1,4 +1,4 @@ -import { LaunchLever, Toggle } from "./index"; +import { LaunchLever, Toggle, isOn } from "./index"; const flags: Toggle[] = [ { @@ -8,18 +8,35 @@ const flags: Toggle[] = [ }, ]; -test("it should return 'on' is status is on", () => { - const toggles = new LaunchLever(flags).flags; - expect(toggles.pfx_123).toEqual("on"); +describe("#isON", () => { + test("should be true when flag is on", () => { + expect(isOn("on")).toBeTruthy(); + }); + + test("should be false when status if 'off'", () => { + expect(isOn("off")).toBeFalsy(); + }); }); -test("it should return 'off' is status is off", () => { - const toggles = new LaunchLever([ - { - name: "pfx_123", - description: "some stuff", - status: "off", - }, - ]).flags; - expect(toggles.pfx_123).toEqual("off"); +describe("LaunchLever", () => { + test("it should return 'off' is status is off", () => { + const toggles = new LaunchLever([ + { + name: "pfx_123", + description: "some stuff", + status: "off", + }, + ]).flags; + expect(isOn(toggles.pfx_123)).toBeFalsy(); + }); + + test("it should return 'on' is status is on", () => { + const toggles = new LaunchLever(flags).flags; + expect(isOn(toggles.pfx_123)).toBeTruthy(); + }); + + test("it should return all toggles", () => { + const toggles = new LaunchLever(flags).toggles; + expect(toggles).toEqual(flags); + }); }); diff --git a/src/index.ts b/src/index.ts index a7d99d1..934d764 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,16 +4,23 @@ export interface Toggle { status: "on" | "off"; } +type ToggleStatus = "on" | "off"; interface ToggleStatuses { - [key: string]: "on" | "off"; + [key: string]: ToggleStatus; } +export const isOn = (status: ToggleStatus): boolean => status === "on"; + export class LaunchLever { _flags: Toggle[] = []; constructor(flags: Toggle[]) { this._flags = flags; } + get toggles(): Toggle[] { + return this._flags; + } + get flags() { let toggles: ToggleStatuses = {}; for (let t of this._flags) { @@ -22,7 +29,3 @@ export class LaunchLever { return toggles; } } - -export default { - LaunchLever, -};