@coorpacademy/progression-engine
Version:
85 lines (84 loc) • 2.39 kB
JavaScript
;
var _set2 = _interopRequireDefault(require("lodash/fp/set"));
var _pipe2 = _interopRequireDefault(require("lodash/fp/pipe"));
var _ava = _interopRequireDefault(require("ava"));
var _applyInstructions = _interopRequireDefault(require("../apply-instructions"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
(0, _ava.default)('should return new variables with instructions to set initial attributes', t => {
const instructions = [{
value: 0,
type: 'set',
field: 'A'
}, {
value: 3,
type: 'set',
field: 'lives'
}, {
value: 0,
type: 'set',
field: 'stars'
}, {
value: false,
type: 'set',
field: 'reverse'
}];
const expectedVariables = (0, _pipe2.default)((0, _set2.default)('lives', 3), (0, _set2.default)('stars', 0), (0, _set2.default)('variables.A', 0), (0, _set2.default)('variables.reverse', false))({
variables: {}
});
const variables = (0, _applyInstructions.default)(instructions)({});
t.deepEqual(expectedVariables, variables);
});
(0, _ava.default)('should return new variables with instructions to update attributes', t => {
const instructions = [{
value: 1,
type: 'add',
field: 'A'
}, {
value: 4,
type: 'add',
field: 'stars'
}, {
value: 'foo',
type: 'add',
field: 'B'
}, {
value: 'baz',
type: 'add',
field: 'C'
}];
const fromState = {
lives: 4,
stars: 4,
variables: {
A: 0,
B: 0,
C: 'bar',
reverse: false
}
};
const expectedVariables = (0, _pipe2.default)((0, _set2.default)('stars', 8), (0, _set2.default)('variables.A', 1), (0, _set2.default)('variables.B', 0), (0, _set2.default)('variables.C', 'barbaz'))(fromState);
const variables = (0, _applyInstructions.default)(instructions)(fromState);
t.deepEqual(expectedVariables, variables);
});
(0, _ava.default)('should return the same input when instructions type are not recognized', t => {
const instructions = [{
value: 1,
type: 'foo',
field: 'A'
}, {
value: 4,
type: 'bar',
field: 'stars'
}];
const fromState = {
lives: 4,
stars: 4,
variables: {
A: 0,
reverse: false
}
};
const variables = (0, _applyInstructions.default)(instructions)(fromState);
t.deepEqual(fromState, variables);
});
//# sourceMappingURL=apply-instructions.js.map