From 79fd515f582647df32d53e4df3114bfb0df35f06 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Tue, 27 Feb 2024 18:58:55 +0000 Subject: [PATCH] Fix type error in BillingService.test.ts --- .../Tests/Services/BillingService.test.ts | 4 +- .../Tests/TestingUtils/Services/Helpers.ts | 77 ++++++++----------- 2 files changed, 36 insertions(+), 45 deletions(-) diff --git a/CommonServer/Tests/Services/BillingService.test.ts b/CommonServer/Tests/Services/BillingService.test.ts index 7446f7f38ba..82a4bf2e580 100644 --- a/CommonServer/Tests/Services/BillingService.test.ts +++ b/CommonServer/Tests/Services/BillingService.test.ts @@ -1383,7 +1383,7 @@ describe('BillingService', () => { .mockResolvedValue(mockCustomer); // mock responses for invoice creation, adding an item, and finalizing - const mockInvoice: Invoice = getStripeInvoice(); + const mockInvoice: any = getStripeInvoice(); mockStripe.invoices.create = jest .fn() .mockResolvedValue(mockInvoice); @@ -1440,7 +1440,7 @@ describe('BillingService', () => { .mockResolvedValue(mockCustomer); // mock successful invoice creation and finalization - const mockInvoice: Invoice = getStripeInvoice(); + const mockInvoice: any = getStripeInvoice(); mockStripe.invoices.create = jest .fn() .mockResolvedValue(mockInvoice); diff --git a/CommonServer/Tests/TestingUtils/Services/Helpers.ts b/CommonServer/Tests/TestingUtils/Services/Helpers.ts index fe92594b2cb..c284a417da4 100644 --- a/CommonServer/Tests/TestingUtils/Services/Helpers.ts +++ b/CommonServer/Tests/TestingUtils/Services/Helpers.ts @@ -20,9 +20,7 @@ import { ProductType } from 'Model/Models/UsageBilling'; type MockIsBillingEnabledFunction = (value: boolean) => BillingService; -const mockIsBillingEnabled: MockIsBillingEnabledFunction = ( - value: boolean -): BillingService => { +const mockIsBillingEnabled: MockIsBillingEnabledFunction = (value: boolean): BillingService => { jest.resetModules(); jest.doMock('../../../BillingConfig', () => { return { @@ -35,9 +33,7 @@ const mockIsBillingEnabled: MockIsBillingEnabledFunction = ( type GetStripeCustomerFunction = (id?: string) => Stripe.Customer; -const getStripeCustomer: GetStripeCustomerFunction = ( - id?: string -): Stripe.Customer => { +const getStripeCustomer: GetStripeCustomerFunction = (id?: string): Stripe.Customer => { id = id || faker.datatype.uuid(); return { id, @@ -61,42 +57,41 @@ const getStripeCustomer: GetStripeCustomerFunction = ( type GetStripeSubscriptionFunction = () => Stripe.Subscription; -const getStripeSubscription: GetStripeSubscriptionFunction = - (): Stripe.Subscription => { - return { - id: faker.datatype.uuid(), - items: { - data: [ - { - id: faker.datatype.uuid(), - // @ts-ignore - price: { - id: new BillingService().getMeteredPlanPriceId( - ProductType.ActiveMonitoring - ), - }, +const getStripeSubscription: GetStripeSubscriptionFunction = (): Stripe.Subscription => { + return { + id: faker.datatype.uuid(), + items: { + data: [ + { + id: faker.datatype.uuid(), + // @ts-ignore + price: { + id: new BillingService().getMeteredPlanPriceId( + ProductType.ActiveMonitoring + ), }, - ], - }, - status: 'active', - customer: getStripeCustomer(), - }; + }, + ], + }, + status: 'active', + customer: getStripeCustomer(), }; +}; + type GetSubscriptionPlanDataFunction = () => SubscriptionPlan; -const getSubscriptionPlanData: GetSubscriptionPlanDataFunction = - (): SubscriptionPlan => { - return new SubscriptionPlan( - faker.datatype.uuid(), // monthlyPlanId - faker.datatype.uuid(), // yearlyPlanId - faker.commerce.productName(), // name - faker.datatype.number(), // monthlySubscriptionAmountInUSD - faker.datatype.number({ min: 1, max: 100 }), // yearlySubscriptionAmountInUSD - faker.datatype.number({ min: 1, max: 100 }), // order - faker.datatype.number({ min: 1, max: 100 }) // trial period days - ); - }; +const getSubscriptionPlanData: GetSubscriptionPlanDataFunction = (): SubscriptionPlan => { + return new SubscriptionPlan( + faker.datatype.uuid(), // monthlyPlanId + faker.datatype.uuid(), // yearlyPlanId + faker.commerce.productName(), // name + faker.datatype.number(), // monthlySubscriptionAmountInUSD + faker.datatype.number({ min: 1, max: 100 }), // yearlySubscriptionAmountInUSD + faker.datatype.number({ min: 1, max: 100 }), // order + faker.datatype.number({ min: 1, max: 100 }) // trial period days + ); +}; type GetStripeInvoiceFunction = () => Stripe.Invoice; @@ -114,9 +109,7 @@ const getStripeInvoice: GetStripeInvoiceFunction = (): Stripe.Invoice => { type GetCustomerDataFunction = (id?: ObjectID) => CustomerData; -const getCustomerData: GetCustomerDataFunction = ( - id?: ObjectID -): CustomerData => { +const getCustomerData: GetCustomerDataFunction = (id?: ObjectID): CustomerData => { return { id: id || new ObjectID('customer_id'), name: 'John Doe', @@ -126,9 +119,7 @@ const getCustomerData: GetCustomerDataFunction = ( type GetSubscriptionDataFunction = (id?: ObjectID) => Subscription; -const getSubscriptionData: GetSubscriptionDataFunction = ( - id?: ObjectID -): Subscription => { +const getSubscriptionData: GetSubscriptionDataFunction = (id?: ObjectID): Subscription => { return { projectId: id || new ObjectID('project_id'), customerId: 'cust_123',