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 nrfcloud/apiClient.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { validateWithTypeBox } from '@hello.nrfcloud.com/proto'
import { AccountInfo } from './apiClient.js'

describe('apiClient()', () => {
it('should validate enterprise plan API Client response', () => {
const APIresponse = {
mqttEndpoint: 'mqtt.nrfcloud.com',
mqttTopicPrefix: 'prod/b8b26bc5-2814-4063-b4fa-83ecddb2fec7/',
team: {
tenantId: 'b8b26bc5-2814-4063-b4fa-83ecddb2fec7',
name: 'XXX',
},
role: 'owner',
tags: [],
plan: {
name: 'ENTERPRISE',
proxyUsageDeclarations: {
AGPS: 0,
PGPS: 0,
GROUND_FIX: 0,
},
serviceKeys: [
{
service: 'ALL',
enabled: true,
createdAt: '2023-09-14T10:24:31.663Z',
},
],
currentMonthCosts: [
{
serviceId: 'Devices',
serviceDescription: 'Devices in your account',
quantity: 53,
price: 0.1,
total: 5.3,
},
{
serviceId: 'Messages',
serviceDescription: 'Device messages stored',
quantity: 70281,
price: 0.0001,
total: 7.03,
},
{
serviceId: 'AGPS',
serviceDescription: 'Assisted GPS Service: total requests',
quantity: 8,
price: 0.001,
total: 0.01,
},
{
serviceId: 'SCELL',
serviceDescription: 'Single-Cell Location Service: total requests',
quantity: 2684,
price: 0.001,
total: 2.68,
},
{
serviceId: 'MCELL',
serviceDescription: 'Multi-Cell Location Service: total requests',
quantity: 4505,
price: 0.002,
total: 9.01,
},
],
currentMonthTotalCost: 24.03,
},
}

const maybeData = validateWithTypeBox(AccountInfo)(APIresponse)

expect('errors' in maybeData).toBe(false)
})
})
17 changes: 1 addition & 16 deletions nrfcloud/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,30 +96,15 @@ const Page = <T extends TSchema>(Item: T) =>
})
const Devices = Page(Device)

const AccountInfo = Type.Object({
export const AccountInfo = Type.Object({
mqttEndpoint: Type.String(), // e.g. 'mqtt.nrfcloud.com'
mqttTopicPrefix: Type.String(), // e.g. 'prod/a0673464-e4e1-4b87-bffd-6941a012067b/',
team: Type.Object({
tenantId: Type.String(), // e.g. 'bbfe6b73-a46a-43ad-94bd-8e4b4a7847ce',
name: Type.String(), // e.g. 'hello.nrfcloud.com'
}),
plan: Type.Object({
currentMonthCosts: Type.Array(
Type.Object({
price: Type.Number(), // e.g. 0.1
quantity: Type.Number(), // e.g. 9
serviceDescription: Type.String(), // e.g. 'Devices in your account'
serviceId: Type.Union([
Type.Literal('Devices'),
Type.Literal('Messages'),
Type.Literal('SCELL'),
Type.Literal('MCELL'),
]),
total: Type.Number(), // e.g. 0.9
}),
),
currentMonthTotalCost: Type.Number(), // e.g. 2.73
name: Type.Union([Type.Literal('PRO'), Type.Literal('DEVELOPER')]),
proxyUsageDeclarations: Type.Object({
AGPS: Type.Number(), // e.g. 0
GROUND_FIX: Type.Number(), // e.g. 200
Expand Down