mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-19 00:11:49 +03:00
9ba251238a
refs https://github.com/TryGhost/Team/issues/2400 - we've deemed it useful to start to return `Content-Version` for all API requests, because it becomes useful to know which version of Ghost a response has come from in logs - this should also help us detect Admin<->Ghost API mismatches, which was the cause of a bug recently (ref'd issue)
74 lines
2.3 KiB
JavaScript
74 lines
2.3 KiB
JavaScript
const {agentProvider, fixtureManager, matchers} = require('../../utils/e2e-framework');
|
|
const {anyContentVersion, anyEtag, anyErrorId, stringMatching, anyISODateTime} = matchers;
|
|
|
|
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)
|
|
.expectEmptyBody()
|
|
.matchHeaderSnapshot({
|
|
'content-version': anyContentVersion,
|
|
etag: anyEtag,
|
|
'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({
|
|
'content-version': anyContentVersion,
|
|
etag: anyEtag
|
|
});
|
|
});
|
|
|
|
it('can delete session (log out)', async function () {
|
|
await agent
|
|
.delete('session/')
|
|
.expectStatus(204)
|
|
.expectEmptyBody()
|
|
.matchHeaderSnapshot({
|
|
'content-version': anyContentVersion,
|
|
etag: anyEtag
|
|
});
|
|
});
|
|
|
|
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({
|
|
'content-version': anyContentVersion,
|
|
etag: anyEtag
|
|
});
|
|
});
|
|
});
|