mdasberg / ng-apimock

Node plugin that provides the ability to use scenario based api mocking: for local development for protractor testing
MIT License
99 stars 26 forks source link

Should I expect additional middleware to be called after a mock is found? #66

Open moefinley opened 5 years ago

moefinley commented 5 years ago

I want to use ng-apimock to mock using real a settings file with a single value modified for each scenario. This is so I don't have to create copies of all the settings I don't want to change in multiple mock JSON files. I was expecting to be able to use Express middleware to do this

let featureScenarioWriter = function (req, res, next) {
    console.log("The request:" + req);
    //check request is for the settings file
    //load the real settings file and modify the key\value matching what is in the response
    //set the response to be the whole settings file with a single value changed

    next();
};
app.set('port', 3000);
// process the api calls through ng-apimock
app.use(require('ng-apimock/lib/utils').ngApimockRequest);
// serve the mocking interface for local development
app.use('/mocking', express.static('./.tmp/ngApimock'));
app.use(featureScenarioWriter);

However no request ever reaches the featureScenarioWriter function. I presume this is because the response is ended by ngApimockRequest.

Should my custom middleware be called? Is there another way I could change one value in a file as part of a scenario?

mdasberg commented 5 years ago

@moefinley the ngapimock middleware does not go to the next middleware function unless you set your scenario to passthrough in apimock.

Do you want to set a variable that is used in your mocks? if so you can use the variable option in apimock