Skip to content

Commit

Permalink
fix!: made fixture generator work with ts
Browse files Browse the repository at this point in the history
  • Loading branch information
leartgjoni-voiceflow committed Jan 7, 2020
1 parent 5a482cc commit 85182a2
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions lib/fixtureGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ const sinon = require('sinon');

const _ = require('lodash');

const hasUserPrototype = (obj) => obj.constructor !== Object;

const createFixture = async (serviceManager) => {
const { middlewares, controllers } = serviceManager;

Expand All @@ -32,22 +30,13 @@ const createFixture = async (serviceManager) => {
controllers: Object.keys(controllers).reduce((result, key) => {
const target = controllers[key];

if (hasUserPrototype(target)) {
result[key] = Object.getOwnPropertyNames(Object.getPrototypeOf(target))
.filter((_key) => _key !== 'constructor')
.reduce((_result, _key) => {
_result[_key] = sinon.stub().callsFake(serviceFake);
return _result;
}, {});
} else {
result[key] = Object.keys(target).reduce((_result, _key) => {
const validations = _.mapValues(controllers[key][_key].validations, () => sinon.stub().callsArg(2));
const controllerStub = sinon.stub().callsFake(serviceFake);
controllerStub.validations = validations;
_result[_key] = [...Object.values(validations), controllerStub];
return _result;
}, {});
}
result[key] = Object.keys(target).reduce((_result, _key) => {
const validations = _.mapValues(controllers[key][_key].validations, () => sinon.stub().callsArg(2));
const controllerStub = sinon.stub().callsFake(serviceFake);
controllerStub.validations = validations;
_result[_key] = [...Object.values(validations), controllerStub];
return _result;
}, {});

return result;
}, {}),
Expand Down

0 comments on commit 85182a2

Please sign in to comment.