@hexadrop/command
Version:
Hexagonal architecture utils library
56 lines (53 loc) • 2.49 kB
TypeScript
import * as bun_test from 'bun:test';
import Either from '@hexadrop/either';
import DomainError from '@hexadrop/error';
import CommandBus from './bus.js';
import Command from './command.js';
import '@hexadrop/types/class';
import '@hexadrop/types/primitives';
/**
* @class BunMockCommandBus
* @implements CommandBus
* @description Class representing a mock command bus for testing in Bun.
*/
declare class BunMockCommandBus implements CommandBus {
/**
* @property {Mock} dispatchSpy - A mock function for the dispatch method.
*/
readonly dispatchSpy: bun_test.Mock<(..._commands: Command[]) => Promise<Either<DomainError, never>>>;
/**
* This is a private static method that extracts data from a command.
* It omits the 'commandId' property from the command object and returns the remaining properties.
* If no command is provided, it returns an empty object.
*
* @template CommandType - A type that extends the Command interface.
* @param {CommandType} command - The command object from which to extract data. This is optional.
* @returns {Omit<CommandType, 'commandId'> | {}} - An object that contains the properties of the command object, excluding 'commandId'. If no command is provided, an empty object is returned.
*/
private static getDataFromCommand;
/**
* @method assertDispatchedCommands
* @description Method to assert that specific commands were dispatched.
* @param {...Command[]} expectedCommands - The expected dispatched commands.
*/
assertDispatchedCommands(...expectedCommands: Command[]): void;
/**
* @method assertLastDispatchedCommand
* @description Method to assert that a specific command was the last one dispatched.
* @param {Command} expectedCommand - The expected last dispatched command.
*/
assertLastDispatchedCommand(expectedCommand: Command): void;
/**
* @method assertNotDispatchedCommand
* @description Method to assert that no command was dispatched.
*/
assertNotDispatchedCommand(): void;
/**
* @method dispatch
* @description Method to dispatch a command.
* @param {Command} command - The command to be dispatched.
* @returns {Either<DomainError, void> | Promise<Either<DomainError, void>>} - The result of the command dispatch.
*/
dispatch(command: Command): Either<DomainError, void> | Promise<Either<DomainError, void>>;
}
export { BunMockCommandBus as default };