diff --git a/package-lock.json b/package-lock.json index 5984b0e..6524893 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@dimo-network/dimo-node-sdk", - "version": "1.1.6", + "version": "1.1.7", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@dimo-network/dimo-node-sdk", - "version": "1.1.6", + "version": "1.1.7", "license": "Apache-2.0", "dependencies": { "axios": "^1.6.7", diff --git a/package.json b/package.json index 0aa4e2f..3be13b4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dimo-network/dimo-node-sdk", - "version": "1.1.6", + "version": "1.1.7", "description": "DIMO SDK for JavaScript", "main": "dist/index.js", "author": "James Li", diff --git a/src/graphql/Query.test.ts b/src/graphql/Query.test.ts new file mode 100644 index 0000000..41f0e02 --- /dev/null +++ b/src/graphql/Query.test.ts @@ -0,0 +1,53 @@ +import axios from 'axios'; +import { CustomQuery, Query } from './Query'; // Import the Query function to be tested +import { DimoError } from '../errors'; +import { DimoEnvironment } from '../environments'; + +const RESOURCE = { + method: 'POST', + path: '', + queryParams: { param1: true }, +}; +const PARAM = { query: `{ + vehicles (first:10) { + totalCount + } +}`}; + +describe('Query Function', () => { + test('Valid API Call - Identity API Server is up and returning data', async () => { + jest.spyOn(axios, 'request').mockResolvedValue({ query: `{ + vehicles (first:10) { + totalCount + } + }`}); + + const devResponse = await CustomQuery(RESOURCE, DimoEnvironment.Dev.Identity, PARAM); + const prodResponse = await CustomQuery(RESOURCE, DimoEnvironment.Production.Identity, PARAM); + + // Assertion - Check if the response data is defined + expect(devResponse.data).toBeDefined(); + expect(prodResponse.data).toBeDefined(); + }); + + test('Missing Required Query Parameter - Throws Error', async () => { + // Mock input data with missing required query parameter + const devResource = { + Query: 'POST', + path: '', + queryParams: { expectedParam: true }, + }; + const prodResource = { + Query: 'POST', + path: '', + queryParams: { expectedParam: true }, + } + const params = { unexpectedParam: 'value1' }; + + // Call the Query function and expect it to throw an error + await expect(Query(devResource, DimoEnvironment.Dev.Identity, params)).rejects.toThrow(DimoError); + await expect(Query(prodResource, DimoEnvironment.Production.Identity, params)).rejects.toThrow(DimoError); + await expect(Query(devResource, DimoEnvironment.Dev.Telemetry, params)).rejects.toThrow(DimoError); + await expect(Query(prodResource, DimoEnvironment.Production.Telemetry, params)).rejects.toThrow(DimoError); + }); +});