Testflight
This commit is contained in:
@@ -1,40 +1,40 @@
|
||||
jest.mock('../../server/lib/postgres', () => ({
|
||||
get: jest.fn(),
|
||||
run: jest.fn(),
|
||||
}));
|
||||
|
||||
const { get, run } = require('../../server/lib/postgres');
|
||||
const { deleteAccount, signUp } = require('../../server/lib/auth');
|
||||
|
||||
describe('server auth account deletion', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
get.mockResolvedValue(null);
|
||||
run.mockResolvedValue({ lastId: null, changes: 1, rows: [] });
|
||||
});
|
||||
|
||||
it('removes auth and billing rows so the same email can sign up again', async () => {
|
||||
const email = 'same@example.com';
|
||||
|
||||
await signUp({}, email, 'First User', 'password-1');
|
||||
await deleteAccount({}, 'usr_deleted');
|
||||
await signUp({}, email, 'Second User', 'password-2');
|
||||
|
||||
const authDeletes = run.mock.calls.filter(([, sql]) => (
|
||||
typeof sql === 'string' && sql.includes('DELETE FROM auth_users')
|
||||
));
|
||||
expect(authDeletes).toHaveLength(1);
|
||||
|
||||
const billingAccountDeletes = run.mock.calls.filter(([, sql]) => (
|
||||
typeof sql === 'string' && sql.includes('DELETE FROM billing_accounts')
|
||||
));
|
||||
expect(billingAccountDeletes).toHaveLength(1);
|
||||
|
||||
const signupChecks = get.mock.calls.filter(([, sql, params]) => (
|
||||
typeof sql === 'string'
|
||||
&& sql.includes('SELECT id FROM auth_users WHERE LOWER(email)')
|
||||
&& params?.[0] === email
|
||||
));
|
||||
expect(signupChecks).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
jest.mock('../../server/lib/postgres', () => ({
|
||||
get: jest.fn(),
|
||||
run: jest.fn(),
|
||||
}));
|
||||
|
||||
const { get, run } = require('../../server/lib/postgres');
|
||||
const { deleteAccount, signUp } = require('../../server/lib/auth');
|
||||
|
||||
describe('server auth account deletion', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
get.mockResolvedValue(null);
|
||||
run.mockResolvedValue({ lastId: null, changes: 1, rows: [] });
|
||||
});
|
||||
|
||||
it('removes auth and billing rows so the same email can sign up again', async () => {
|
||||
const email = 'same@example.com';
|
||||
|
||||
await signUp({}, email, 'First User', 'password-1');
|
||||
await deleteAccount({}, 'usr_deleted');
|
||||
await signUp({}, email, 'Second User', 'password-2');
|
||||
|
||||
const authDeletes = run.mock.calls.filter(([, sql]) => (
|
||||
typeof sql === 'string' && sql.includes('DELETE FROM auth_users')
|
||||
));
|
||||
expect(authDeletes).toHaveLength(1);
|
||||
|
||||
const billingAccountDeletes = run.mock.calls.filter(([, sql]) => (
|
||||
typeof sql === 'string' && sql.includes('DELETE FROM billing_accounts')
|
||||
));
|
||||
expect(billingAccountDeletes).toHaveLength(1);
|
||||
|
||||
const signupChecks = get.mock.calls.filter(([, sql, params]) => (
|
||||
typeof sql === 'string'
|
||||
&& sql.includes('SELECT id FROM auth_users WHERE LOWER(email)')
|
||||
&& params?.[0] === email
|
||||
));
|
||||
expect(signupChecks).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,45 +1,45 @@
|
||||
jest.mock('../../server/lib/postgres', () => ({
|
||||
get: jest.fn(),
|
||||
run: jest.fn(),
|
||||
}));
|
||||
|
||||
const { get, run } = require('../../server/lib/postgres');
|
||||
const { syncRevenueCatCustomerInfo } = require('../../server/lib/billing');
|
||||
|
||||
describe('server billing timestamp normalization', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
run.mockResolvedValue({ lastId: null, changes: 1, rows: [] });
|
||||
});
|
||||
|
||||
it('upserts ISO timestamps when postgres returns Date objects', async () => {
|
||||
get.mockResolvedValueOnce({
|
||||
userId: 'usr_mnjcdwpo_ax9lf68b',
|
||||
plan: 'free',
|
||||
provider: 'revenuecat',
|
||||
cycleStartedAt: new Date('2027-04-01T00:00:00.000Z'),
|
||||
cycleEndsAt: new Date('2027-05-01T00:00:00.000Z'),
|
||||
monthlyAllowance: 15,
|
||||
usedThisCycle: 0,
|
||||
topupBalance: 0,
|
||||
renewsAt: null,
|
||||
updatedAt: new Date('2026-04-02T12:00:00.000Z'),
|
||||
});
|
||||
|
||||
await syncRevenueCatCustomerInfo(
|
||||
{},
|
||||
'usr_mnjcdwpo_ax9lf68b',
|
||||
{ entitlements: { active: {} }, nonSubscriptions: {} },
|
||||
{ source: 'topup_purchase' },
|
||||
);
|
||||
|
||||
const upsertCall = run.mock.calls.find(([, sql]) => typeof sql === 'string' && sql.includes('INSERT INTO billing_accounts'));
|
||||
expect(upsertCall).toBeTruthy();
|
||||
|
||||
const params = upsertCall[2];
|
||||
expect(params[3]).toBe('2027-04-01T00:00:00.000Z');
|
||||
expect(params[4]).toBe('2027-05-01T00:00:00.000Z');
|
||||
expect(params[3]).not.toContain('Coordinated Universal Time');
|
||||
expect(params[4]).not.toContain('Coordinated Universal Time');
|
||||
});
|
||||
});
|
||||
jest.mock('../../server/lib/postgres', () => ({
|
||||
get: jest.fn(),
|
||||
run: jest.fn(),
|
||||
}));
|
||||
|
||||
const { get, run } = require('../../server/lib/postgres');
|
||||
const { syncRevenueCatCustomerInfo } = require('../../server/lib/billing');
|
||||
|
||||
describe('server billing timestamp normalization', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
run.mockResolvedValue({ lastId: null, changes: 1, rows: [] });
|
||||
});
|
||||
|
||||
it('upserts ISO timestamps when postgres returns Date objects', async () => {
|
||||
get.mockResolvedValueOnce({
|
||||
userId: 'usr_mnjcdwpo_ax9lf68b',
|
||||
plan: 'free',
|
||||
provider: 'revenuecat',
|
||||
cycleStartedAt: new Date('2027-04-01T00:00:00.000Z'),
|
||||
cycleEndsAt: new Date('2027-05-01T00:00:00.000Z'),
|
||||
monthlyAllowance: 15,
|
||||
usedThisCycle: 0,
|
||||
topupBalance: 0,
|
||||
renewsAt: null,
|
||||
updatedAt: new Date('2026-04-02T12:00:00.000Z'),
|
||||
});
|
||||
|
||||
await syncRevenueCatCustomerInfo(
|
||||
{},
|
||||
'usr_mnjcdwpo_ax9lf68b',
|
||||
{ entitlements: { active: {} }, nonSubscriptions: {} },
|
||||
{ source: 'topup_purchase' },
|
||||
);
|
||||
|
||||
const upsertCall = run.mock.calls.find(([, sql]) => typeof sql === 'string' && sql.includes('INSERT INTO billing_accounts'));
|
||||
expect(upsertCall).toBeTruthy();
|
||||
|
||||
const params = upsertCall[2];
|
||||
expect(params[3]).toBe('2027-04-01T00:00:00.000Z');
|
||||
expect(params[4]).toBe('2027-05-01T00:00:00.000Z');
|
||||
expect(params[3]).not.toContain('Coordinated Universal Time');
|
||||
expect(params[4]).not.toContain('Coordinated Universal Time');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user