mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-04-15 03:01:37 -05:00
Required updated_at
for Admin API v2 when updating a post/page
refs #10438 - the `updated_at` functions as version control value - it is required for collision detection - we might redesign this feature at some point
This commit is contained in:
parent
f394eaa7b8
commit
0dd3aad2d0
5 changed files with 58 additions and 20 deletions
|
@ -11,7 +11,11 @@
|
|||
"type": "array",
|
||||
"minItems": 1,
|
||||
"maxItems": 1,
|
||||
"items": {"$ref": "posts#/definitions/post"}
|
||||
"items": {
|
||||
"type": "object",
|
||||
"allOf": [{"$ref": "posts#/definitions/post"}],
|
||||
"required": ["updated_at"]
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [ "posts" ]
|
||||
|
|
|
@ -22,6 +22,7 @@ describe('Actions API', function () {
|
|||
// @NOTE: This test runs a little slower, because we store Dates without milliseconds.
|
||||
it('Can request actions for resource', function () {
|
||||
let postId;
|
||||
let postUpdatedAt;
|
||||
|
||||
return request
|
||||
.post(localUtils.API.getApiQuery('posts/'))
|
||||
|
@ -36,6 +37,7 @@ describe('Actions API', function () {
|
|||
.expect(201)
|
||||
.then((res) => {
|
||||
postId = res.body.posts[0].id;
|
||||
postUpdatedAt = res.body.posts[0].updated_at;
|
||||
|
||||
return request
|
||||
.get(localUtils.API.getApiQuery(`actions/resource/${postId}/`))
|
||||
|
@ -67,14 +69,17 @@ describe('Actions API', function () {
|
|||
.set('Origin', config.get('url'))
|
||||
.send({
|
||||
posts: [{
|
||||
slug: 'new-slug'
|
||||
slug: 'new-slug',
|
||||
updated_at: postUpdatedAt
|
||||
}]
|
||||
})
|
||||
.expect('Content-Type', /json/)
|
||||
.expect('Cache-Control', testUtils.cacheRules.private)
|
||||
.expect(200);
|
||||
})
|
||||
.then(() => {
|
||||
.then((res) => {
|
||||
postUpdatedAt = res.body.posts[0].updated_at;
|
||||
|
||||
return request
|
||||
.get(localUtils.API.getApiQuery(`actions/resource/${postId}/`))
|
||||
.set('Origin', config.get('url'))
|
||||
|
@ -108,7 +113,8 @@ describe('Actions API', function () {
|
|||
.set('Authorization', `Ghost ${localUtils.getValidAdminToken(localUtils.API.getApiQuery(`posts/${postId}/`))}`)
|
||||
.send({
|
||||
posts: [{
|
||||
featured: true
|
||||
featured: true,
|
||||
updated_at: postUpdatedAt
|
||||
}]
|
||||
})
|
||||
.expect('Content-Type', /json/)
|
||||
|
|
|
@ -288,12 +288,20 @@ describe('Posts API', function () {
|
|||
title: 'update draft'
|
||||
};
|
||||
|
||||
return request.put(localUtils.API.getApiQuery('posts/' + testUtils.DataGenerator.Content.posts[3].id))
|
||||
return request
|
||||
.get(localUtils.API.getApiQuery(`posts/${testUtils.DataGenerator.Content.posts[3].id}/?status=all`))
|
||||
.set('Origin', config.get('url'))
|
||||
.send({posts: [post]})
|
||||
.expect('Content-Type', /json/)
|
||||
.expect('Cache-Control', testUtils.cacheRules.private)
|
||||
.expect(200)
|
||||
.then((res) => {
|
||||
post.updated_at = res.body.posts[0].updated_at;
|
||||
|
||||
return request.put(localUtils.API.getApiQuery('posts/' + testUtils.DataGenerator.Content.posts[3].id))
|
||||
.set('Origin', config.get('url'))
|
||||
.send({posts: [post]})
|
||||
.expect('Content-Type', /json/)
|
||||
.expect('Cache-Control', testUtils.cacheRules.private)
|
||||
.expect(200);
|
||||
})
|
||||
.then((res) => {
|
||||
res.headers['x-cache-invalidate'].should.eql('/p/' + res.body.posts[0].uuid + '/');
|
||||
});
|
||||
|
@ -305,12 +313,20 @@ describe('Posts API', function () {
|
|||
};
|
||||
|
||||
return request
|
||||
.put(localUtils.API.getApiQuery('posts/' + testUtils.DataGenerator.Content.posts[1].id + '/'))
|
||||
.get(localUtils.API.getApiQuery(`posts/${testUtils.DataGenerator.Content.posts[1].id}/?status=all`))
|
||||
.set('Origin', config.get('url'))
|
||||
.send({posts: [post]})
|
||||
.expect('Content-Type', /json/)
|
||||
.expect('Cache-Control', testUtils.cacheRules.private)
|
||||
.expect(200)
|
||||
.then((res) => {
|
||||
post.updated_at = res.body.posts[0].updated_at;
|
||||
|
||||
return request
|
||||
.put(localUtils.API.getApiQuery('posts/' + testUtils.DataGenerator.Content.posts[1].id + '/'))
|
||||
.set('Origin', config.get('url'))
|
||||
.send({posts: [post]})
|
||||
.expect('Content-Type', /json/)
|
||||
.expect('Cache-Control', testUtils.cacheRules.private)
|
||||
.expect(200);
|
||||
})
|
||||
.then((res) => {
|
||||
res.headers['x-cache-invalidate'].should.eql('/*');
|
||||
res.body.posts[0].status.should.eql('draft');
|
||||
|
|
|
@ -116,14 +116,23 @@ describe('Posts API', function () {
|
|||
describe('edit', function () {
|
||||
it('published_at = null', function () {
|
||||
return request
|
||||
.put(localUtils.API.getApiQuery('posts/' + testUtils.DataGenerator.Content.posts[0].id + '/'))
|
||||
.get(localUtils.API.getApiQuery(`posts/${testUtils.DataGenerator.Content.posts[0].id}/`))
|
||||
.set('Origin', config.get('url'))
|
||||
.send({
|
||||
posts: [{published_at: null}]
|
||||
})
|
||||
.expect('Content-Type', /json/)
|
||||
.expect('Cache-Control', testUtils.cacheRules.private)
|
||||
.expect(200)
|
||||
.then((res) => {
|
||||
return request
|
||||
.put(localUtils.API.getApiQuery('posts/' + testUtils.DataGenerator.Content.posts[0].id + '/'))
|
||||
.set('Origin', config.get('url'))
|
||||
.send({
|
||||
posts: [{
|
||||
published_at: null,
|
||||
updated_at: res.body.posts[0].updated_at
|
||||
}]
|
||||
})
|
||||
.expect('Content-Type', /json/)
|
||||
.expect('Cache-Control', testUtils.cacheRules.private)
|
||||
.expect(200);
|
||||
})
|
||||
.then((res) => {
|
||||
// @NOTE: you cannot modify published_at manually, that's why the resource won't change.
|
||||
should.not.exist(res.headers['x-cache-invalidate']);
|
||||
|
|
|
@ -301,7 +301,8 @@ describe('Unit: v2/utils/validators/input/posts', function () {
|
|||
options: {},
|
||||
data: {
|
||||
posts: [{
|
||||
title: 'pass'
|
||||
title: 'pass',
|
||||
updated_at: new Date().toISOString()
|
||||
}],
|
||||
}
|
||||
};
|
||||
|
@ -360,6 +361,7 @@ describe('Unit: v2/utils/validators/input/posts', function () {
|
|||
posts: [
|
||||
{
|
||||
title: 'cool',
|
||||
updated_at: new Date().toISOString(),
|
||||
authors: [{
|
||||
id: 'correct',
|
||||
name: 'ja'
|
||||
|
@ -378,7 +380,8 @@ describe('Unit: v2/utils/validators/input/posts', function () {
|
|||
data: {
|
||||
posts: [
|
||||
{
|
||||
title: 'cool'
|
||||
title: 'cool',
|
||||
updated_at: new Date().toISOString()
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue