Return headers from login/registerAccount test methods
This commit is contained in:
parent
3739f27ebe
commit
4f533e7fff
@ -26,9 +26,7 @@ describe('/auth', () => {
|
|||||||
const t = test.request('/api')
|
const t = test.request('/api')
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const session = await test.registerAccount()
|
const session = await test.registerAccount()
|
||||||
const token = session.token
|
t.setHeaders(session.headers)
|
||||||
const cookie = session.cookie
|
|
||||||
t.setHeaders({cookie, 'x-csrf-token': token})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should prevent access when user not logged in', async () => {
|
it('should prevent access when user not logged in', async () => {
|
||||||
@ -64,7 +62,7 @@ describe('/auth', () => {
|
|||||||
let cookie!: string
|
let cookie!: string
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await test.registerAccount()
|
await test.registerAccount()
|
||||||
cookie = (await test.login()).cookie
|
cookie = (await test.login()).headers.cookie
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should log out the user', async () => {
|
it('should log out the user', async () => {
|
||||||
|
|||||||
@ -6,13 +6,11 @@ describe('user', () => {
|
|||||||
const t = test.request('/api')
|
const t = test.request('/api')
|
||||||
|
|
||||||
let cookie!: string
|
let cookie!: string
|
||||||
let token!: string
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await test.registerAccount()
|
await test.registerAccount()
|
||||||
const session = await test.login()
|
const session = await test.login()
|
||||||
cookie = session.cookie
|
cookie = session.headers.cookie
|
||||||
token = session.token
|
t.setHeaders(session.headers)
|
||||||
t.setHeaders({ cookie, 'x-csrf-token': token })
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('GET /users/profile', () => {
|
describe('GET /users/profile', () => {
|
||||||
|
|||||||
@ -5,15 +5,10 @@ describe('user', () => {
|
|||||||
|
|
||||||
test.withDatabase()
|
test.withDatabase()
|
||||||
|
|
||||||
let cookie!: string
|
|
||||||
let token!: string
|
|
||||||
let headers: Record<string, string> = {}
|
let headers: Record<string, string> = {}
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await test.registerAccount()
|
await test.registerAccount()
|
||||||
const session = await test.login()
|
headers = (await test.login()).headers
|
||||||
cookie = session.cookie
|
|
||||||
token = session.token
|
|
||||||
headers = {cookie, 'x-csrf-token': token}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const createService = () => {
|
const createService = () => {
|
||||||
|
|||||||
@ -6,15 +6,11 @@ describe('team', () => {
|
|||||||
test.withDatabase()
|
test.withDatabase()
|
||||||
const t = test.request('/api')
|
const t = test.request('/api')
|
||||||
|
|
||||||
let cookie!: string
|
|
||||||
let token!: string
|
|
||||||
let mainUserId: number
|
let mainUserId: number
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const session = await test.registerAccount()
|
const session = await test.registerAccount()
|
||||||
cookie = session.cookie
|
|
||||||
token = session.token
|
|
||||||
mainUserId = session.userId
|
mainUserId = session.userId
|
||||||
t.setHeaders({ cookie, 'x-csrf-token': token })
|
t.setHeaders(session.headers)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('POST /teams', () => {
|
describe('POST /teams', () => {
|
||||||
|
|||||||
@ -133,9 +133,11 @@ export class TestUtils<T extends IRoutes> {
|
|||||||
const cookies = this.getCookies(response.header['set-cookie'])
|
const cookies = this.getCookies(response.header['set-cookie'])
|
||||||
|
|
||||||
return {
|
return {
|
||||||
cookie: [cookies, cookie].join('; '),
|
headers: {
|
||||||
|
"cookie": [cookies, cookie].join('; '),
|
||||||
|
'x-csrf-token': token,
|
||||||
|
},
|
||||||
userId: response.body.id,
|
userId: response.body.id,
|
||||||
token,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,8 +154,10 @@ export class TestUtils<T extends IRoutes> {
|
|||||||
const cookies = this.getCookies(response.header['set-cookie'])
|
const cookies = this.getCookies(response.header['set-cookie'])
|
||||||
|
|
||||||
return {
|
return {
|
||||||
cookie: [cookies, cookie].join('; '),
|
headers: {
|
||||||
token,
|
"cookie": [cookies, cookie].join('; '),
|
||||||
|
'x-csrf-token': token,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user