UNPKG

dynamodb-toolbox

Version:

Lightweight and type-safe query builder for DynamoDB and TypeScript.

28 lines (27 loc) 789 B
import { isString } from '../../../utils/validation/isString.js'; import { $actionName, $mocks, $spy } from './constants.js'; export class EntityActionStub { constructor(spy, Action) { this[$spy] = spy; this[$actionName] = Action.actionName; } resolve(response) { this[$spy][$mocks][this[$actionName]] = () => response; return this[$spy]; } reject(error) { this[$spy][$mocks][this[$actionName]] = () => { if (error === undefined || isString(error)) { throw new Error(error); } else { throw error; } }; return this[$spy]; } mock(mock) { this[$spy][$mocks][this[$actionName]] = mock; return this[$spy]; } }