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

How to stub liana.ensureAuthenticated? #219

Open
neokaiyuan opened this issue Dec 13, 2018 · 2 comments
Open

How to stub liana.ensureAuthenticated? #219

neokaiyuan opened this issue Dec 13, 2018 · 2 comments
Labels

Comments

@neokaiyuan
Copy link

Expected behavior

sinon.stub(liana, 'ensureAuthenticated') should stub the ensureAuthenticated

Actual behavior

stub does not address liana 'ensureAuthenticated', and code in forest-express-sequelize and forest-express seem to obscure how ensureAuthenticated is exposed

Context

I use liana.ensureAuthenticated as a middleware as suggested by Forest docs https://doc.forestadmin.com/developer-guide/express-sequelize.html#uploading-images and am hoping to unit test my controller.

@neokaiyuan neokaiyuan changed the title How to mock liana.ensureAuthenticated? How to stub liana.ensureAuthenticated? Dec 13, 2018
@neokaiyuan
Copy link
Author

seems to be a broader issue with stubbing express app middleware before app gets loaded.

https://stackoverflow.com/questions/41995464/how-to-mock-middleware-in-express-to-skip-authentication-for-unit-test
https://stackoverflow.com/questions/41392497/node-express-es6-sinon-stubbing-middleware-not-working
sinonjs/sinon#1711

ended up resolving this by not including ensureAuthenticated middleware in test env, as bad as it is to include test-specific logic in production code.

@polaroi8d
Copy link

seems to be a broader issue with stubbing express app middleware before app gets loaded.

https://stackoverflow.com/questions/41995464/how-to-mock-middleware-in-express-to-skip-authentication-for-unit-test
https://stackoverflow.com/questions/41392497/node-express-es6-sinon-stubbing-middleware-not-working
sinonjs/sinon#1711

ended up resolving this by not including ensureAuthenticated middleware in test env, as bad as it is to include test-specific logic in production code.

Could you provide your working example?

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

No branches or pull requests

3 participants