Skip to content

Commit

Permalink
feat: add support for account edition (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
santese committed Jan 26, 2023
1 parent 14c1cb7 commit 6c2fde1
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
27 changes: 27 additions & 0 deletions src/lib/accounts/accounts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
},
)
})
})
22 changes: 21 additions & 1 deletion src/lib/accounts/accounts.ts
Original file line number Diff line number Diff line change
@@ -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) {}
Expand All @@ -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<Account> {
const { data: res } = await this.httpAgent.post(
'/accounts/v1/account/create',
Expand Down
2 changes: 2 additions & 0 deletions src/lib/accounts/accounts.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ export interface Account {
export interface CreateAccount {
name: string
}

export type AccountEdition = 'PERSONAL' | 'ENTERPRISE' | 'BUSINESS' | 'PLATFORM' | 'BEYOND'

0 comments on commit 6c2fde1

Please sign in to comment.