Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions static/gsAdmin/views/customerDetails.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1624,6 +1624,80 @@ describe('Customer Details', () => {
});
});

describe('billing platform migration', () => {
const migrationOrg = OrganizationFixture();
const mockBillingAdminUser = UserFixture({
permissions: new Set(['billing.admin']),
});

async function openMigrationAction(name: string) {
render(<CustomerDetails />, {
initialRouterConfig: {
location: {pathname: `/customers/${migrationOrg.slug}`},
route: '/customers/:orgId',
},
organization: migrationOrg,
});

await screen.findByRole('heading', {name: 'Customers'});

await userEvent.click(
screen.getAllByRole('button', {
name: 'Customers Actions',
})[0]!
);

await userEvent.click(screen.getByText(name));

renderGlobalModal();
await userEvent.click(screen.getByRole('button', {name: 'Confirm'}));
}

it('migrates an org to the billing platform', async () => {
ConfigStore.set('user', mockBillingAdminUser);
setUpMocks(migrationOrg, {hasMigratedToBillingPlatform: false});

const migrateMock = MockApiClient.addMockResponse({
url: `/_admin/customers/${migrationOrg.slug}/billing-platform-migration/`,
method: 'POST',
});

await openMigrationAction('[Do Not Use] Migrate to Billing Platform');

await waitFor(() => {
expect(migrateMock).toHaveBeenCalledWith(
`/_admin/customers/${migrationOrg.slug}/billing-platform-migration/`,
expect.objectContaining({
method: 'POST',
data: {migrated: true},
})
);
});
});

it('unmigrates an org from the billing platform', async () => {
ConfigStore.set('user', mockBillingAdminUser);
setUpMocks(migrationOrg, {hasMigratedToBillingPlatform: true});

const unmigrateMock = MockApiClient.addMockResponse({
url: `/_admin/customers/${migrationOrg.slug}/billing-platform-migration/`,
method: 'POST',
});

await openMigrationAction('[Do Not Use] Unmigrate from Billing Platform');

await waitFor(() => {
expect(unmigrateMock).toHaveBeenCalledWith(
`/_admin/customers/${migrationOrg.slug}/billing-platform-migration/`,
expect.objectContaining({
method: 'POST',
data: {migrated: false},
})
);
});
});
});

describe('close account', () => {
it('closes an account', async () => {
setUpMocks(organization);
Expand Down
28 changes: 25 additions & 3 deletions static/gsAdmin/views/customerDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,28 @@ export function CustomerDetails() {
refetchBillingConfig();
};

const onToggleBillingPlatformMigrationMutation = useMutation({
mutationFn: (params: Record<string, any>) =>
fetchMutation({
url: `/_admin/customers/${orgId}/billing-platform-migration/`,
method: 'POST',
data: params,
}),
onMutate: () => addLoadingMessage('Saving changes\u2026'),
onSuccess: (_data, variables) => {
addSuccessMessage(
variables.migrated
? 'Marked this org as migrated to the billing platform.'
: 'Marked this org as not migrated to the billing platform.'
);
reloadData();
},
onError: (error: RequestError) => {
const detail = error.responseJSON?.detail;
addErrorMessage(typeof detail === 'string' ? detail : DEFAULT_ERROR_MESSAGE);
},
});

if (isPendingSubscription || isPendingOrganization || isPendingBillingConfig) {
return <LoadingIndicator />;
}
Expand Down Expand Up @@ -460,15 +482,15 @@ export function CustomerDetails() {
{
key: 'toggleBillingPlatformMigration',
name: subscription.hasMigratedToBillingPlatform
? '[Do Not Use] Unmigrate to Billing Platform'
? '[Do Not Use] Unmigrate from Billing Platform'
: '[Do Not Use] Migrate to Billing Platform',
help: subscription.hasMigratedToBillingPlatform
? 'Mark this org as not migrated to the billing platform.'
: 'Mark this org as migrated to the billing platform.',
onAction: params =>
onUpdateMutation.mutate({
onToggleBillingPlatformMigrationMutation.mutate({
...params,
migratedToBillingPlatform: !subscription.hasMigratedToBillingPlatform,
migrated: !subscription.hasMigratedToBillingPlatform,
}),
...actionRequiresBillingAdmin,
},
Expand Down
Loading