const DOMParser = require('xmldom').DOMParser; const XMLSerializer = require('xmldom').XMLSerializer; const settings = require('./settings'); var xmlTestProfile = undefined; beforeEach(() => { xmlTestProfile = new DOMParser().parseFromString(` _properties_ false _sonatype-snapshots_ false `); }); test('template should be read', () => { const template = settings.getSettingsTemplate(); expect(template).toBeDefined(); }); test('fillServers do nothing if no params', () => { const xml = new DOMParser().parseFromString(""); settings.fillServers(xml); const xmlStr = new XMLSerializer().serializeToString(xml); expect(xmlStr).toBe(""); }); test('fillServers one server', () => { const xml = new DOMParser().parseFromString(""); process.env['INPUT_SERVERS'] = '[{"id": "id1", "username": "username1", "password":"password1"}]'; settings.fillServers(xml); const xmlStr = new XMLSerializer().serializeToString(xml); expect(xmlStr).toBe("" + "id1username1password1" + ""); }); test('fillServers two servers', () => { const xml = new DOMParser().parseFromString(""); process.env['INPUT_SERVERS'] = '[{"id": "id1", "username": "username1", "password":"password1"},\ {"id": "id2", "username": "username2", "password":"password2"}]'; settings.fillServers(xml); const xmlStr = new XMLSerializer().serializeToString(xml); expect(xmlStr).toBe("" + "id1username1password1" + "id2username2password2" + ""); }); test('addSonatypeSnapshots activate', () => { process.env['INPUT_SONATYPE-SNAPSHOTS'] = "true"; settings.addSonatypeSnapshots(xmlTestProfile); const xmlStr = new XMLSerializer().serializeToString(xmlTestProfile); expect(xmlStr).toBe(` _properties_ false _sonatype-snapshots_ true `); }); test('fillProperties', () => { process.env['INPUT_PROPERTIES'] = '[{"propertyName1": "propertyValue1"}, {"propertyName2": "propertyValue2"}]'; settings.fillProperties(xmlTestProfile); const xmlStr = new XMLSerializer().serializeToString(xmlTestProfile); expect(xmlStr).toBe(` _properties_ true propertyValue1propertyValue2 _sonatype-snapshots_ false `); })