From 25342f7b330e9816cbe538cfba15009dd2aaf2d5 Mon Sep 17 00:00:00 2001 From: Lena Haraldseid Date: Fri, 22 Sep 2023 10:43:19 +0200 Subject: [PATCH 1/4] test: add failing test for api validation --- nrfcloud/apiClient.spec.ts | 74 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 nrfcloud/apiClient.spec.ts diff --git a/nrfcloud/apiClient.spec.ts b/nrfcloud/apiClient.spec.ts new file mode 100644 index 000000000..50bb80376 --- /dev/null +++ b/nrfcloud/apiClient.spec.ts @@ -0,0 +1,74 @@ +import { validateWithTypeBox } from '@hello.nrfcloud.com/proto' +import { AccountInfo } from './apiClient.js' + +describe('apiClient()', () => { + it('should validate enterprice 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) + }) +}) From bf5f7b93e98cda6e5dafbfe4a7bb01130d1b46c8 Mon Sep 17 00:00:00 2001 From: Lena Haraldseid Date: Fri, 22 Sep 2023 10:46:25 +0200 Subject: [PATCH 2/4] fix: update AccountInfo schema Update missing properties in the schema: currentMonthCosts, name, serviceKeys --- nrfcloud/apiClient.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/nrfcloud/apiClient.ts b/nrfcloud/apiClient.ts index 653c0b71c..ba1d22a7b 100644 --- a/nrfcloud/apiClient.ts +++ b/nrfcloud/apiClient.ts @@ -96,7 +96,7 @@ const Page = (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({ @@ -114,17 +114,29 @@ const AccountInfo = Type.Object({ Type.Literal('Messages'), Type.Literal('SCELL'), Type.Literal('MCELL'), + Type.Literal('AGPS'), ]), total: Type.Number(), // e.g. 0.9 }), ), currentMonthTotalCost: Type.Number(), // e.g. 2.73 - name: Type.Union([Type.Literal('PRO'), Type.Literal('DEVELOPER')]), + name: Type.Union([ + Type.Literal('PRO'), + Type.Literal('DEVELOPER'), + Type.Literal('ENTERPRISE'), + ]), proxyUsageDeclarations: Type.Object({ AGPS: Type.Number(), // e.g. 0 GROUND_FIX: Type.Number(), // e.g. 200 PGPS: Type.Number(), // e.g. 0 }), + serviceKeys: Type.Array( + Type.Object({ + createdAt: Type.String(), + enabled: Type.Boolean(), + service: Type.String(), + }), + ), }), role: Type.Union([ Type.Literal('owner'), From d3c73bc1719f91818dfe04e6df9b357c7f10e23b Mon Sep 17 00:00:00 2001 From: Lena Haraldseid Date: Fri, 22 Sep 2023 12:22:35 +0200 Subject: [PATCH 3/4] fix: remove validations that are not needed --- nrfcloud/apiClient.ts | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/nrfcloud/apiClient.ts b/nrfcloud/apiClient.ts index ba1d22a7b..e0f3752c2 100644 --- a/nrfcloud/apiClient.ts +++ b/nrfcloud/apiClient.ts @@ -104,39 +104,12 @@ export const AccountInfo = Type.Object({ 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'), - Type.Literal('AGPS'), - ]), - total: Type.Number(), // e.g. 0.9 - }), - ), currentMonthTotalCost: Type.Number(), // e.g. 2.73 - name: Type.Union([ - Type.Literal('PRO'), - Type.Literal('DEVELOPER'), - Type.Literal('ENTERPRISE'), - ]), proxyUsageDeclarations: Type.Object({ AGPS: Type.Number(), // e.g. 0 GROUND_FIX: Type.Number(), // e.g. 200 PGPS: Type.Number(), // e.g. 0 }), - serviceKeys: Type.Array( - Type.Object({ - createdAt: Type.String(), - enabled: Type.Boolean(), - service: Type.String(), - }), - ), }), role: Type.Union([ Type.Literal('owner'), From 0fa42e1bbc44f3e755e79cae7ca6dd7185446164 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lena=20Kr=C3=A5kevik=20Haraldseid?= <35926103+Lenakh97@users.noreply.github.com> Date: Fri, 22 Sep 2023 12:44:03 +0200 Subject: [PATCH 4/4] Update nrfcloud/apiClient.spec.ts Co-authored-by: Markus Tacker --- nrfcloud/apiClient.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nrfcloud/apiClient.spec.ts b/nrfcloud/apiClient.spec.ts index 50bb80376..174b8052a 100644 --- a/nrfcloud/apiClient.spec.ts +++ b/nrfcloud/apiClient.spec.ts @@ -2,7 +2,7 @@ import { validateWithTypeBox } from '@hello.nrfcloud.com/proto' import { AccountInfo } from './apiClient.js' describe('apiClient()', () => { - it('should validate enterprice plan API Client response', () => { + it('should validate enterprise plan API Client response', () => { const APIresponse = { mqttEndpoint: 'mqtt.nrfcloud.com', mqttTopicPrefix: 'prod/b8b26bc5-2814-4063-b4fa-83ecddb2fec7/',