UNPKG

@stordata/vsphere-soapify

Version:

A NodeJS abstraction layer for the vSphere SOAP API

42 lines (32 loc) 1.1 kB
'use strict'; const fs = require('fs'), chai = require('chai'), nock = require('nock'); // Load chai plugins before(function() { chai.use(require('chai-datetime')); }); before(function() { this.loadXml = file => this.normalizeXml(fs.readFileSync(file, { encoding: 'utf-8' })); this.normalizeXml = xml => xml.replace(/^\s{2,}/gm, '').replace(/\s{2,}/g, ' ').replace(/\n/g, ''); this.mockSoapService = (version) => { const path = `${__dirname}/fixtures/${version}/wsdl`; fs.readdirSync(path).forEach((file) => { nock('https://url') .get(`/sdk/${file}`) .reply(200, () => fs.createReadStream(`${path}/${file}`)); }); }; this.mockSoapOperation = (version, operation) => { const path = `${__dirname}/fixtures/${version}`; nock('https://url') .post('/sdk', body => this.normalizeXml(body) === this.loadXml(`${path}/requests/${operation}.xml`)) .reply(200, this.loadXml(`${path}/responses/${operation}.xml`)); }; }); afterEach(function(done) { if (nock.isDone()) { return done(); } done(nock.pendingMocks()); });