0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00
ghost/apps/comments-ui/test/utils/fixtures.ts
Ronald Langeveld 6d3317fcfc
Added feature flagging system for Comments UI (#20984)
ref PLG-229

- Previously we had no way of using Ghost labs flags in Comments UI.
- With this change, we now get Labs data from the existing content
  settings endpoint.
- Additionally, we have a `useLabs` hook that can be accessed from
  anywhere in the App to put those awesome new features behind a flag
for staging
- And we can pass labs params to the initialiser for testing.

For more details: https://ghost.slack.com/archives/C06TQR9SHSM/p1726133527960489
2024-09-12 18:36:37 +09:00

74 lines
1.7 KiB
TypeScript

const ObjectId = require('bson-objectid').default;
let memberCounter = 0;
export function buildMember(override: any = {}) {
memberCounter += 1;
return {
id: ObjectId().toString(),
avatar_image: 'https://www.gravatar.com/avatar/7a68f69cc9c9e9b45d97ecad6f24184a?s=250&r=g&d=blank',
expertise: 'Head of Testing',
name: 'Test Member ' + memberCounter,
uuid: ObjectId().toString(),
paid: override.status === 'paid',
status: 'free',
...override
};
}
export function buildSettings(override: any = {}) {
return {
meta: {},
settings: {},
...override
};
}
export function buildComment(override: any = {}) {
return {
id: ObjectId().toString(),
html: '<p>Empty</p>',
replies: [],
liked: false,
created_at: '2022-08-11T09:26:34.000Z',
edited_at: null,
member: buildMember(),
status: 'published',
...override,
count: {
replies: 0,
likes: 0,
...override.count
}
};
}
export function buildReply(override: any = {}) {
return {
id: ObjectId().toString(),
html: '<p>Empty</p>',
count: {
likes: 0
},
liked: false,
created_at: '2022-08-11T09:26:34.000Z',
edited_at: null,
member: buildMember(),
status: 'published',
...override
};
}
export function buildCommentsReply(override: any = {}) {
return {
comments: [],
meta: {
pagination: {
pages: 1,
total: 0,
page: 1,
limit: 5
}
}
};
}