Skip to content

Commit

Permalink
Removed dependency on tier.type in bulk edit endpoints for posts and …
Browse files Browse the repository at this point in the history
…pages
  • Loading branch information
sagzy committed Mar 6, 2024
1 parent 1853bf2 commit b32c870
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
14 changes: 6 additions & 8 deletions ghost/core/test/e2e-api/admin/pages-bulk.test.js
Expand Up @@ -124,10 +124,10 @@ describe('Pages Bulk API', function () {

const products = await models.Product.findAll();

const freeTier = products.models[0];
const paidTier = products.models[1];
const tier1 = products.models[0];
const tier2 = products.models[1];

assert(freeTier.id && paidTier.id);
assert(tier1.id && tier2.id);

// Check all the pages that should be affected
const changedPages = await models.Post.findPage({filter: forcePageFilter(filter), limit: 1, status: 'all'});
Expand All @@ -144,12 +144,10 @@ describe('Pages Bulk API', function () {
visibility: 'tiers',
tiers: [
{
id: freeTier.id,
type: freeTier.get('type')
id: tier1.id
},
{
id: paidTier.id,
type: paidTier.get('type')
id: tier2.id
}
]
}
Expand All @@ -166,7 +164,7 @@ describe('Pages Bulk API', function () {

for (const page of pages) {
assert(page.get('visibility') === 'tiers', `Expect page ${page.id} to have access 'tiers'`);
assert.equal(page.related('tiers').length, 1); // Only the paid tier, not the free tier
assert.equal(page.related('tiers').length, 2);
}
});

Expand Down
14 changes: 6 additions & 8 deletions ghost/core/test/e2e-api/admin/posts-bulk.test.js
Expand Up @@ -159,10 +159,10 @@ describe('Posts Bulk API', function () {

const products = await models.Product.findAll();

const freeTier = products.models[0];
const paidTier = products.models[1];
const tier1 = products.models[0];
const tier2 = products.models[1];

assert(freeTier.id && paidTier.id);
assert(tier1.id && tier2.id);

// Check all the posts that should be affected
const changedPosts = await models.Post.findPage({filter, limit: 1, status: 'all'});
Expand All @@ -179,12 +179,10 @@ describe('Posts Bulk API', function () {
visibility: 'tiers',
tiers: [
{
id: freeTier.id,
type: freeTier.get('type')
id: tier1.id
},
{
id: paidTier.id,
type: paidTier.get('type')
id: tier2.id
}
]
}
Expand All @@ -201,7 +199,7 @@ describe('Posts Bulk API', function () {

for (const post of posts) {
assert(post.get('visibility') === 'tiers', `Expect post ${post.id} to have access 'tiers'`);
assert.equal(post.related('tiers').length, 1); // Only the paid tier, not the free tier
assert.equal(post.related('tiers').length, 2);
}
});

Expand Down
2 changes: 1 addition & 1 deletion ghost/posts-service/lib/PostsService.js
Expand Up @@ -271,7 +271,7 @@ class PostsService {
message: tpl(messages.invalidTiers)
});
}
tiers = data.meta.tiers.filter(t => t.type === 'paid');
tiers = data.meta.tiers;
}
return await this.#updatePosts({visibility: data.meta.visibility, tiers}, {filter: options.filter, context: options.context});
}
Expand Down

0 comments on commit b32c870

Please sign in to comment.