@mediarithmics/plugins-nodejs-sdk
Version:
This is the mediarithmics nodejs to help plugin developers bootstrapping their plugin without having to deal with most of the plugin boilerplate
64 lines • 3.12 kB
JavaScript
"use strict";
/* eslint-disable @typescript-eslint/ban-ts-comment */
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const sinon_1 = __importDefault(require("sinon"));
const winston_1 = __importDefault(require("winston"));
const StatsClient_1 = require("./StatsClient");
const delay = (interval) => new Promise((resolve) => setTimeout(resolve, interval));
describe('statsClient', () => {
let statsClient;
const logger = winston_1.default.createLogger({
format: winston_1.default.format.simple(),
transports: [new winston_1.default.transports.Console()],
level: 'debug',
});
beforeEach(() => {
statsClient = StatsClient_1.StatsClient.init({
timerInMs: 50,
logger,
});
});
afterEach(() => {
// @ts-ignore
clearInterval(statsClient.interval);
});
it('ok', async () => {
// @ts-ignore
const spyFnIncr = sinon_1.default.spy(statsClient.client, 'increment');
// @ts-ignore
const spyFnGauge = sinon_1.default.spy(statsClient.client, 'gauge');
statsClient.addOrUpdateMetrics({
metrics: {
processed_users: { type: StatsClient_1.MetricsType.INCREMENT, value: 4, tags: { datamart_id: '4521' } },
users_with_mobile_id_count: { type: StatsClient_1.MetricsType.GAUGE, value: 1, tags: { datamart_id: '4521' } },
},
});
await delay(75);
(0, chai_1.expect)(spyFnIncr.callCount).to.be.eq(1);
(0, chai_1.expect)(spyFnIncr.getCall(0).args).to.be.eqls(['processed_users', 4, { datamart_id: '4521' }]);
(0, chai_1.expect)(spyFnGauge.callCount).to.be.eq(1);
(0, chai_1.expect)(spyFnGauge.getCall(0).args).to.be.eqls(['users_with_mobile_id_count', 1, { datamart_id: '4521' }]);
await delay(50);
statsClient.addOrUpdateMetrics({
metrics: {
processed_users: { type: StatsClient_1.MetricsType.INCREMENT, value: 2, tags: { datamart_id: '4521' } },
users_with_mobile_id_count: { type: StatsClient_1.MetricsType.GAUGE, value: 1, tags: { datamart_id: '4521' } },
},
});
statsClient.addOrUpdateMetrics({
metrics: { apiCallsError: { type: StatsClient_1.MetricsType.INCREMENT, value: 3, tags: { statusCode: '500' } } },
});
await delay(25);
(0, chai_1.expect)(spyFnIncr.callCount).to.be.eq(4);
(0, chai_1.expect)(spyFnIncr.getCall(2).args).to.be.eqls(['processed_users', 2, { datamart_id: '4521' }]);
(0, chai_1.expect)(spyFnIncr.getCall(3).args).to.be.eqls(['apiCallsError', 3, { statusCode: '500' }]);
(0, chai_1.expect)(spyFnGauge.callCount).to.be.eq(3);
(0, chai_1.expect)(spyFnGauge.getCall(2).args).to.be.eqls(['users_with_mobile_id_count', 2, { datamart_id: '4521' }]);
await delay(100);
});
});
//# sourceMappingURL=StatsClient.spec.js.map