it('should append new children to XML document tree', function () { const configfile_cfg = new ConfigParser(configfile_xml); const platformJson = PlatformJson.load(plugins_dir, 'android'); const munger = new configChanges.PlatformMunger('android', temp, platformJson, pluginInfoProvider); munger.add_config_changes(configfile_cfg, true).save_all(); const am_xml = new et.ElementTree(et.XML(fs.readFileSync(path.join(temp, 'AndroidManifest.xml'), 'utf-8'))); const activity = am_xml.find('./application/activity[@android:name="com.foo.Bar"]'); expect(activity).toBeDefined(); expect(activity.attrib['android:label']).toEqual('@string/app_name'); });
describe( 'Coordinate merger', () => { it( 'removes duplicate coordinates', () => { expect( buttons.uniqueCoords( [ [ 1, 2 ], [ 2, 1 ], [ 1, 2 ], [ 1, 2 ] ] ) ).toEqual( [ [ 1, 2 ], [ 2, 1 ] ] ); expect( buttons.uniqueCoords( [] ) ).toEqual( [] ); expect( buttons.uniqueCoords( [ [ 1, 2 ] ] ) ).toEqual( [ [ 1, 2 ] ] ); } ); } );
it('should call pruneXMLRemove for every new config.xml config munge with mode \'remove\' it introduces', function () { const platformJson = PlatformJson.load(plugins_dir, 'android'); // var spy = spyOn(xml_helpers, 'pruneXMLRemove').andReturn(true); const munger = new configChanges.PlatformMunger('android', temp, platformJson); munger.add_config_changes(cfg, true).save_all(); const am_xml = new et.ElementTree(et.XML(fs.readFileSync(path.join(temp, 'AndroidManifest.xml'), 'utf-8'))); const sdk = am_xml.find('./uses-sdk'); expect(sdk).toBeDefined(); expect(sdk.attrib['android:maxSdkVersion']).toBeUndefined(); });
it('should be an unprocessable error with custom message and causes', function () { var e = new NspError(NspError.codes.UNPROCESSABLE, 'message', [ 'cause1', 'cause2' ]); expect(e).toEqual(jasmine.any(Error)); expect(e.name).toBe('NspError'); expect(e.code).toBe('UNPROCESSABLE'); expect(e.message).toBe('message'); expect(e.stack).toBeString(); expect(e.toString()).toBe('NspError: message'); expect(e.causes).toEqual([ 'cause1', 'cause2' ]); });
it('Test 019 : should map an empty directory', function () { mockFs.statMap[path.join(testRootDir, testSourceDir)] = testDirStats; mockFs.dirMap[path.join(testRootDir, testSourceDir)] = []; const dirMap = FileUpdater.mapDirectory(testRootDir, testSourceDir, ['**'], []); expect(Object.keys(dirMap)).toEqual(['']); expect(dirMap[''].subDir).toBe(testSourceDir); expect(dirMap[''].stats).toBe(testDirStats); });
it('should overwrite plugin config munge for every conflicting config.xml config munge', function () { install_plugin(editconfigplugin_two); const platformJson = PlatformJson.load(plugins_dir, 'android'); platformJson.addInstalledPluginToPrepareQueue('org.test.editconfigtest_two', {}, true, true); const munger = new configChanges.PlatformMunger('android', temp, platformJson, pluginInfoProvider); munger.process(plugins_dir); munger.add_config_changes(cfg, true).save_all(); const am_xml = new et.ElementTree(et.XML(fs.readFileSync(path.join(temp, 'AndroidManifest.xml'), 'utf-8'))); const sdk = am_xml.find('./uses-sdk'); expect(sdk).toBeDefined(); expect(sdk.attrib['android:targetSdkVersion']).toEqual('24'); });
it("getTargetHost should get Target host", () => { let result = getTargetHost("test.com"); expect(result).toBe("https://test.com"); result = getTargetHost("test.com", "21"); expect(result).toBe("https://test.com"); result = getTargetHost("", "21"); expect(result).toBe("https://mboxedge21.tt.omtrdc.net"); result = getTargetHost(null, null, "testclient"); expect(result).toBe("https://testclient.tt.omtrdc.net"); result = getTargetHost(null, null, "testclient", false); expect(result).toBe("http://testclient.tt.omtrdc.net"); });
it('Test 023 : should include files that match include globs', function () { mockFs.statMap[testSourceDir] = testDirStats; mockFs.dirMap[testSourceDir] = [testSourceFile, testSourceFile2]; mockFs.statMap[path.join(testSourceDir, testSourceFile)] = testFileStats; mockFs.statMap[path.join(testSourceDir, testSourceFile2)] = testFileStats; const dirMap = FileUpdater.mapDirectory('', testSourceDir, [testSourceFile], []); expect(Object.keys(dirMap).sort()).toEqual(['', testSourceFile]); expect(dirMap[''].subDir).toBe(testSourceDir); expect(dirMap[''].stats).toBe(testDirStats); expect(dirMap[testSourceFile].subDir).toBe(testSourceDir); expect(dirMap[testSourceFile].stats).toBe(testFileStats); });
it('Test 033 : should merge platform tags with the correct platform', function () { const testXml = et.XML('<widget><platform name="bar"><testElement testAttrib="value">testTEXT</testElement></platform></widget>'); const origCfg = et.tostring(dstXml); xml_helpers.mergeXml(testXml, dstXml, 'bar', true); expect(et.tostring(dstXml)).not.toEqual(origCfg); const testElement = dstXml.find('testElement'); expect(testElement).toBeDefined(); expect(testElement.attrib.testAttrib).toEqual('value'); expect(testElement.text).toEqual('testTEXT'); });
it('should be a 403 error', function () { var e = new HttpError(HttpError.statusCodes.FORBIDDEN, 'You cannot delete a Card'); expect(e).toEqual(jasmine.any(Error)); expect(e.name).toBe('HttpError'); expect(e.statusCode).toBe(403); expect(e.statusReason).toBe('Forbidden'); expect(e.message).toBe('You cannot delete a Card'); expect(e.causes).toBeEmptyArray(); expect(e.toString()).toBe('HttpError: You cannot delete a Card'); });
it('should be a 422 error with causes', function () { var causes = ['owner is read-only', 'uuid required']; var e = new HttpError(HttpError.statusCodes.UNPROCESSABLE_ENTITY, 'Validation error', causes); expect(e).toEqual(jasmine.any(Error)); expect(e.name).toBe('HttpError'); expect(e.statusCode).toBe(422); expect(e.statusReason).toBe('Unprocessable entity'); expect(e.message).toBe('Validation error'); expect(e.causes).toEqual(causes); expect(e.toString()).toBe('HttpError: Validation error'); });
it('should be a 415 error', function () { var e = new HttpError(HttpError.statusCodes.UNSUPPORTED_MEDIA_TYPE, 'Content-Type must be ' + 'application/json'); expect(e).toEqual(jasmine.any(Error)); expect(e.name).toBe('HttpError'); expect(e.statusCode).toBe(415); expect(e.statusReason).toBe('Unsupported media type'); expect(e.message).toBe('Content-Type must be application/json'); expect(e.causes).toBeEmptyArray(); expect(e.toString()).toBe('HttpError: Content-Type must be application/json'); });
it('should be a 400 error with a cause', function () { var cause = 'Unexpected character: \';\''; var e = new HttpError(HttpError.statusCodes.BAD_REQUEST, 'Invalid JSON', cause); expect(e).toEqual(jasmine.any(Error)); expect(e.name).toBe('HttpError'); expect(e.statusCode).toBe(400); expect(e.statusReason).toBe('Bad request'); expect(e.message).toBe('Invalid JSON'); expect(e.causes).toEqual([cause]); expect(e.toString()).toBe('HttpError: Invalid JSON'); });
it('should be a 500 error', function () { var e = new HttpError(HttpError.statusCodes.INTERNAL_SERVER_ERROR, 'Disk full'); expect(e).toEqual(jasmine.any(Error)); expect(e.name).toBe('HttpError'); expect(e.statusCode).toBe(500); expect(e.statusReason).toBe('Internal server error'); expect(e.message).toBe('Disk full'); expect(e.causes).toBeEmptyArray(); expect(e.toString()).toBe('HttpError: Disk full'); });