UNPKG

@paralleldrive/feature-toggles

Version:

Low-level feature toggle tools for Node and browsers.

142 lines (117 loc) 4.72 kB
'use strict'; var _riteway = require('riteway'); var _deepFreeze = require('deep-freeze'); var _deepFreeze2 = _interopRequireDefault(_deepFreeze); var _getCurrentActiveFeatureNames = require('./get-current-active-feature-names'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; } var makeFeatures = function makeFeatures() { return (0, _deepFreeze2.default)([{ name: 'foo', isActive: true }, { name: 'bar', isActive: true }, { name: 'baz', isActive: false }, { name: 'baz-dependent', isActive: false, dependencies: ['baz'] }, { name: 'other', isActive: false }]); }; (0, _riteway.describe)('getCurrentActiveFeatureNames()', function () { var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(should) { var _should, assert, req, _req, search, _search; return regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _should = should(), assert = _should.assert; assert({ given: 'no arguments', should: 'return an empty array', actual: (0, _getCurrentActiveFeatureNames.getCurrentActiveFeatureNames)(), expected: [] }); assert({ given: 'an empty object', should: 'return an empty array', actual: (0, _getCurrentActiveFeatureNames.getCurrentActiveFeatureNames)({}), expected: [] }); assert({ given: 'an empty initial features', should: 'return an empty array', actual: (0, _getCurrentActiveFeatureNames.getCurrentActiveFeatureNames)({ initialFeatures: [] }), expected: [] }); assert({ given: 'initial features', should: 'return the correct features', actual: (0, _getCurrentActiveFeatureNames.getCurrentActiveFeatureNames)({ initialFeatures: makeFeatures() }), expected: ['foo', 'bar'] }); req = (0, _deepFreeze2.default)({ query: { ft: 'baz,other' } }); assert({ given: 'initial features and req', should: 'return the correct features', actual: (0, _getCurrentActiveFeatureNames.getCurrentActiveFeatureNames)({ initialFeatures: makeFeatures(), req: req }), expected: ['foo', 'bar', 'baz', 'other'] }); _req = (0, _deepFreeze2.default)({ query: { ft: 'baz-dependent' } }); assert({ given: 'initial features and req', should: 'respect dependencies and enable the correct features', actual: (0, _getCurrentActiveFeatureNames.getCurrentActiveFeatureNames)({ initialFeatures: makeFeatures(), req: _req }), expected: ['foo', 'bar'] }); search = '?ft=baz,other'; assert({ given: 'initial features and search', should: 'return the correct features', actual: (0, _getCurrentActiveFeatureNames.getCurrentActiveFeatureNames)({ initialFeatures: makeFeatures(), search: search }), expected: ['foo', 'bar', 'baz', 'other'] }); _search = '?ft=baz-dependent'; assert({ given: 'initial features and search', should: 'respect dependencies and enable the correct features', actual: (0, _getCurrentActiveFeatureNames.getCurrentActiveFeatureNames)({ initialFeatures: makeFeatures(), search: _search }), expected: ['foo', 'bar'] }); case 13: case 'end': return _context.stop(); } } }, _callee, undefined); })); return function (_x) { return _ref.apply(this, arguments); }; }());