Skip to content

Commit 5994837

Browse files
authored
Merge branch 'main' into cores-scripts
2 parents 3b74d2c + 607f8a2 commit 5994837

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

__tests__/users.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4059,6 +4059,27 @@ describe('mutation deleteUser', () => {
40594059
expect(userOne).toEqual(null);
40604060
});
40614061

4062+
it('should not call cancel subscription for gifted subscription', async () => {
4063+
loggedUser = '1';
4064+
4065+
await con.getRepository(User).update(
4066+
{ id: '1' },
4067+
{
4068+
subscriptionFlags: updateSubscriptionFlags({
4069+
subscriptionId: '123',
4070+
provider: SubscriptionProvider.Paddle,
4071+
giftExpirationDate: new Date(Date.now() + 86400000), // 1 day from now
4072+
}),
4073+
},
4074+
);
4075+
4076+
await client.mutate(MUTATION);
4077+
4078+
expect(cancelSubscription).not.toHaveBeenCalled();
4079+
const userOne = await con.getRepository(User).findOneBy({ id: '1' });
4080+
expect(userOne).toEqual(null);
4081+
});
4082+
40624083
describe('when user has a storekit subscription', () => {
40634084
beforeEach(async () => {
40644085
await saveFixtures(con, User, [

queries/calculateTopReaders.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ views AS (
99
INNER JOIN "public"."post_keyword" "pk" ON "v"."postId" = "pk"."postId"
1010
WHERE
1111
"pk"."status" = 'allow'
12-
AND "pk"."keyword" NOT IN ('dailydev')
12+
AND "pk"."keyword" NOT IN ('dailydev', 'tiktok', 'legal', 'social-media', 'discord', 'interview', 'google', 'apple', 'iphone')
1313
AND "v"."timestamp" >= (date_trunc('month', CURRENT_DATE) - INTERVAL '1 month')
1414
-- Example 2024-10-01 00:00:00+00
1515
AND "v"."timestamp" < (date_trunc('month', CURRENT_DATE))

src/common/user.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,18 @@ export const deleteUser = async (
4747
}
4848

4949
if (subscriptionFlags?.provider === SubscriptionProvider.Paddle) {
50-
await cancelSubscription({
51-
subscriptionId: subscriptionFlags.subscriptionId,
52-
});
50+
const isGifted = !!subscriptionFlags.giftExpirationDate;
51+
// gifted subscription is a one-time payment hence not considered subscription in Paddle's terms
52+
if (!isGifted) {
53+
await cancelSubscription({
54+
subscriptionId: subscriptionFlags.subscriptionId,
55+
});
56+
}
5357
logger.info(
5458
{
5559
provider: SubscriptionProvider.Paddle,
5660
userId,
61+
isGifted,
5762
subscriptionId: subscriptionFlags.subscriptionId,
5863
},
5964
'Subscription cancelled user deletion',

0 commit comments

Comments
 (0)