Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests
Browse files Browse the repository at this point in the history
zoltanbedi committed Jun 13, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 9d80323 commit f383490
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ZabbixAPIConnector } from './zabbixAPIConnector';

describe('Zabbix API connector', () => {
describe('getProxies function', () => {
it('should send the name parameter to the request when version is 7 or greater for the getProxies', async () => {
const zabbixAPIConnector = new ZabbixAPIConnector(true, true, 123, '7.0.0');
zabbixAPIConnector.request = jest.fn();

await zabbixAPIConnector.getProxies();
expect(zabbixAPIConnector.request).toHaveBeenCalledWith('proxy.get', { output: ['proxyid', 'name'] });
});

it('should send the host parameter when version is less than 7.0.0', () => {
const zabbixAPIConnector = new ZabbixAPIConnector(true, true, 123, '6.0.0');
zabbixAPIConnector.request = jest.fn();

zabbixAPIConnector.getProxies();
expect(zabbixAPIConnector.request).toHaveBeenCalledWith('proxy.get', { output: ['proxyid', 'host'] });
});
});
});
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ export class ZabbixAPIConnector {
getVersionPromise: Promise<string>;
datasourceId: number;

constructor(basicAuth: any, withCredentials: boolean, datasourceId: number) {
constructor(basicAuth: any, withCredentials: boolean, datasourceId: number, zabbixVersion?: string) {
this.datasourceId = datasourceId;
this.backendAPIUrl = `/api/datasources/${this.datasourceId}/resources/zabbix-api`;

@@ -37,6 +37,8 @@ export class ZabbixAPIConnector {
withCredentials: withCredentials,
};

this.version = zabbixVersion || null;

this.getTrend = this.getTrend_ZBXNEXT1193;
//getTrend = getTrend_30;

@@ -877,6 +879,7 @@ export class ZabbixAPIConnector {
const params = {
output: ['proxyid'],
};
// Before version 7.0.0 host was used, after - name
if (semver.lt(this.version, '7.0.0')) {
params.output.push('host');
} else {

0 comments on commit f383490

Please sign in to comment.