mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -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:
parent
d9ec7a0b90
commit
d406d2ba6a
2 changed files with 48 additions and 3 deletions
|
@ -91,8 +91,9 @@ export function allowCompMemberUpgrade({member}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getCompExpiry({member}) {
|
export function getCompExpiry({member}) {
|
||||||
if (member?.subscriptions?.[0]?.tier?.expiry_at) {
|
const subscription = getMemberSubscription({member});
|
||||||
return getDateString(member.subscriptions[0].tier.expiry_at);
|
if (subscription?.tier?.expiry_at) {
|
||||||
|
return getDateString(subscription.tier.expiry_at);
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 * as Fixtures from './fixtures-generator';
|
||||||
import {site as FixturesSite, member as FixtureMember, offer as FixtureOffer, transformTierFixture as TransformFixtureTiers} from '../utils/test-fixtures';
|
import {site as FixturesSite, member as FixtureMember, offer as FixtureOffer, transformTierFixture as TransformFixtureTiers} from '../utils/test-fixtures';
|
||||||
import {isComplimentaryMember} from '../utils/helpers';
|
import {isComplimentaryMember} from '../utils/helpers';
|
||||||
|
@ -404,4 +404,48 @@ describe('Helpers - ', () => {
|
||||||
expect(actual.length).toBe(0);
|
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('');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue