Skip to content

Commit

Permalink
feat(api, web): Add annual subscription support (#5335)
Browse files Browse the repository at this point in the history
* feat: add annual toggle for business plan

* fix(web): Change billing tab name for simplicity

* chore: Update submodule

* fix: update source

* test(billing): Fix get-prices test

* test(api): Upsert setup intent fixes

* chore: Update submodule

* test(api): Fix setup intent webhook tests

* chore: Update submodule

* test(api): Fix create-usage-records test

* test(api): Fix upsert-subscription tests

* chore: Update submodule

* chore: Update submodule

* test(api): Add tests for non-existing subscriptions

* test(api): Update billing tests for annual subscription

* chore: Update submodule

* test(billing): Add upsert deletion assertions

* revert(api): Add chimera module

* chore: Remove comments and fix constants

* chore: remove comments

* chore: remove comment

---------

Co-authored-by: Richard Fontein <32132657+rifont@users.noreply.github.com>
  • Loading branch information
davidsoderberg and rifont authored Mar 26, 2024
1 parent f6201e1 commit db7318f
Show file tree
Hide file tree
Showing 7 changed files with 694 additions and 263 deletions.
2 changes: 1 addition & 1 deletion .source
151 changes: 0 additions & 151 deletions apps/api/src/app/testing/billing/create-setup-intent.e2e-ee.ts

This file was deleted.

35 changes: 23 additions & 12 deletions apps/api/src/app/testing/billing/create-usage-records.e2e-ee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ import { Logger } from '@nestjs/common';
import * as sinon from 'sinon';
import { expect } from 'chai';
import { ApiServiceLevelEnum } from '@novu/shared';
import { StripeBillingIntervalEnum, StripeUsageTypeEnum } from '@novu/ee-billing/src/stripe/types';

const mockBusinessSubscription = {
const mockMonthlyBusinessSubscription = {
id: 'subscription_id',
items: {
data: [
{ id: 'item_id_usage_notifications', price: { lookup_key: 'business_usage_notifications' } },
{ id: 'item_id_flat', price: { lookup_key: 'business_flat_monthly' } },
{
id: 'item_id_usage_notifications',
price: { lookup_key: 'business_usage_notifications', recurring: { usage_type: StripeUsageTypeEnum.METERED } },
},
{
id: 'item_id_flat',
price: { lookup_key: 'business_flat_monthly', recurring: { usage_type: StripeUsageTypeEnum.LICENSED } },
},
],
},
};
Expand Down Expand Up @@ -53,15 +60,18 @@ describe('CreateUsageRecords', () => {
},
] as any);
getFeatureFlagStub = sinon.stub(getFeatureFlagUsecase, 'execute').resolves(true);
upsertSubscriptionStub = sinon.stub(upsertSubscriptionUsecase, 'execute').resolves(mockBusinessSubscription as any);
upsertSubscriptionStub = sinon.stub(upsertSubscriptionUsecase, 'execute').resolves({
licensed: mockMonthlyBusinessSubscription,
metered: mockMonthlyBusinessSubscription,
} as any);
getCustomerStub = sinon.stub(getCustomerUsecase, 'execute').resolves({
id: 'customer_id',
deleted: false,
metadata: {
organizationId: 'organization_id',
},
subscriptions: {
data: [mockBusinessSubscription],
data: [mockMonthlyBusinessSubscription],
},
} as any);
});
Expand Down Expand Up @@ -141,20 +151,21 @@ describe('CreateUsageRecords', () => {
{
customer: mockNoSubscriptionsCustomer,
apiServiceLevel: ApiServiceLevelEnum.FREE,
billingInterval: StripeBillingIntervalEnum.MONTH,
},
]);
});

it('should set the usage timestamp to the subscription start date if the subscription is new', async () => {
it('should set the usage timestamp to the subscription current period start if the subscription is new', async () => {
const mockSubscriptionStartDate = new Date('2021-02-01T00:00:00Z');
const mockSubscriptionCreated = mockSubscriptionStartDate.getTime() / 1000;
const mockSubscriptionCurrentPeriodStart = mockSubscriptionStartDate.getTime() / 1000;
const mockUsageStartDate = new Date('2021-01-15T00:00:00Z');
getCustomerStub.resolves({
subscriptions: {
data: [
{
created: mockSubscriptionCreated,
...mockBusinessSubscription,
...mockMonthlyBusinessSubscription,
current_period_start: mockSubscriptionCurrentPeriodStart,
},
],
},
Expand All @@ -167,7 +178,7 @@ describe('CreateUsageRecords', () => {
})
);

expect(createUsageRecordStub.lastCall.args[1].timestamp).to.equal(mockSubscriptionCreated);
expect(createUsageRecordStub.lastCall.args[1].timestamp).to.equal(mockSubscriptionCurrentPeriodStart);
});

it('should set the usage timestamp to the usage start date if the subscription is not new', async () => {
Expand All @@ -178,8 +189,8 @@ describe('CreateUsageRecords', () => {
subscriptions: {
data: [
{
created: mockSubscriptionCreated,
...mockBusinessSubscription,
...mockMonthlyBusinessSubscription,
current_period_start: mockSubscriptionCreated,
},
],
},
Expand Down
Loading

0 comments on commit db7318f

Please sign in to comment.