mirror of
https://github.com/wassname/talk.git
synced 2026-07-28 11:27:05 +08:00
Adds agent to persist session in tests.
This commit is contained in:
@@ -70,15 +70,9 @@ app.use(session(session_opts));
|
||||
// CSRF MIDDLEWARE
|
||||
//==============================================================================
|
||||
|
||||
// Use CSRF only if we are not testing.
|
||||
if (app.get('env') !== 'test') {
|
||||
console.log('DEBUGT NO TEST');
|
||||
app.use(cookieParser());
|
||||
}
|
||||
app.use(cookieParser());
|
||||
|
||||
app.use((err, req, res, next) => {
|
||||
console.log('DEBUG EN SERVER', req.csrfToken());
|
||||
|
||||
res.locals._csrf = req.csrfToken();
|
||||
return next();
|
||||
});
|
||||
|
||||
@@ -4,6 +4,8 @@ const expect = chai.expect;
|
||||
|
||||
chai.use(require('chai-http'));
|
||||
|
||||
const agent = chai.request.agent(app);
|
||||
|
||||
const User = require('../../../../models/user');
|
||||
|
||||
describe('/api/v1/auth', () => {
|
||||
@@ -12,8 +14,8 @@ describe('/api/v1/auth', () => {
|
||||
return chai.request(app)
|
||||
.get('/api/v1/auth')
|
||||
.then((res) => {
|
||||
expect(res.status).to.be.equal(204);
|
||||
expect(res.body).to.be.empty;
|
||||
expect(res.status).to.be.equal(200);
|
||||
expect(res.body).to.have.property('csrfToken');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -27,14 +29,20 @@ describe('/api/v1/auth/local', () => {
|
||||
|
||||
describe('#post', () => {
|
||||
it('should send back the user on a successful login', () => {
|
||||
return chai.request(app)
|
||||
.post('/api/v1/auth/local')
|
||||
.send({email: 'maria@gmail.com', password: 'password!'})
|
||||
.catch((res) => {
|
||||
expect(res).to.have.status(200);
|
||||
expect(res).to.be.json;
|
||||
expect(res.body).to.have.property('user');
|
||||
expect(res.body.user).to.have.property('displayName', 'Maria');
|
||||
|
||||
agent
|
||||
.get('/api/v1/auth')
|
||||
.then((res) => {
|
||||
expect(res.status).to.be.equal(200);
|
||||
expect(res.body).to.have.property('csrfToken');
|
||||
return agent.post('/api/v1/auth/local')
|
||||
.send({email: 'maria@gmail.com', password: 'password!', csrfToken: res.body.csrfToken})
|
||||
.catch((res2) => {
|
||||
expect(res2).to.have.status(200);
|
||||
expect(res2).to.be.json;
|
||||
expect(res2.body).to.have.property('user');
|
||||
expect(res2.body.user).to.have.property('displayName', 'Maria');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user