-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9ba95b0
commit 94bad6b
Showing
3 changed files
with
56 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); |