Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
moefinley opened this issue Feb 8, 2019 · 1 comment

Comments

@moefinley
Copy link

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
Copy link
Owner

mdasberg commented Mar 5, 2019

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants