feat: add comprehensive tests and samples for host and user rights endpoints
- Added GraphQL sample queries and mutations for host and user rights endpoints in the 'docs' directory. - Implemented unit tests for all remaining GraphQL endpoints, including hosts, devices, host groups, locations, and user permissions. - Created dedicated integration tests for host and user rights workflows, utilizing the new sample files. - Fixed a bug in 'HostImporter.getHostGroupHierarchyNames' to correctly process and sort nested host group hierarchies. - Refined Zabbix API mocking in tests to improve reliability and support path-based routing. - Verified all 38 tests across 11 suites pass successfully.
This commit is contained in:
parent
a3ed4886a3
commit
fdfd5f1e0e
14 changed files with 729 additions and 6 deletions
49
src/test/misc_resolvers.test.ts
Normal file
49
src/test/misc_resolvers.test.ts
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
|
||||
import {createResolvers} from "../api/resolvers.js";
|
||||
import {zabbixAPI} from "../datasources/zabbix-api.js";
|
||||
|
||||
// Mocking ZabbixAPI
|
||||
jest.mock("../datasources/zabbix-api.js", () => ({
|
||||
zabbixAPI: {
|
||||
executeRequest: jest.fn(),
|
||||
post: jest.fn()
|
||||
}
|
||||
}));
|
||||
|
||||
describe("Miscellaneous Resolvers", () => {
|
||||
let resolvers: any;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
resolvers = createResolvers();
|
||||
});
|
||||
|
||||
test("apiVersion query", async () => {
|
||||
const result = await resolvers.Query.apiVersion();
|
||||
expect(typeof result).toBe("string");
|
||||
});
|
||||
|
||||
test("zabbixVersion query", async () => {
|
||||
(zabbixAPI.post as jest.Mock).mockResolvedValueOnce({ result: "7.0.0" });
|
||||
const result = await resolvers.Query.zabbixVersion();
|
||||
expect(zabbixAPI.post).toHaveBeenCalledWith("apiinfo.version", expect.anything());
|
||||
});
|
||||
|
||||
test("login query", async () => {
|
||||
(zabbixAPI.post as jest.Mock).mockResolvedValueOnce("mock-token");
|
||||
const result = await resolvers.Query.login(null, { username: "admin", password: "password" });
|
||||
expect(result).toBe("mock-token");
|
||||
expect(zabbixAPI.post).toHaveBeenCalledWith("user.login", expect.objectContaining({
|
||||
body: expect.objectContaining({
|
||||
params: { username: "admin", password: "password" }
|
||||
})
|
||||
}));
|
||||
});
|
||||
|
||||
test("logout query", async () => {
|
||||
(zabbixAPI.post as jest.Mock).mockResolvedValueOnce(true);
|
||||
const result = await resolvers.Query.logout(null, null, { zabbixAuthToken: "token" });
|
||||
expect(result).toBe(true);
|
||||
expect(zabbixAPI.post).toHaveBeenCalledWith("user.logout", expect.anything());
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue