2022-04-08 12:30:10 +03:00
|
|
|
const {agentProvider, fixtureManager, matchers} = require('../../utils/e2e-framework');
|
2022-04-08 09:56:53 +03:00
|
|
|
const {anyErrorId, anyString, stringMatching} = 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-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/')
|
|
|
|
.matchBodySnapshot({
|
|
|
|
site: {
|
|
|
|
version: stringMatching(/\d+\.\d+/)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyString
|
|
|
|
});
|
|
|
|
});
|
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')
|
|
|
|
.matchBodySnapshot({
|
|
|
|
site: {
|
|
|
|
version: stringMatching(/\d+\.\d+/)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyString,
|
|
|
|
'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')
|
|
|
|
.matchBodySnapshot({
|
|
|
|
site: {
|
|
|
|
version: stringMatching(/\d+\.\d+/)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyString,
|
|
|
|
'content-version': stringMatching(/v\d+\.\d+/)
|
|
|
|
});
|
|
|
|
});
|
2022-04-08 09:56:53 +03:00
|
|
|
|
2022-04-12 12:03:16 +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')
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyString
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
|
|
|
errors: [{
|
|
|
|
id: anyErrorId
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-04-12 12:03:16 +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')
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyString
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
|
|
|
errors: [{
|
|
|
|
id: anyErrorId
|
|
|
|
}]
|
|
|
|
});
|
|
|
|
});
|
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')
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyString
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
|
|
|
errors: [{
|
|
|
|
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-08 09:56:53 +03:00
|
|
|
});
|
2022-04-06 11:12:20 +03:00
|
|
|
});
|