2022-04-22 05:38:22 +03:00
|
|
|
const {agentProvider, fixtureManager, matchers, mockManager} = require('../../utils/e2e-framework');
|
2022-05-01 13:34:33 +03:00
|
|
|
const {anyErrorId, stringMatching, anyEtag} = matchers;
|
2022-04-06 11:12:20 +03:00
|
|
|
|
|
|
|
describe('API Versioning', function () {
|
2022-04-08 12:30:10 +03:00
|
|
|
describe('Admin API', function () {
|
|
|
|
let agentAdminAPI;
|
2022-04-06 11:12:20 +03:00
|
|
|
|
2022-04-08 12:30:10 +03:00
|
|
|
before(async function () {
|
|
|
|
agentAdminAPI = await agentProvider.getAdminAPIAgent();
|
2022-04-13 07:53:49 +03:00
|
|
|
await fixtureManager.init();
|
|
|
|
await agentAdminAPI.loginAsOwner();
|
2022-04-08 12:30:10 +03:00
|
|
|
});
|
2022-04-06 11:12:20 +03:00
|
|
|
|
2022-04-22 05:38:22 +03:00
|
|
|
beforeEach(function () {
|
|
|
|
mockManager.mockMail();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
mockManager.restore();
|
|
|
|
});
|
|
|
|
|
2022-04-08 12:30:10 +03:00
|
|
|
it('responds with no content version header when accept version header is NOT PRESENT', async function () {
|
|
|
|
await agentAdminAPI
|
|
|
|
.get('site/')
|
2022-04-21 07:45:21 +03:00
|
|
|
.expectStatus(200)
|
2022-04-08 12:30:10 +03:00
|
|
|
.matchBodySnapshot({
|
|
|
|
site: {
|
|
|
|
version: stringMatching(/\d+\.\d+/)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.matchHeaderSnapshot({
|
2022-05-01 13:34:33 +03:00
|
|
|
etag: anyEtag
|
2022-04-08 12:30:10 +03:00
|
|
|
});
|
|
|
|
});
|
2022-04-06 11:12:20 +03:00
|
|
|
|
2022-04-08 12:30:10 +03:00
|
|
|
it('responds with current content version header when requested version is BEHIND current version and CAN respond', async function () {
|
|
|
|
await agentAdminAPI
|
|
|
|
.get('site/')
|
|
|
|
.header('Accept-Version', 'v3.0')
|
2022-04-21 07:45:21 +03:00
|
|
|
.expectStatus(200)
|
2022-04-08 12:30:10 +03:00
|
|
|
.matchBodySnapshot({
|
|
|
|
site: {
|
|
|
|
version: stringMatching(/\d+\.\d+/)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.matchHeaderSnapshot({
|
2022-05-01 13:34:33 +03:00
|
|
|
etag: anyEtag,
|
2022-04-08 12:30:10 +03:00
|
|
|
'content-version': stringMatching(/v\d+\.\d+/)
|
|
|
|
});
|
|
|
|
});
|
2022-04-08 09:56:53 +03:00
|
|
|
|
2022-04-08 12:30:10 +03:00
|
|
|
it('responds with current content version header when requested version is AHEAD and CAN respond', async function () {
|
|
|
|
await agentAdminAPI
|
|
|
|
.get('site/')
|
|
|
|
.header('Accept-Version', 'v999.5')
|
2022-04-21 07:45:21 +03:00
|
|
|
.expectStatus(200)
|
2022-04-08 12:30:10 +03:00
|
|
|
.matchBodySnapshot({
|
|
|
|
site: {
|
|
|
|
version: stringMatching(/\d+\.\d+/)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.matchHeaderSnapshot({
|
2022-05-01 13:34:33 +03:00
|
|
|
etag: anyEtag,
|
2022-04-08 12:30:10 +03:00
|
|
|
'content-version': stringMatching(/v\d+\.\d+/)
|
|
|
|
});
|
|
|
|
});
|
2022-04-08 09:56:53 +03:00
|
|
|
|
2022-04-18 05:35:29 +03:00
|
|
|
it('responds with error requested version is AHEAD and CANNOT respond', async function () {
|
2022-04-08 12:30:10 +03:00
|
|
|
// CASE 2: If accept-version is behind, send a 406 & tell them the client needs updating.
|
|
|
|
await agentAdminAPI
|
|
|
|
.get('removed_endpoint')
|
|
|
|
.header('Accept-Version', 'v999.1')
|
2022-04-21 07:45:21 +03:00
|
|
|
.expectStatus(406)
|
2022-04-08 12:30:10 +03:00
|
|
|
.matchHeaderSnapshot({
|
2022-05-02 19:01:54 +03:00
|
|
|
etag: anyEtag,
|
|
|
|
'content-version': stringMatching(/v\d+\.\d+/)
|
2022-04-08 12:30:10 +03:00
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
|
|
|
errors: [{
|
2022-04-18 05:35:29 +03:00
|
|
|
context: stringMatching(/Provided client version v999\.1 is ahead of current Ghost instance version v\d+\.\d+/),
|
2022-04-08 12:30:10 +03:00
|
|
|
id: anyErrorId
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-04-18 05:35:29 +03:00
|
|
|
it('responds with error when requested version is BEHIND and CANNOT respond', async function () {
|
2022-04-08 12:30:10 +03:00
|
|
|
// CASE 2: If accept-version is behind, send a 406 & tell them the client needs updating.
|
|
|
|
await agentAdminAPI
|
|
|
|
.get('removed_endpoint')
|
|
|
|
.header('Accept-Version', 'v3.1')
|
2022-04-22 05:38:22 +03:00
|
|
|
.header('User-Agent', 'Zapier 1.3')
|
2022-04-21 07:45:21 +03:00
|
|
|
.expectStatus(406)
|
2022-04-08 12:30:10 +03:00
|
|
|
.matchHeaderSnapshot({
|
2022-05-02 19:01:54 +03:00
|
|
|
etag: anyEtag,
|
|
|
|
'content-version': stringMatching(/v\d+\.\d+/)
|
2022-04-08 12:30:10 +03:00
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
|
|
|
errors: [{
|
2022-04-18 05:35:29 +03:00
|
|
|
context: stringMatching(/Provided client version v3.1 is outdated and is behind current Ghost version v\d+\.\d+/),
|
2022-04-08 12:30:10 +03:00
|
|
|
id: anyErrorId
|
|
|
|
}]
|
|
|
|
});
|
2022-04-22 05:38:22 +03:00
|
|
|
|
2022-05-03 10:45:23 +03:00
|
|
|
mockManager.assert.sentEmailCount(1);
|
|
|
|
mockManager.assert.sentEmail({
|
|
|
|
subject: 'Attention required: Your Zapier 1.3 integration has failed',
|
|
|
|
to: 'jbloggs@example.com'
|
|
|
|
});
|
2022-04-22 05:38:22 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('responds with error and sends email ONCE when requested version is BEHIND and CANNOT respond multiple times', async function () {
|
|
|
|
await agentAdminAPI
|
|
|
|
.get('removed_endpoint')
|
|
|
|
.header('Accept-Version', 'v3.5')
|
|
|
|
.header('User-Agent', 'Zapier 1.4')
|
|
|
|
.expectStatus(406)
|
|
|
|
.matchHeaderSnapshot({
|
2022-05-02 19:01:54 +03:00
|
|
|
etag: anyEtag,
|
|
|
|
'content-version': stringMatching(/v\d+\.\d+/)
|
2022-04-22 05:38:22 +03:00
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
|
|
|
errors: [{
|
|
|
|
context: stringMatching(/Provided client version v3.5 is outdated and is behind current Ghost version v\d+\.\d+/),
|
|
|
|
id: anyErrorId
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
2022-05-03 10:45:23 +03:00
|
|
|
mockManager.assert.sentEmailCount(1);
|
|
|
|
mockManager.assert.sentEmail({
|
|
|
|
subject: 'Attention required: Your Zapier 1.4 integration has failed',
|
|
|
|
to: 'jbloggs@example.com'
|
|
|
|
});
|
2022-04-22 05:38:22 +03:00
|
|
|
|
|
|
|
await agentAdminAPI
|
|
|
|
.get('removed_endpoint')
|
|
|
|
.header('Accept-Version', 'v3.5')
|
|
|
|
.header('User-Agent', 'Zapier 1.4')
|
|
|
|
.expectStatus(406)
|
|
|
|
.matchHeaderSnapshot({
|
2022-05-02 19:01:54 +03:00
|
|
|
etag: anyEtag,
|
|
|
|
'content-version': stringMatching(/v\d+\.\d+/)
|
2022-04-22 05:38:22 +03:00
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
|
|
|
errors: [{
|
|
|
|
context: stringMatching(/Provided client version v3.5 is outdated and is behind current Ghost version v\d+\.\d+/),
|
|
|
|
id: anyErrorId
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
|
2022-05-03 10:45:23 +03:00
|
|
|
mockManager.assert.sentEmailCount(1);
|
2022-04-08 12:30:10 +03:00
|
|
|
});
|
2022-04-13 07:53:49 +03:00
|
|
|
|
|
|
|
it('responds with 404 error when the resource cannot be found', async function () {
|
|
|
|
await agentAdminAPI
|
|
|
|
.get('/members/member_does_not_exist@example.com')
|
|
|
|
.header('Accept-Version', 'v4.1')
|
2022-04-21 07:45:21 +03:00
|
|
|
.expectStatus(404)
|
2022-04-13 07:53:49 +03:00
|
|
|
.matchHeaderSnapshot({
|
2022-05-02 19:01:54 +03:00
|
|
|
etag: anyEtag,
|
|
|
|
'content-version': stringMatching(/v\d+\.\d+/)
|
2022-04-13 07:53:49 +03:00
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
|
|
|
errors: [{
|
|
|
|
id: anyErrorId
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
});
|
2022-04-21 11:47:45 +03:00
|
|
|
|
|
|
|
it('307 redirects GET with accept version set when version is included in the URL', async function () {
|
|
|
|
await agentAdminAPI
|
|
|
|
.get('/site/', {baseUrl: '/ghost/api/canary/admin/'})
|
|
|
|
.expectStatus(307)
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
location: stringMatching(/^\/ghost\/api\/admin\/site\/$/)
|
|
|
|
})
|
|
|
|
.expectEmptyBody();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('307 redirects POST with accept version set when version is included in the URL', async function () {
|
|
|
|
await agentAdminAPI
|
|
|
|
.post('/session/', {baseUrl: '/ghost/api/v3/admin/'})
|
|
|
|
.expectStatus(307)
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
location: stringMatching(/^\/ghost\/api\/admin\/session\/$/)
|
|
|
|
})
|
|
|
|
.expectEmptyBody();
|
|
|
|
});
|
2022-05-02 18:00:15 +03:00
|
|
|
|
|
|
|
it('responds with 406 for an unknown version with accept-version set ahead', async function () {
|
|
|
|
await agentAdminAPI
|
|
|
|
.get('/site/', {baseUrl: '/ghost/api/v99/admin/'})
|
|
|
|
.header('Accept-Version', 'v99.0')
|
|
|
|
.expectStatus(406)
|
|
|
|
.matchHeaderSnapshot({
|
2022-05-02 19:01:54 +03:00
|
|
|
etag: anyEtag,
|
|
|
|
'content-version': stringMatching(/v\d+\.\d+/)
|
2022-05-02 18:00:15 +03:00
|
|
|
})
|
|
|
|
.matchBodySnapshot({errors: [{
|
|
|
|
context: stringMatching(/Provided client version v99\.0 is ahead of current Ghost instance version v\d+\.\d+/),
|
|
|
|
id: anyErrorId
|
|
|
|
}]});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('responds with 406 for an unknown version with accept-version set behind', async function () {
|
|
|
|
await agentAdminAPI
|
|
|
|
.get('/site/', {baseUrl: '/ghost/api/v1/admin/'})
|
|
|
|
.header('Accept-Version', 'v1.0')
|
|
|
|
.expectStatus(406)
|
|
|
|
.matchHeaderSnapshot({
|
2022-05-02 19:01:54 +03:00
|
|
|
etag: anyEtag,
|
|
|
|
'content-version': stringMatching(/v\d+\.\d+/)
|
2022-05-02 18:00:15 +03:00
|
|
|
})
|
|
|
|
.matchBodySnapshot({errors: [{
|
|
|
|
context: stringMatching(/Provided client version v1\.0 is outdated and is behind current Ghost version v\d+\.\d+/),
|
|
|
|
id: anyErrorId
|
|
|
|
}]});
|
|
|
|
});
|
2022-04-08 09:56:53 +03:00
|
|
|
});
|
|
|
|
|
2022-04-08 12:30:10 +03:00
|
|
|
describe('Content API', function () {
|
|
|
|
let agentContentAPI;
|
|
|
|
|
|
|
|
before(async function () {
|
|
|
|
agentContentAPI = await agentProvider.getContentAPIAgent();
|
|
|
|
await fixtureManager.init('api_keys');
|
|
|
|
agentContentAPI.authenticate();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('responds with no content version header when accept version header is NOT PRESENT', async function () {
|
|
|
|
await agentContentAPI.get('settings/')
|
|
|
|
.expectStatus(200)
|
|
|
|
.matchHeaderSnapshot()
|
|
|
|
.matchBodySnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('responds with current content version header when requested version is BEHIND current version and CAN respond', async function () {
|
|
|
|
await agentContentAPI.get('settings/')
|
|
|
|
.header('Accept-Version', 'v3.0')
|
|
|
|
.expectStatus(200)
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
'content-version': stringMatching(/v\d+\.\d+/)
|
|
|
|
})
|
|
|
|
.matchBodySnapshot();
|
|
|
|
});
|
2022-04-21 11:47:45 +03:00
|
|
|
|
|
|
|
it('307 redirects with accept version set when version is included in the URL', async function () {
|
|
|
|
await agentContentAPI
|
|
|
|
.get('/posts/', {baseUrl: '/ghost/api/canary/content/'})
|
|
|
|
.expectStatus(307)
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
location: stringMatching(/^\/ghost\/api\/content\/posts\//)
|
|
|
|
})
|
|
|
|
.expectEmptyBody();
|
|
|
|
});
|
2022-04-08 09:56:53 +03:00
|
|
|
});
|
2022-04-06 11:12:20 +03:00
|
|
|
});
|