UNPKG

@apidaze/node-red-contrib-apidaze

Version:
62 lines (47 loc) 1.5 kB
const { Apidaze } = require('@apidaze/node'); const test = require('ava'); const helper = require('node-red-node-test-helper'); const accountNode = require('../../nodes/config/config'); helper.init(require.resolve('node-red')); test.serial.before.cb((t) => { helper.startServer(t.end); }); test.serial.cb('should be loaded properly', (t) => { const node = accountNode; const nodeName = 'sample account'; const type = 'helper'; const flow = [{ id: 'n1', type: type, name: nodeName }]; helper.load(node, flow, () => { const n1 = helper.getNode('n1'); t.is(n1.name, nodeName); t.end(); }); }); test.serial.cb(`should have 'client' as an Apidaze instance`, (t) => { const apiKey = 'API_KEY'; const apiSecret = 'API_SECRET'; const sampleAccountNode = { id: 'n1', type: 'config', name: 'Apidaze account', }; const nodes = [accountNode]; const flow = [sampleAccountNode]; const creds = { [sampleAccountNode.id]: { apiKey, apiSecret }, }; helper.load(nodes, flow, creds, () => { const loadedAccountNode = helper.getNode(sampleAccountNode.id); t.is(loadedAccountNode.name, sampleAccountNode.name); t.true(loadedAccountNode.client instanceof Apidaze); t.is(loadedAccountNode.credentials.apiKey, apiKey); t.is(loadedAccountNode.credentials.apiSecret, apiSecret); t.end(); }); }); test.serial.afterEach(async () => { await helper.unload(); }); test.serial.after.cb((t) => { helper.stopServer(t.end); });