-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import chaiHttp from 'chai-http'; | ||
import chai, { expect } from 'chai'; | ||
import app from '../../app'; | ||
import { loggedInToken, createUsers } from '../fixtures/users.fixture'; | ||
|
||
chai.use(chaiHttp); | ||
describe('Tests for user logout', () => { | ||
before(async () => { | ||
await createUsers(); | ||
}); | ||
it('Should logout a user', (done) => { | ||
chai.request(app) | ||
.post('/api/auth/logout') | ||
.set('Authorization', loggedInToken) | ||
.end((error, response) => { | ||
expect(response).to.have.status(200); | ||
expect(response.body).to.have.property('message') | ||
.that.contain('Successful logout'); | ||
done(error); | ||
}); | ||
}); | ||
it('Should not allow access to protected route after log out', (done) => { | ||
chai.request(app) | ||
.get('/api/auth/protected') | ||
.set('Authorization', loggedInToken) | ||
.end((err, res) => { | ||
expect(res).to.have.status(401); | ||
expect(res.body).to.be.an('object'); | ||
expect(res.body).to.have.property('message') | ||
.that.contain('Unauthorized access. Invalid token for this user'); | ||
done(err); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters