-
Notifications
You must be signed in to change notification settings - Fork 2
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
3 changed files
with
30 additions
and
3 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,10 +9,37 @@ describe('/api/v1/auth', () => { | |
it('should return not found for email that is not registered', async (t) => { | ||
const app = await build(t); | ||
const response = await app.inject().post('/api/v1/auth/login').payload({ | ||
email: 'not.found@gmail.com', | ||
email: 'not.found@test.com', | ||
password: 'test', | ||
}); | ||
assert.deepStrictEqual(response.statusCode, StatusCodes.NOT_FOUND); | ||
}); | ||
|
||
it('should return unauthorized for invalid password', async (t) => { | ||
const app = await build(t); | ||
await t.loadFixtures(); | ||
const response = await app.inject().post('/api/v1/auth/login').payload({ | ||
email: '[email protected]', | ||
password: 'invalid', | ||
}); | ||
assert.deepStrictEqual(response.statusCode, StatusCodes.UNAUTHORIZED); | ||
}); | ||
|
||
it('should return ok and a secure session cookie for valid credentials', async (t) => { | ||
const app = await build(t); | ||
await t.loadFixtures(); | ||
const response = await app.inject().post('/api/v1/auth/login').payload({ | ||
email: '[email protected]', | ||
password: 'test', | ||
}); | ||
assert.deepStrictEqual(response.statusCode, StatusCodes.OK); | ||
const cookie = response.headers['set-cookie'] | ||
?.split(';') | ||
.map((t) => t.trim()); | ||
assert.ok(cookie[0].startsWith('session=')); | ||
assert.ok(cookie.includes('HttpOnly')); | ||
assert.ok(cookie.includes('Secure')); | ||
assert.ok(cookie.includes('SameSite=Strict')); | ||
}); | ||
}); | ||
}); |