From 6c2fde177259f502911391cd0da7eb8eb484b66b Mon Sep 17 00:00:00 2001 From: Santese Smith <43831817+santese@users.noreply.github.com> Date: Wed, 25 Jan 2023 23:51:45 -0800 Subject: [PATCH] feat: add support for account edition (#5) --- src/lib/accounts/accounts.spec.ts | 27 +++++++++++++++++++++++++++ src/lib/accounts/accounts.ts | 22 +++++++++++++++++++++- src/lib/accounts/accounts.types.ts | 2 ++ 3 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/lib/accounts/accounts.spec.ts b/src/lib/accounts/accounts.spec.ts index 280d11d..1337cb3 100644 --- a/src/lib/accounts/accounts.spec.ts +++ b/src/lib/accounts/accounts.spec.ts @@ -73,4 +73,31 @@ describe('Accounts', () => { }, ) }) + + it('gets an account edition', async () => { + const data = { + response: 'PERSONAL', + } + jest.spyOn(mockAxios, 'get').mockResolvedValue({ data }) + const res = await accounts.getAccountEdition('1') + expect(res).toEqual('PERSONAL') + expect(mockAxios.get).toHaveBeenCalledWith('/admin/v1/billing/edition', { + params: { account_id: '1' }, + }) + }) + + it('sets an account edition', async () => { + jest.spyOn(mockAxios, 'post').mockResolvedValue({ data: {} }) + await accounts.setAccountEdition('1', 'ENTERPRISE') + expect(mockAxios.post).toHaveBeenCalledWith( + '/admin/v1/billing/edition', + {}, + { + params: { + account_id: '1', + edition: 'ENTERPRISE', + }, + }, + ) + }) }) diff --git a/src/lib/accounts/accounts.ts b/src/lib/accounts/accounts.ts index 299b36a..7fe7422 100644 --- a/src/lib/accounts/accounts.ts +++ b/src/lib/accounts/accounts.ts @@ -1,5 +1,5 @@ import { AxiosInstance } from 'axios' -import { Account, CreateAccount } from './accounts.types' +import { Account, AccountEdition, CreateAccount } from './accounts.types' export class Accounts { constructor(private readonly httpAgent: AxiosInstance) {} @@ -19,6 +19,26 @@ export class Accounts { return accounts.find((account) => account.name === name) } + async getAccountEdition(accountId: string) { + const { data: res } = await this.httpAgent.get('/admin/v1/billing/edition', { + params: { account_id: accountId }, + }) + return res.response + } + + async setAccountEdition(accountId: string, edition: AccountEdition) { + await this.httpAgent.post( + '/admin/v1/billing/edition', + {}, + { + params: { + account_id: accountId, + edition, + }, + }, + ) + } + async create(account: CreateAccount): Promise { const { data: res } = await this.httpAgent.post( '/accounts/v1/account/create', diff --git a/src/lib/accounts/accounts.types.ts b/src/lib/accounts/accounts.types.ts index c219e9d..f5b83b9 100644 --- a/src/lib/accounts/accounts.types.ts +++ b/src/lib/accounts/accounts.types.ts @@ -7,3 +7,5 @@ export interface Account { export interface CreateAccount { name: string } + +export type AccountEdition = 'PERSONAL' | 'ENTERPRISE' | 'BUSINESS' | 'PLATFORM' | 'BEYOND'