2022-03-18 15:47:09 +03:00
|
|
|
const {agentProvider, fixtureManager, matchers} = require('../../utils/e2e-framework');
|
2023-01-17 14:56:29 +03:00
|
|
|
const {anyContentVersion, anyEtag, anyErrorId, stringMatching, anyISODateTime} = matchers;
|
2022-03-18 15:47:09 +03:00
|
|
|
|
|
|
|
describe('Sessions API', function () {
|
|
|
|
let agent;
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
agent = await agentProvider.getAdminAPIAgent();
|
|
|
|
await fixtureManager.init();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can create session (log in)', async function () {
|
|
|
|
const owner = await fixtureManager.get('users', 0);
|
|
|
|
await agent
|
|
|
|
.post('session/')
|
|
|
|
.body({
|
|
|
|
grant_type: 'password',
|
|
|
|
username: owner.email,
|
|
|
|
password: owner.password
|
|
|
|
})
|
|
|
|
.expectStatus(201)
|
2022-03-31 20:55:46 +03:00
|
|
|
.expectEmptyBody()
|
2022-03-18 15:47:09 +03:00
|
|
|
.matchHeaderSnapshot({
|
2023-01-17 14:56:29 +03:00
|
|
|
'content-version': anyContentVersion,
|
2022-05-01 13:34:33 +03:00
|
|
|
etag: anyEtag,
|
2022-03-18 15:47:09 +03:00
|
|
|
'set-cookie': [
|
|
|
|
stringMatching(/^ghost-admin-api-session=/)
|
|
|
|
]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can read session now the owner is logged in', async function () {
|
|
|
|
await agent
|
|
|
|
.get('session/')
|
|
|
|
.expectStatus(200)
|
|
|
|
.matchBodySnapshot({
|
|
|
|
// id is 1, but should be anyObjectID :(
|
|
|
|
last_seen: anyISODateTime,
|
|
|
|
created_at: anyISODateTime,
|
|
|
|
updated_at: anyISODateTime
|
|
|
|
})
|
|
|
|
.matchHeaderSnapshot({
|
2023-01-17 14:56:29 +03:00
|
|
|
'content-version': anyContentVersion,
|
2022-05-01 13:34:33 +03:00
|
|
|
etag: anyEtag
|
2022-03-18 15:47:09 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('can delete session (log out)', async function () {
|
|
|
|
await agent
|
|
|
|
.delete('session/')
|
|
|
|
.expectStatus(204)
|
2022-03-31 20:55:46 +03:00
|
|
|
.expectEmptyBody()
|
2022-03-18 15:47:09 +03:00
|
|
|
.matchHeaderSnapshot({
|
2023-01-17 14:56:29 +03:00
|
|
|
'content-version': anyContentVersion,
|
2022-05-01 13:34:33 +03:00
|
|
|
etag: anyEtag
|
2022-03-18 15:47:09 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('errors when reading session again now owner is not logged in', async function () {
|
|
|
|
await agent
|
|
|
|
.get('session/')
|
|
|
|
.expectStatus(403)
|
|
|
|
.matchBodySnapshot({
|
|
|
|
errors: [{
|
|
|
|
id: anyErrorId
|
|
|
|
}]
|
|
|
|
})
|
|
|
|
.matchHeaderSnapshot({
|
2023-01-17 14:56:29 +03:00
|
|
|
'content-version': anyContentVersion,
|
2022-05-01 13:34:33 +03:00
|
|
|
etag: anyEtag
|
2022-03-18 15:47:09 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|