test(user): write tests for getInvoices

This commit is contained in:
Ali BARIN
2024-11-19 12:48:10 +00:00
committed by Faruk AYDIN
parent ca9cb8b07b
commit db718d6fc3

View File

@@ -28,6 +28,7 @@ import { createStep } from '../../test/factories/step.js';
import { createExecution } from '../../test/factories/execution.js';
import { createSubscription } from '../../test/factories/subscription.js';
import { createUsageData } from '../../test/factories/usage-data.js';
import Billing from '../helpers/billing/index.ee.js';
describe('User model', () => {
it('tableName should return correct name', () => {
@@ -1105,4 +1106,26 @@ describe('User model', () => {
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([]);
});
});
});