UNPKG

@stordata/vsphere-soapify

Version:

A NodeJS abstraction layer for the vSphere SOAP API

114 lines (95 loc) 2.69 kB
/* eslint-disable max-classes-per-file */ 'use strict'; const { expect } = require('chai'), Client = require('../../client'), DynamicData = require('./DynamicData'); describe('The DynamicData class', function() { let client; beforeEach(function() { client = new Client('https://url/sdk'); }); describe('The constructor', function() { class DynamicDataSubclass extends DynamicData { static mappings() { return { a: 'xsd:string', b: 'xsd:boolean' }; } } it('should initialize the instance with a propertySet, when mappings is defined', function() { expect(new DynamicDataSubclass(client, { a: { attributes: { type: 'xsd:string' }, $value: 'val' }, b: { $value: 'true' } })).to.deep.equal({ a: 'val', b: true }); }); it('should initialize the instance with a propertySet, when mappings is defined, supporting a undefined source', function() { expect(new DynamicDataSubclass(client, undefined)).to.deep.equal({}); }); it('should initialize the instance with a propertySet, when mappings is defined, supporting undefined keys in source', function() { expect(new DynamicDataSubclass(client, { b: false })).to.deep.equal({ b: false }); }); }); describe('toXmlObject method', function() { class DynamicDataSubclass extends DynamicData { static mappings() { return { a: 'xsd:string', b: 'ManagedObjectReference', c: 'ClusterDasFdmHostState' }; } } it('should set the XML attributes', function() { expect(new DynamicDataSubclass(client).toXmlObject()).to.deep.equal({ attributes: { 'xsi:type': 'DynamicDataSubclass' } }); }); it('should set the XML attributes and iterate over the properties of the instance, recursively', function() { const instance = new DynamicDataSubclass(client, { a: 'str1', b: { attributes: { type: 'Folder' }, $value: 'myFolder' }, c: { state: 'myState' } }); expect(instance.toXmlObject()).to.deep.equal({ attributes: { 'xsi:type': 'DynamicDataSubclass' }, a: 'str1', b: { $value: 'myFolder', attributes: { type: 'Folder' } }, c: { attributes: { 'xsi:type': 'ClusterDasFdmHostState' }, state: 'myState' } }); }); }); });