Skip to content

Commit

Permalink
Use spy instead of new argument
Browse files Browse the repository at this point in the history
  • Loading branch information
zoltanbedi committed Jun 13, 2024
1 parent f383490 commit ff940a3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@ import { ZabbixAPIConnector } from './zabbixAPIConnector';

describe('Zabbix API connector', () => {
describe('getProxies function', () => {
beforeAll(() => {
jest.spyOn(ZabbixAPIConnector.prototype, 'initVersion').mockResolvedValue('');
});

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');
const zabbixAPIConnector = new ZabbixAPIConnector(true, true, 123);
zabbixAPIConnector.version = '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');
const zabbixAPIConnector = new ZabbixAPIConnector(true, true, 123);
zabbixAPIConnector.version = '6.0.0';
zabbixAPIConnector.request = jest.fn();

zabbixAPIConnector.getProxies();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class ZabbixAPIConnector {
getVersionPromise: Promise<string>;
datasourceId: number;

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

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

this.version = zabbixVersion || null;

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

Expand Down

0 comments on commit ff940a3

Please sign in to comment.