0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

🐛 Fixed incorrect subscription status text when subscription is comped (#18369)

refs https://github.com/TryGhost/Product/issues/3963

The subscription status text was incorrect when a subscription was
comped and a member had multiple subscriptions (i.e a cancelled sub and
a comped sub). This was because the methods used to determine the status
of a subscription only took into account the status of the first
subscription associated with a member.
This commit is contained in:
Michael Barrett 2023-09-27 08:46:55 +01:00 committed by GitHub
parent d9ec7a0b90
commit d406d2ba6a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 3 deletions

View file

@ -91,8 +91,9 @@ export function allowCompMemberUpgrade({member}) {
}
export function getCompExpiry({member}) {
if (member?.subscriptions?.[0]?.tier?.expiry_at) {
return getDateString(member.subscriptions[0].tier.expiry_at);
const subscription = getMemberSubscription({member});
if (subscription?.tier?.expiry_at) {
return getDateString(subscription.tier.expiry_at);
}
return '';
}

View file

@ -1,4 +1,4 @@
import {getAllProductsForSite, getAvailableProducts, getCurrencySymbol, getFreeProduct, getMemberName, getMemberSubscription, getPriceFromSubscription, getPriceIdFromPageQuery, getSupportAddress, getUrlHistory, hasMultipleProducts, isActiveOffer, isInviteOnlySite, isPaidMember, isSameCurrency, transformApiTiersData, isSigninAllowed, isSignupAllowed} from './helpers';
import {getAllProductsForSite, getAvailableProducts, getCurrencySymbol, getFreeProduct, getMemberName, getMemberSubscription, getPriceFromSubscription, getPriceIdFromPageQuery, getSupportAddress, getUrlHistory, hasMultipleProducts, isActiveOffer, isInviteOnlySite, isPaidMember, isSameCurrency, transformApiTiersData, isSigninAllowed, isSignupAllowed, getCompExpiry} from './helpers';
import * as Fixtures from './fixtures-generator';
import {site as FixturesSite, member as FixtureMember, offer as FixtureOffer, transformTierFixture as TransformFixtureTiers} from '../utils/test-fixtures';
import {isComplimentaryMember} from '../utils/helpers';
@ -404,4 +404,48 @@ describe('Helpers - ', () => {
expect(actual.length).toBe(0);
});
});
describe('getCompExpiry', () => {
let member = {};
beforeEach(() => {
member = {
paid: true,
subscriptions: [
{
status: 'active',
price: {
amount: 0
},
tier: {
expiry_at: '2023-10-13T00:00:00.000Z'
}
}
]
};
});
it('returns the expiry date of a comped subscription', () => {
expect(getCompExpiry({member})).toEqual('13 Oct 2023');
});
it('returns the expiry date of a comped subscription if the member has multiple subscriptions', () => {
member.subscriptions.push({
status: 'cancelled',
price: {
amount: 1234
},
tier: {
expiry_at: '2023-10-14T00:00:00.000Z'
}
});
expect(getCompExpiry({member})).toEqual('13 Oct 2023');
});
it('returns an empty string if the subscription has no expiry date', () => {
delete member.subscriptions[0].tier.expiry_at;
expect(getCompExpiry({member})).toEqual('');
});
});
});