Skip to content

Commit

Permalink
[B][T][login] add /isValidToken test
Browse files Browse the repository at this point in the history
  • Loading branch information
Fibii committed Sep 25, 2020
1 parent 5ebf3b8 commit 07226e8
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions backend/tests/login.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const app = require('../app')
const User = require('../models/user')

const api = superTest(app)
const agent = superTest.agent(app)

beforeEach(async () => {
await User.deleteMany({})
Expand Down Expand Up @@ -61,4 +62,28 @@ describe('auth', () => {

expect(response.body.error).toBe('invalid password')
})

test('user cookie can be verified', async () => {
const initialUsers = testHelper.getInitialUsers()
const user = {
username: initialUsers[0].username,
password: initialUsers[0].password,
}

await agent.post('/api/users')
.send(initialUsers[0])

const response = await agent
.post('/api/login')
.send(user)

const cookie = response
.headers['set-cookie'][0]
.split(',')
.map((item) => item.split(';')[0])
agent.jar.setCookie(cookie[0])

await agent.get('/api/login/isValidToken')
.expect(200)
})
})

0 comments on commit 07226e8

Please sign in to comment.