UNPKG

@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

53 lines 2.12 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.mockApi = exports.itFactory = void 0; require("mocha"); const chai_1 = require("chai"); const sinon_1 = __importDefault(require("sinon")); const supertest_1 = __importDefault(require("supertest")); const index_1 = require("../index"); const activityAnalyzer = { status: 'ok', data: { id: '1000', name: 'my analyzer', organisation_id: '1000', visit_analyzer_plugin_id: 1001, group_id: 'com.mediarithmics.visit-analyzer', artifact_id: 'default', }, }; const rpMockupGlobal = sinon_1.default.stub(); const mockApi = (uriPattern) => { return rpMockupGlobal.withArgs(sinon_1.default.match.has('uri', sinon_1.default.match((value) => value.match(uriPattern) !== null))); }; exports.mockApi = mockApi; mockApi(/\/v1\/activity_analyzers\/(.){1,10}/).returns(activityAnalyzer); const itFactory = (plugin, property, logLevel = 'info') => (name, input, output) => { it(name, function (done) { mockApi(/\/v1\/activity_analyzers\/(.){1,10}\/properties/).returns(property); const runner = new index_1.core.TestingPluginRunner(plugin, rpMockupGlobal); void (0, supertest_1.default)(runner.plugin.app) .put('/v1/log_level') .send({ level: logLevel }) .end((err, res) => { (0, chai_1.expect)(res.status).to.equal(200); void (0, supertest_1.default)(runner.plugin.app) .post('/v1/activity_analysis') .send(input) .end((err, res) => { (0, chai_1.expect)(res.status).to.eq(200); (0, chai_1.expect)(JSON.parse(res.text)).to.be.deep.equal(output); done(); }); }); afterEach(function () { runner.plugin.pluginCache.clear(); }); }); }; exports.itFactory = itFactory; //# sourceMappingURL=ActivityAnalyzerTestHelper.js.map