Skip to content

Commit b0e92ff

Browse files
added edge cases - the response structure is different
Signed-off-by: [email protected] <[email protected]>
1 parent f79e0eb commit b0e92ff

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

common/utils/QueryUtils.test.ts

+32
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,36 @@ describe('retrieveQueryById - Fetch Query Record by ID from API', () => {
6464

6565
expect(result).toBeNull();
6666
});
67+
it('should return null if API response is missing the response field', async () => {
68+
mockCore.http.get.mockResolvedValue({});
69+
70+
const result = await retrieveQueryById(mockCore, undefined, testStart, testEnd, testId);
71+
72+
expect(result).toBeNull();
73+
});
74+
75+
it('should return null if API response contains an unexpected structure', async () => {
76+
mockCore.http.get.mockResolvedValue({ unexpectedKey: {} });
77+
78+
const result = await retrieveQueryById(mockCore, undefined, testStart, testEnd, testId);
79+
80+
expect(result).toBeNull();
81+
});
82+
83+
it('should return null if API request fails', async () => {
84+
mockCore.http.get.mockRejectedValue(new Error('API error'));
85+
86+
const result = await retrieveQueryById(mockCore, undefined, testStart, testEnd, testId);
87+
88+
expect(result).toBeNull();
89+
});
90+
91+
it('should handle cases where API returns an empty object instead of expected response structure', async () => {
92+
mockCore.http.get.mockResolvedValue({});
93+
94+
const result = await retrieveQueryById(mockCore, undefined, testStart, testEnd, testId);
95+
96+
expect(result).toBeNull();
97+
});
98+
6799
});

0 commit comments

Comments
 (0)