Improved post's webhook test annotations

refs https://github.com/TryGhost/Toolbox/issues/320

- There noe "roles" attached to the post's author when the 'post.added' event is fired. Webhooks function based of the model events and differ slightly with it's output comparing to the API response. For example, in case of Posts API, there'a an additional 'findOne' call (ref.: https://github.com/TryGhost/Ghost/blob/main/ghost/core/core/server/models/post.js#L1224-L1227) before returning the post to the endpoint handler and then passing that to the output serializer.
- If we want to have 1:1 copy of webhooks outputs and API outputs, we should rethink how we rely on model event data which is never the same as API controller level data.
This commit is contained in:
Naz 2022-10-06 10:50:02 +08:00
parent 4315b21d25
commit 78c97d10a6
No known key found for this signature in database

View File

@ -7,15 +7,13 @@ const tierSnapshot = {
updated_at: anyISODateTime
};
const buildAuthorSnapshot = (roles = false) => {
const buildAuthorSnapshot = (roles = true) => {
const authorSnapshot = {
last_seen: anyISODateTime,
created_at: anyISODateTime,
updated_at: anyISODateTime
};
// NOTE: this is such a bad hack! for the reasons I did not investigate the "add" event does not include
// the roles but the "published" does! massive inconsistency and needs to be fixed one day
if (roles) {
authorSnapshot.roles = new Array(1).fill({
id: anyObjectId,
@ -27,7 +25,7 @@ const buildAuthorSnapshot = (roles = false) => {
return authorSnapshot;
};
const buildPostSnapshotWithTiers = ({published, tiersCount, roles = false}) => {
const buildPostSnapshotWithTiers = ({published, tiersCount, roles = true}) => {
return {
id: anyObjectId,
uuid: anyUuid,
@ -108,8 +106,7 @@ describe('post.* events', function () {
post: {
current: buildPostSnapshotWithTiers({
published: true,
tiersCount: 2,
roles: true
tiersCount: 2
}),
previous: buildPreviousPostSnapshotWithTiers({
tiersCount: 2
@ -148,7 +145,10 @@ describe('post.* events', function () {
post: {
current: buildPostSnapshotWithTiers({
published: false,
tiersCount: 2
tiersCount: 2,
// @NOTE: post.added event does not include post author's roles
// see commit message for more context
roles: false
})
}
});