Skip to content

Commit

Permalink
chore: update some specs
Browse files Browse the repository at this point in the history
  • Loading branch information
Nana Adjei Manu committed Mar 24, 2024
1 parent a495006 commit e2bbb60
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
43 changes: 30 additions & 13 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LaunchLever, Toggle } from "./index";
import { LaunchLever, Toggle, isOn } from "./index";

const flags: Toggle[] = [
{
Expand All @@ -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);
});
});
13 changes: 8 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -22,7 +29,3 @@ export class LaunchLever {
return toggles;
}
}

export default {
LaunchLever,
};

0 comments on commit e2bbb60

Please sign in to comment.