test(user): write tests for getInvoices
This commit is contained in:
@@ -28,6 +28,7 @@ import { createStep } from '../../test/factories/step.js';
|
|||||||
import { createExecution } from '../../test/factories/execution.js';
|
import { createExecution } from '../../test/factories/execution.js';
|
||||||
import { createSubscription } from '../../test/factories/subscription.js';
|
import { createSubscription } from '../../test/factories/subscription.js';
|
||||||
import { createUsageData } from '../../test/factories/usage-data.js';
|
import { createUsageData } from '../../test/factories/usage-data.js';
|
||||||
|
import Billing from '../helpers/billing/index.ee.js';
|
||||||
|
|
||||||
describe('User model', () => {
|
describe('User model', () => {
|
||||||
it('tableName should return correct name', () => {
|
it('tableName should return correct name', () => {
|
||||||
@@ -1105,4 +1106,26 @@ describe('User model', () => {
|
|||||||
expect(() => user.getPlanAndUsage()).rejects.toThrow('NotFoundError');
|
expect(() => user.getPlanAndUsage()).rejects.toThrow('NotFoundError');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('getInvoices', () => {
|
||||||
|
it('should return invoices for the current subscription', async () => {
|
||||||
|
const user = await createUser();
|
||||||
|
const subscription = await createSubscription({ userId: user.id });
|
||||||
|
|
||||||
|
const getInvoicesSpy = vi
|
||||||
|
.spyOn(Billing.paddleClient, 'getInvoices')
|
||||||
|
.mockResolvedValue('dummy-invoices');
|
||||||
|
|
||||||
|
expect(await user.getInvoices()).toBe('dummy-invoices');
|
||||||
|
expect(getInvoicesSpy).toHaveBeenCalledWith(
|
||||||
|
Number(subscription.paddleSubscriptionId)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return empty array without any subscriptions', async () => {
|
||||||
|
const user = await createUser();
|
||||||
|
|
||||||
|
expect(await user.getInvoices()).toStrictEqual([]);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user