import type { Person } from '../../types'; import { cyLog, getAtom, getClientFromSpec, getSimulationAtomSlice, } from '../../utils'; import { assert } from 'assert-ts'; import type Bluebird from 'cypress/types/bluebird'; export function given(attrs: Partial = {}) { return cy.then((): Bluebird => { return new Cypress.Promise((resolve, reject) => { const client = getClientFromSpec(Cypress.spec.name); const simulation = getSimulationAtomSlice(); assert(!!simulation, 'no sumulation in given'); client .given(simulation, 'person', attrs) .then((scenario) => { cyLog('person created:', scenario); getAtom() .slice(Cypress.spec.name) .update((current) => { return { ...current, person: scenario.data, }; }); resolve(scenario.data); }) .catch((e) => { cyLog('Failed to create person:', e); reject(e); }); }); }); }