From 3e5a292cde395a4842499d873a62c6e3eb891e12 Mon Sep 17 00:00:00 2001 From: Paul Fitzpatrick Date: Mon, 13 Sep 2021 17:29:35 -0400 Subject: [PATCH] (core) add tests for site deletion Summary: This tests site deletion with and without a plan. Test Plan: adding tests Reviewers: dsagal Reviewed By: dsagal Differential Revision: https://phab.getgrist.com/D3017 --- app/client/models/BillingModel.ts | 2 +- app/common/BillingAPI.ts | 13 ++++++++++--- app/gen-server/lib/Doom.ts | 2 +- app/gen-server/lib/HomeDBManager.ts | 2 +- app/server/lib/FlexServer.ts | 5 +++++ app/server/lib/GristServer.ts | 2 ++ 6 files changed, 20 insertions(+), 6 deletions(-) diff --git a/app/client/models/BillingModel.ts b/app/client/models/BillingModel.ts index b987898f..7ba3cc38 100644 --- a/app/client/models/BillingModel.ts +++ b/app/client/models/BillingModel.ts @@ -157,7 +157,7 @@ export class BillingModelImpl extends Disposable implements BillingModel { if (task === 'updatePlan') { // Change plan from a paid plan to another paid plan or to the free plan. if (!planId) { throw new Error('BillingPage _submit error: no plan selected'); } - await this._billingAPI.setSubscription(planId, formData.token); + await this._billingAPI.setSubscription(planId, {tokenId: formData.token}); } else if (task === 'addCard' || task === 'updateCard') { // Add or update payment card. if (!formData.token) { throw new Error('BillingPage _submit error: missing card info token'); } diff --git a/app/common/BillingAPI.ts b/app/common/BillingAPI.ts index 5147b1da..b73622b4 100644 --- a/app/common/BillingAPI.ts +++ b/app/common/BillingAPI.ts @@ -121,7 +121,11 @@ export interface BillingAPI { settings: IBillingOrgSettings): Promise; setCard(tokenId: string): Promise; removeCard(): Promise; - setSubscription(planId: string, tokenId?: string): Promise; + setSubscription(planId: string, options: { + tokenId?: string, + address?: IBillingAddress, + settings?: IBillingOrgSettings, + }): Promise; updateAddress(address?: IBillingAddress, settings?: IBillingOrgSettings): Promise; updateBillingManagers(delta: ManagerDelta): Promise; } @@ -178,10 +182,13 @@ export class BillingAPIImpl extends BaseAPI implements BillingAPI { return parsed.data; } - public async setSubscription(planId: string, tokenId?: string): Promise { + public async setSubscription(planId: string, options: { + tokenId?: string, + address?: IBillingAddress, + }): Promise { await this.request(`${this._url}/api/billing/subscription`, { method: 'POST', - body: JSON.stringify({ tokenId, planId }) + body: JSON.stringify({ ...options, planId }) }); } diff --git a/app/gen-server/lib/Doom.ts b/app/gen-server/lib/Doom.ts index 5f4e67c2..56a7c3b0 100644 --- a/app/gen-server/lib/Doom.ts +++ b/app/gen-server/lib/Doom.ts @@ -16,7 +16,7 @@ export class Doom { /** * Deletes a team site. - * - Remove billing (fails if no outstanding balance). + * - Remove billing (fails if there is an outstanding balance). * - Delete workspaces. * - Delete org. */ diff --git a/app/gen-server/lib/HomeDBManager.ts b/app/gen-server/lib/HomeDBManager.ts index cad7fa70..63eca33a 100644 --- a/app/gen-server/lib/HomeDBManager.ts +++ b/app/gen-server/lib/HomeDBManager.ts @@ -1331,7 +1331,7 @@ export class HomeDBManager extends EventEmitter { ...wsAcls, ...wsGroups, ...docs, ...docAcls, ...docGroups]); // Delete billing account if this was the last org using it. - const billingAccount = await manager.findOne(BillingAccount, org.billingAccount, + const billingAccount = await manager.findOne(BillingAccount, org.billingAccountId, {relations: ['orgs']}); if (billingAccount && billingAccount.orgs.length === 0) { await manager.remove([billingAccount]); diff --git a/app/server/lib/FlexServer.ts b/app/server/lib/FlexServer.ts index 37133709..aa69902e 100644 --- a/app/server/lib/FlexServer.ts +++ b/app/server/lib/FlexServer.ts @@ -264,6 +264,11 @@ export class FlexServer implements GristServer { return this._dbManager; } + public getStorageManager(): IDocStorageManager { + if (!this._storageManager) { throw new Error('no storage manager available'); } + return this._storageManager; + } + public addLogging() { if (this._check('logging')) { return; } if (process.env.GRIST_LOG_SKIP_HTTP) { return; } diff --git a/app/server/lib/GristServer.ts b/app/server/lib/GristServer.ts index ea17bd73..d51fffaa 100644 --- a/app/server/lib/GristServer.ts +++ b/app/server/lib/GristServer.ts @@ -6,6 +6,7 @@ import { HomeDBManager } from 'app/gen-server/lib/HomeDBManager'; import * as Comm from 'app/server/lib/Comm'; import { Hosts } from 'app/server/lib/extractOrg'; import { ICreate } from 'app/server/lib/ICreate'; +import { IDocStorageManager } from 'app/server/lib/IDocStorageManager'; import { IPermitStore } from 'app/server/lib/Permit'; import { Sessions } from 'app/server/lib/Sessions'; import * as express from 'express'; @@ -29,6 +30,7 @@ export interface GristServer { getComm(): Comm; getHosts(): Hosts; getHomeDBManager(): HomeDBManager; + getStorageManager(): IDocStorageManager; } export interface GristLoginMiddleware {