/
githubmirror
/
strapi
Обзор
Документация
Войти
/
githubmirror
/
strapi
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
packages/utils/api-tests/builder/context.js
43 строки
813 B
Alexandre BODIN
Move api tests to root of repo with same structure (#16242)
05 апр 2023, 11:32
Не верифицирован
05 апр 2023, 11:32
feced1d
Код
Авторство
О чём код?
'use strict'; const { merge } = require('lodash/fp'); const getDefaultState = () => ({ actions: [], models: [], fixtures: {} }); const createContext = (initialState) => { let state; const contextApi = { get state() { return state; }, addAction(action) { state.actions.push(action); return this; }, addModel(model) { state.models.push(model); return this; }, addFixtures(modelName, entries) { state.fixtures = merge(state.fixtures, { [modelName]: entries }); return this; }, resetState() { return this.setState({ ...getDefaultState(), ...initialState }); }, setState(newState) { state = newState; return this; }, }; return contextApi.resetState(); }; module.exports = { createContext };