Skip to content

Commit

Permalink
Fix type error in BillingService.test.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
simlarsen committed Feb 27, 2024
1 parent 4285331 commit 79fd515
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 45 deletions.
4 changes: 2 additions & 2 deletions CommonServer/Tests/Services/BillingService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
77 changes: 34 additions & 43 deletions CommonServer/Tests/TestingUtils/Services/Helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand All @@ -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;

Expand All @@ -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',
Expand All @@ -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',
Expand Down

0 comments on commit 79fd515

Please sign in to comment.