c36558e0f3
Memind CI / Test, build, and release guards (push) Successful in 4m20s
欠费停用用户仍送达早安与天气,跳过复杂页面订阅与定时任务补发。 Co-authored-by: Cursor <cursoragent@cursor.com>
92 lines
2.8 KiB
JavaScript
92 lines
2.8 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
|
|
import {
|
|
canCommitPushSubscriptionForSuspendedUser,
|
|
isEssentialPushSubscriptionSource,
|
|
isSuspendedBillingUser,
|
|
sanitizeDeliveryForSuspendedUser,
|
|
shouldSkipPushReminderForSuspendedUser,
|
|
} from './suspended-user-push-policy.mjs';
|
|
import { pushSubscriptionMetadataSource } from './push-subscription-catalog.mjs';
|
|
|
|
test('isSuspendedBillingUser matches suspended status only', () => {
|
|
assert.equal(isSuspendedBillingUser('suspended'), true);
|
|
assert.equal(isSuspendedBillingUser({ status: 'suspended' }), true);
|
|
assert.equal(isSuspendedBillingUser('active'), false);
|
|
assert.equal(isSuspendedBillingUser('disabled'), false);
|
|
});
|
|
|
|
test('essential push subscriptions stay enabled for suspended users', () => {
|
|
assert.equal(
|
|
isEssentialPushSubscriptionSource(pushSubscriptionMetadataSource('morning')),
|
|
true,
|
|
);
|
|
assert.equal(
|
|
isEssentialPushSubscriptionSource(pushSubscriptionMetadataSource('weather')),
|
|
true,
|
|
);
|
|
assert.equal(
|
|
isEssentialPushSubscriptionSource(pushSubscriptionMetadataSource('news')),
|
|
false,
|
|
);
|
|
});
|
|
|
|
test('shouldSkipPushReminderForSuspendedUser skips complex subscriptions only', () => {
|
|
assert.equal(
|
|
shouldSkipPushReminderForSuspendedUser({
|
|
userStatus: 'suspended',
|
|
pushSource: pushSubscriptionMetadataSource('morning'),
|
|
}),
|
|
false,
|
|
);
|
|
assert.equal(
|
|
shouldSkipPushReminderForSuspendedUser({
|
|
userStatus: 'suspended',
|
|
pushSource: pushSubscriptionMetadataSource('news'),
|
|
}),
|
|
true,
|
|
);
|
|
assert.equal(
|
|
shouldSkipPushReminderForSuspendedUser({
|
|
userStatus: 'active',
|
|
pushSource: pushSubscriptionMetadataSource('news'),
|
|
}),
|
|
false,
|
|
);
|
|
assert.equal(
|
|
shouldSkipPushReminderForSuspendedUser({
|
|
userStatus: 'suspended',
|
|
pushSource: '',
|
|
}),
|
|
false,
|
|
);
|
|
});
|
|
|
|
test('sanitizeDeliveryForSuspendedUser drops complex page urls', () => {
|
|
const kept = sanitizeDeliveryForSuspendedUser(
|
|
{ text: '早安', verifiedHtmlUrls: ['https://example.com/page.html'] },
|
|
{
|
|
userStatus: 'suspended',
|
|
pushSource: pushSubscriptionMetadataSource('morning'),
|
|
},
|
|
);
|
|
assert.equal(kept.text, '早安');
|
|
assert.deepEqual(kept.verifiedHtmlUrls, []);
|
|
|
|
const skipped = sanitizeDeliveryForSuspendedUser(
|
|
{ text: '新闻', verifiedHtmlUrls: ['https://example.com/page.html'] },
|
|
{
|
|
userStatus: 'suspended',
|
|
pushSource: pushSubscriptionMetadataSource('news'),
|
|
},
|
|
);
|
|
assert.equal(skipped, null);
|
|
});
|
|
|
|
test('canCommitPushSubscriptionForSuspendedUser allows morning and weather only', () => {
|
|
assert.equal(canCommitPushSubscriptionForSuspendedUser('morning'), true);
|
|
assert.equal(canCommitPushSubscriptionForSuspendedUser('weather'), true);
|
|
assert.equal(canCommitPushSubscriptionForSuspendedUser('news'), false);
|
|
});
|