How to do test passport social login?
Facebook delegates login instead of me. I just needed to set passport stuffs in my application code.
If I set passport code in my app, and If I send request 'login', Facebook does work. like redirecting to login page, validating Id/Password input, and showing result page etc. these processes is not in my application code.
so I didn't know what to do for testing passport.js.
[THINGS I TRIED] : "zombie.js" -> "MockStrategy" -> "nock"
At first, I saw "zombie.js". [Result : This is not fit for testing passport-facebook]
It tests like real web browser. It can redirect, fill id/password , and click submit buttons.
const Browser = require('zombie');
// We're going to make requests to http://example.com/signup
// Which will be routed to our test server localhost:3000
Browser.localhost('example.com', 3000);
describe('User visits signup page', function() {
const browser = new Browser();
before(function(done) {
browser.visit('/signup', done);
});
describe('submits form', function() {
before(function(done) {
browser
.fill('email', 'zombie@underworld.dead')
.fill('password', 'eat-the-living')
.pressButton('Sign Me Up!', done);
});
it('should be successful', function() {
browser.assert.success();
});
it('should see welcome page', function() {
browser.assert.text('title', 'Welcome To Brains Depot');
});
});
});
It Looks usefull. but I couldnt use it properly. so I stoped to using this for test.
One days is gone by studying "zombie.js"
Next I found "MockStrategy". [Result : It looks good but I coudlnt use well]
Someone made MockStrategy for test.
const MockStrategy = require('passport-mock-strategy');
...
passport.use(new MockStrategy());
I tried but I couldn't understand how to use it. and there is not much examples.
so another day was gone with MockStrategy.
Next I found "nock" and "sinon".[Result : These are most famous and easy to Use!]
These were most famous test tools. How I could not recognize these two tools for a long time?
I guess I dont wantted to learn new stuff at that time. I was too laaazy..
It is time to select between "nock" and "sinon" and study one.
I stuck in passport TDD. wow...
I couldnt get process with this...
stop this for a while.. need time..
'express' 카테고리의 다른 글
passport-facebook with JWT [Express] (0) | 2020.07.03 |
---|---|
body-parser[Middleware] (0) | 2020.07.03 |
How to show joined models [mongoose] (0) | 2020.05.21 |
Permission check on user's actions [Express, Node] (0) | 2020.05.21 |
When we forgot password/ using registered email. [Express, Node] (0) | 2020.05.21 |