Skip to content

Commit

Permalink
refactor: remove deprecated ofFunc and ofPromise cmd objects
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `ofFunc` and `ofPromise` cmd objects were removed. Use `ofEither`, `ofSuccess` and `ofError` instead.
  • Loading branch information
atheck committed Nov 1, 2024
1 parent 382e04d commit 7b88cb1
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 488 deletions.
338 changes: 0 additions & 338 deletions src/cmd.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,342 +283,4 @@ describe("cmd", () => {
expect(message.name).toBe("error");
});
});

describe("ofFunc", () => {
describe("either", () => {
it("returns one function", () => {
// arrange
const result = cmd.ofFunc.either(jest.fn(), successMsg, errorMsg);

// assert
expect(result).toHaveLength(1);
expect(result[0]).toBeInstanceOf(Function);
});

it("runs the task", () => {
// arrange
const task = jest.fn();
const result = cmd.ofFunc.either(task, successMsg, errorMsg);

// act
result[0]?.(() => null);

// assert
expect(task).toHaveBeenCalledTimes(1);
});

it("dispatches the success message", () => {
// arrange
const task = jest.fn();
const result = cmd.ofFunc.either(task, successMsg, errorMsg);

// act
let message: Message = { name: "none" };

result[0]?.((msg) => {
message = msg;
});

// assert
expect(message.name).toBe("success");
});

it("dispatches the error message", () => {
// arrange
const task = jest.fn(() => {
throw new Error("error");
});
const result = cmd.ofFunc.either(task, successMsg, errorMsg);

// act
let message: Message = { name: "none" };

result[0]?.((msg) => {
message = msg;
});

// assert
expect(message.name).toBe("error");
});
});

describe("perform", () => {
it("returns one function", () => {
// arrange
const result = cmd.ofFunc.perform(jest.fn(), successMsg);

// assert
expect(result).toHaveLength(1);
expect(result[0]).toBeInstanceOf(Function);
});

it("runs the task", () => {
// arrange
const task = jest.fn();
const result = cmd.ofFunc.perform(task, successMsg);

// act
result[0]?.(() => null);

// assert
expect(task).toHaveBeenCalledTimes(1);
});

it("dispatches the success message", () => {
// arrange
const task = jest.fn();
const result = cmd.ofFunc.perform(task, successMsg);

// act
let message: Message = { name: "none" };

result[0]?.((msg) => {
message = msg;
});

// assert
expect(message.name).toBe("success");
});

it("ignores an error", () => {
// arrange
const task = jest.fn(() => {
throw new Error("error");
});
const result = cmd.ofFunc.perform(task, successMsg);

// act
let message: Message = { name: "none" };

result[0]?.((msg) => {
message = msg;
});

// assert
expect(message.name).toBe("none");
});
});

describe("attempt", () => {
it("returns one function", () => {
// arrange
const result = cmd.ofFunc.attempt(jest.fn(), errorMsg);

// assert
expect(result).toHaveLength(1);
expect(result[0]).toBeInstanceOf(Function);
});

it("runs the task", () => {
// arrange
const task = jest.fn();
const result = cmd.ofFunc.attempt(task, errorMsg);

// act
result[0]?.(() => null);

// assert
expect(task).toHaveBeenCalledTimes(1);
});

it("ignores the success", () => {
// arrange
const task = jest.fn();
const result = cmd.ofFunc.attempt(task, errorMsg);

// act
let message: Message = { name: "none" };

result[0]?.((msg) => {
message = msg;
});

// assert
expect(message.name).toBe("none");
});

it("dispatches the error message", () => {
// arrange
const task = jest.fn(() => {
throw new Error("error");
});
const result = cmd.ofFunc.attempt(task, errorMsg);

// act
let message: Message = { name: "none" };

result[0]?.((msg) => {
message = msg;
});

// assert
expect(message.name).toBe("error");
});
});
});

describe("ofPromise", () => {
describe("either", () => {
it("returns one function", () => {
// arrange
const result = cmd.ofPromise.either(asyncResolve, successMsg, errorMsg);

// assert
expect(result).toHaveLength(1);
expect(result[0]).toBeInstanceOf(Function);
});

it("runs the task", () => {
// arrange
const task = jest.fn(asyncResolve);
const result = cmd.ofPromise.either(task, successMsg, errorMsg);

// act
result[0]?.(() => null);

// assert
expect(task).toHaveBeenCalledTimes(1);
});

it("dispatches the success message", async () => {
// arrange
const task = jest.fn(asyncResolve);
const result = cmd.ofPromise.either(task, successMsg, errorMsg);

// act
const act = async (): Promise<Message> =>
new Promise((resolve) => {
result[0]?.(resolve);
});
const message = await act();

// assert
expect(message.name).toBe("success");
});

it("dispatches the error message", async () => {
// arrange
const task = jest.fn(async () => {
throw new Error("error");
});
const result = cmd.ofPromise.either(task, successMsg, errorMsg);

// act
const act = async (): Promise<Message> =>
new Promise((resolve) => {
result[0]?.(resolve);
});
const message = await act();

// assert
expect(message.name).toBe("error");
});
});

describe("perform", () => {
it("returns one function", () => {
// arrange
const result = cmd.ofPromise.perform(asyncResolve, successMsg);

// assert
expect(result).toHaveLength(1);
expect(result[0]).toBeInstanceOf(Function);
});

it("runs the task", () => {
// arrange
const task = jest.fn(asyncResolve);
const result = cmd.ofPromise.perform(task, successMsg);

// act
result[0]?.(() => null);

// assert
expect(task).toHaveBeenCalledTimes(1);
});

it("dispatches the success message", async () => {
// arrange
const task = jest.fn(asyncResolve);
const result = cmd.ofPromise.perform(task, successMsg);

// act
const act = async (): Promise<Message> =>
new Promise((resolve) => {
result[0]?.(resolve);
});
const message = await act();

// assert
expect(message.name).toBe("success");
});

it("ignores an error", async () => {
// arrange
const task = jest.fn(async () => {
throw new Error("error");
});
const result = cmd.ofPromise.perform(task, successMsg);

// act
const succeeds = (): void => result[0]?.(jest.fn());

// assert
expect(succeeds).not.toThrow();
});
});

describe("attempt", () => {
it("returns one function", () => {
// arrange
const result = cmd.ofPromise.attempt(asyncResolve, errorMsg);

// assert
expect(result).toHaveLength(1);
expect(result[0]).toBeInstanceOf(Function);
});

it("runs the task", () => {
// arrange
const task = jest.fn(asyncResolve);
const result = cmd.ofPromise.attempt(task, errorMsg);

// act
result[0]?.(() => null);

// assert
expect(task).toHaveBeenCalledTimes(1);
});

it("ignores the success", async () => {
// arrange
const task = jest.fn(asyncResolve);
const result = cmd.ofPromise.attempt(task, errorMsg);

// act
result[0]?.(jest.fn());

// assert
expect(task).toHaveBeenCalledWith();
});

it("dispatches the error message", async () => {
// arrange
const task = jest.fn(async () => {
throw new Error("error");
});
const result = cmd.ofPromise.attempt(task, errorMsg);

// act
const act = async (): Promise<Message> =>
new Promise((resolve) => {
result[0]?.(resolve);
});
const message = await act();

// assert
expect(message.name).toBe("error");
});
});
});
});
Loading

0 comments on commit 7b88cb1

Please sign in to comment.