How to use license method in Jasmine-core

Best JavaScript code snippet using jasmine-core

core_license.js

Source:core_license.js Github

copy

Full Screen

1/**2 * Shopware 53 * Copyright (c) shopware AG4 *5 * According to our dual licensing model, this program can be used either6 * under the terms of the GNU Affero General Public License, version 3,7 * or under a proprietary license.8 *9 * The texts of the GNU Affero General Public License with an additional10 * permission and of our proprietary license can be found at and11 * in the LICENSE file you have received along with this program.12 *13 * This program is distributed in the hope that it will be useful,14 * but WITHOUT ANY WARRANTY; without even the implied warranty of15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the16 * GNU Affero General Public License for more details.17 *18 * "Shopware" is a registered trademark of shopware AG.19 * The licensing of the program under the AGPLv3 does not imply a20 * trademark license. Therefore any rights, title and interest in21 * our trademarks remain entirely with us.22 */23//{namespace name=backend/config/view/core_license}24/**25 * Shopware UI - Core-license management26 *27 * The customer is able to insert the shopware license data,28 * e.g. the shopware Core license key.29 *30 * If the license key is valid, the shopware backend icon is31 * switched accordingly and the license information is shown32 * to the customer.33 *34 */35//{block name="backend/config/view/form/core_license"}36Ext.define('Shopware.apps.Config.view.form.CoreLicense', {37 extend: 'Shopware.apps.Config.view.base.Form',38 alias: 'widget.config-form-corelicense',39 layout: 'anchor',40 bodyPadding: 20,41 /**42 * Unfilled license data object, used in case of43 * invalid license key check or license removal.44 */45 savedLicenseData: {46 'success': false,47 'message': '',48 'errorType': '',49 'licenseData': {50 'label': '',51 'module': '',52 'creation': '',53 'edition': '',54 'host': '',55 'type': '',56 'license': ''57 }58 },59 /**60 * The translatable label strings for license information.61 * Kept in seperate object to easier prevent interference with smarty compiler.62 */63 infoLabels: {64 heading: '{s name=info/heading}Add or change and validate your shopware license.{/s}',65 license: '{s name=info/license}License{/s}',66 error: '{s name=errors/common/heading}Error{/s}',67 registeredTo: '{s name=info/registeredTo}Registered to{/s}',68 createdAt: '{s name=info/createdAt}Created at{/s}'69 },70 /**71 * All known shopware edition css classes,72 * used when switching the backend icon.73 */74 editions: [75 'shopware-ce',76 'shopware-pe',77 'shopware-pp',78 'shopware-ee',79 'shopware-eb',80 'shopware-ec'81 ],82 /**83 * Used to keep the date format translatable for84 * different countries.85 */86 dateFormat: '{s name=date_format}m/d/Y{/s}',87 constructor: function(config) {88 var me = this;89 me.emptyLicenseData = me.savedLicenseData;90 Ext.Ajax.request({91 url: '{url controller="CoreLicense" action="loadSavedLicense"}',92 method: 'GET',93 async : false,94 success: function(result){95 me.savedLicenseData = Ext.decode(result.responseText);96 }97 });98 me.callParent(arguments);99 },100 getItems: function() {101 var me = this;102 me.licenseField = Ext.create('Ext.form.field.TextArea', {103 name: 'license',104 height: 250,105 width: '100%',106 anchor: '100%',107 fieldStyle: 'font: 13px monospace !important;',108 cols: 4,109 fieldLabel: '',110 supportText: ''111 });112 me.blockMessage = Shopware.Notification.createBlockMessage('', 'success');113 me.blockMessage.hide();114 /* {literal} */115 me.licenseStatus = Ext.create('Ext.Component', {116 tpl: new Ext.XTemplate(117 '<div style="text-align:left;width:100%;">' +118 '<p class="x-form-item-label">' +119 me.infoLabels.heading +120 '</p>' +121 '<br />'+122 '<div class="x-panel" style="width:100%;display:{display};">' +123 '<div style="height: 100px;">'+124 '<table style="width:400px;">' +125 '<tr>' +126 '<td>' + me.infoLabels.license + ':</td>' +127 '<td><b>{license}</b></td>' +128 '</tr>'+129 '<tr>' +130 '<td>' + me.infoLabels.registeredTo + ':</td>' +131 '<td>{host}</td>' +132 '</tr>'+133 '<tr>' +134 '<td>' + me.infoLabels.createdAt + ':</td>' +135 '<td>{[this.formatDate(values.licenseDate)]}</td>' +136 '</tr>'+137 '</table>'+138 '</div>' +139 '</div>' +140 '</div>',141 {142 formatDate: function(licenseDate) {143 var dt = Ext.Date.parse(licenseDate, 'Ymd');144 return Ext.Date.format(dt, me.dateFormat);145 }146 }147 ),148 data: {149 license: '',150 licenseDate: '',151 host: '',152 display: 'none'153 }154 });155 /* {/literal} */156 me.showLicenseData(me.savedLicenseData);157 return [158 me.blockMessage,159 me.licenseStatus,160 {161 xtype: 'fieldset',162 title: me.infoLabels.license,163 defaults: {164 anchor: '100%',165 labelWidth: 250,166 xtype: 'textfield'167 },168 items: [169 me.licenseField170 ]171 },172 {173 xtype: 'container',174 layout: {175 type: 'hbox',176 pack: 'end'177 },178 items: [179 {180 xtype: 'button',181 cls: 'small',182 text: '{s name=buttons/uninstallLicenseLabel}Uninstall{/s}',183 name: 'license-delete-button',184 handler: Ext.bind(me.handleUninstallButtonClick, me)185 },186 {187 xtype: 'button',188 cls: 'small primary',189 text: '{s name=buttons/addLicenseLabel}Save{/s}',190 name: 'license-set-button',191 handler: Ext.bind(me.setNewLicense, me)192 }193 ]194 }195 ];196 },197 /**198 * Displays a confirmation dialog before uninstallation takes place.199 * Triggered when the uninstall button is clicked.200 */201 handleUninstallButtonClick: function(){202 var me = this,203 licenseData = me.savedLicenseData.licenseData;204 // Check if a license is present205 if (!licenseData.host || licenseData.host.length === 0) {206 return;207 }208 Ext.MessageBox.confirm(209 '{s name=mesagebox/uninstall/title}Uninstallation confirmation{/s}',210 '{s name=mesagebox/uninstall/body}Are you sure you want to remove your license information from this shopware installation?{/s}',211 function (response) {212 if (response !== 'yes') {213 return;214 }215 me.uninstallLicense();216 });217 },218 /**219 * Deletes the license data from database via backend controller,220 * removes the license information content which is visible to the user221 * empty afterwards.222 */223 uninstallLicense: function () {224 var me = this,225 jsonData,226 licensePresent,227 licenseData = me.savedLicenseData.licenseData;228 Ext.Ajax.request({229 url: '{url controller="CoreLicense" action="uninstallLicense"}',230 method: 'GET',231 success: function (result) {232 jsonData = Ext.decode(result.responseText);233 licensePresent = licenseData.host && licenseData.host.length > 0;234 235 if (jsonData.success) {236 me.savedLicenseData = me.emptyLicenseData;237 me.switchEditionIcon('ce');238 me.licenseField.setValue('');239 if (licensePresent) {240 me.licenseStatus.update({241 license: '{s name=info/license/unlicensed}Not licensed{/s}',242 licenseDate: '',243 host: '',244 display: 'initial'245 });246 }247 me.blockMessage.hide();248 } else {249 Shopware.Notification.createGrowlMessage(250 '{s name=errors/common/heading}Error{/s}',251 '{s name=errors/common/common}An unknown error occured.{/s}',252 '{s name=errors/common/title}Core License{/s}'253 );254 }255 }256 });257 },258 /**259 * Tries to validate and set new license information provided260 * by the customer.261 */262 setNewLicense: function(){263 var me = this,264 license = me.licenseField.getValue().trim();265 me.licenseField.setDisabled(true);266 if(!license){267 Shopware.Notification.createGrowlMessage(268 '{s name=errors/common/heading}Error{/s}',269 '{s name=errors/license/common}License key could not be validated{/s}',270 '{s name=errors/common/title}Core License{/s}'271 );272 me.licenseField.setDisabled(false);273 return;274 }275 me.checkLicense(license);276 me.licenseField.setDisabled(false);277 },278 /**279 * Performs a license validation request and280 * updates the license information on success,281 * shows error otherwise.282 *283 * @string licenseString284 */285 checkLicense: function(licenseString){286 var me = this,287 jsonData;288 Ext.Ajax.request({289 url: '{url controller="CoreLicense" action="checkLicense"}',290 method: 'POST',291 params: {292 licenseString: licenseString293 },294 success: function (result) {295 jsonData = Ext.decode(result.responseText);296 if (jsonData.success === true) {297 me.showLicenseData(jsonData);298 } else {299 Shopware.Notification.createGrowlMessage(300 '{s name=errors/common/heading}Error{/s}',301 me.getErrorMessage(jsonData.errorType),302 '{s name=errors/common/title}Core License{/s}'303 );304 }305 }306 });307 },308 /**309 * Performs the actual task of license information display by310 * updating the ExtJs xTemplate data using the provided object.311 *312 * @object jsonData313 */314 showLicenseData: function (jsonData) {315 var me = this;316 if (jsonData.errorType && jsonData.errorType == 'LicenseHostException') {317 me.switchEditionIcon('ce');318 me.licenseStatus.update({319 license: jsonData.licenseData.label,320 licenseDate: jsonData.licenseData.creation,321 host: jsonData.licenseData.host,322 display: 'initial'323 });324 me.licenseField.setValue(jsonData.licenseData.license);325 me.setBlockMessage('{s name=errors/license/host}License key is not valid for domain{/s}', 'error');326 me.blockMessage.show();327 return;328 }329 if(jsonData.success === false){330 me.savedLicenseData = me.emptyLicenseData;331 me.licenseStatus.update({332 license: '',333 licenseDate: '',334 host: '',335 display: 'none'336 });337 me.blockMessage.hide();338 return;339 }340 me.savedLicenseData = jsonData;341 me.licenseField.setValue(jsonData.licenseData.license);342 me.licenseStatus.update({343 license: jsonData.licenseData.label,344 licenseDate: jsonData.licenseData.creation,345 host: jsonData.licenseData.host,346 display: 'initial'347 });348 me.setBlockMessage('{s name=message/validLicense}Your license was successfully validated{/s}', 'success');349 me.blockMessage.show();350 me.switchEditionIcon(jsonData.licenseData.edition);351 },352 /**353 * Update the blockmessage content and type.354 * Doesn't change the blockmessage visibility.355 *356 * @param text357 * @param type358 */359 setBlockMessage: function (text, type) {360 var me = this,361 inner = me.blockMessage.items.first();362 inner.update({363 text: text,364 type: type365 });366 Ext.each(['notice', 'error', 'success'], function (element) {367 inner.removeCls(element);368 });369 inner.addCls(type);370 },371 /**372 * Switches the shopware icon in the backend according373 * to the string provided. If empty parameter is provided,374 * shopware community edition is assumed.375 *376 * @string edition377 */378 switchEditionIcon: function (edition) {379 var me = this,380 classes = Ext.getBody().getAttribute('class').split(" ");381 if(!edition){382 edition = 'ce';383 }384 classes.forEach(function (element) {385 if (Ext.Array.indexOf(me.editions, element) > -1) {386 Ext.getBody().removeCls(element);387 Ext.getBody().addCls('shopware-' + edition.toLowerCase());388 }389 });390 },391 /**392 * Translates an error string from the backend controller to a more393 * human readable and translatable error message.394 * 395 * @string errorType396 * @returns string397 */398 getErrorMessage: function (errorType) {399 var me= this,400 message;401 switch (errorType) {402 case 'LicenseProductKeyException':403 message = '{s name=errors/license/product_key}License key does not match a commercial shopware edition{/s}';404 break;405 case 'LicenseHostException':406 message = '{s name=errors/license/host}License key is not valid for domain{/s}';407 break;408 default:409 message = '{s name=errors/license/common}License key could not be validated{/s}';410 }411 return message;412 }413});...

Full Screen

Full Screen

xpack_info_license.test.js

Source:xpack_info_license.test.js Github

copy

Full Screen

1/*2 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one3 * or more contributor license agreements. Licensed under the Elastic License;4 * you may not use this file except in compliance with the Elastic License.5 */6import { licensingMock } from '../../../../../plugins/licensing/server/mocks';7import { XPackInfoLicense } from './xpack_info_license';8function getXPackInfoLicense(getRawLicense) {9 return new XPackInfoLicense(getRawLicense);10}11describe('XPackInfoLicense', () => {12 const xpackInfoLicenseUndefined = getXPackInfoLicense(() => {});13 let xpackInfoLicense;14 let getRawLicense;15 beforeEach(() => {16 getRawLicense = jest.fn();17 xpackInfoLicense = getXPackInfoLicense(getRawLicense);18 });19 test('getUid returns uid field', () => {20 const uid = 'abc123';21 getRawLicense.mockReturnValue(licensingMock.createLicense({ license: { uid } }));22 expect(xpackInfoLicense.getUid()).toBe(uid);23 expect(getRawLicense).toHaveBeenCalledTimes(1);24 expect(xpackInfoLicenseUndefined.getUid()).toBe(undefined);25 });26 test('isActive returns true if status is active', () => {27 getRawLicense.mockReturnValue(licensingMock.createLicense({ license: { status: 'active' } }));28 expect(xpackInfoLicense.isActive()).toBe(true);29 expect(getRawLicense).toHaveBeenCalledTimes(1);30 });31 test('isActive returns false if status is not active', () => {32 getRawLicense.mockReturnValue(licensingMock.createLicense({ license: { status: 'aCtIvE' } })); // needs to match exactly33 expect(xpackInfoLicense.isActive()).toBe(false);34 expect(getRawLicense).toHaveBeenCalledTimes(1);35 expect(xpackInfoLicenseUndefined.isActive()).toBe(false);36 });37 test('getExpiryDateInMillis returns expiry_date_in_millis', () => {38 getRawLicense.mockReturnValue(39 licensingMock.createLicense({ license: { expiryDateInMillis: 123 } })40 );41 expect(xpackInfoLicense.getExpiryDateInMillis()).toBe(123);42 expect(getRawLicense).toHaveBeenCalledTimes(1);43 expect(xpackInfoLicenseUndefined.getExpiryDateInMillis()).toBe(undefined);44 });45 test('isOneOf returns true of the mode includes one of the types', () => {46 getRawLicense.mockReturnValue(licensingMock.createLicense({ license: { mode: 'platinum' } }));47 expect(xpackInfoLicense.isOneOf('platinum')).toBe(true);48 expect(getRawLicense).toHaveBeenCalledTimes(1);49 expect(xpackInfoLicense.isOneOf(['platinum'])).toBe(true);50 expect(getRawLicense).toHaveBeenCalledTimes(2);51 expect(xpackInfoLicense.isOneOf(['gold', 'platinum'])).toBe(true);52 expect(getRawLicense).toHaveBeenCalledTimes(3);53 expect(xpackInfoLicense.isOneOf(['platinum', 'gold'])).toBe(true);54 expect(getRawLicense).toHaveBeenCalledTimes(4);55 expect(xpackInfoLicense.isOneOf(['basic', 'gold'])).toBe(false);56 expect(getRawLicense).toHaveBeenCalledTimes(5);57 expect(xpackInfoLicense.isOneOf(['basic'])).toBe(false);58 expect(getRawLicense).toHaveBeenCalledTimes(6);59 expect(xpackInfoLicenseUndefined.isOneOf(['platinum', 'gold'])).toBe(false);60 });61 test('getType returns the type', () => {62 getRawLicense.mockReturnValue(licensingMock.createLicense({ license: { type: 'basic' } }));63 expect(xpackInfoLicense.getType()).toBe('basic');64 expect(getRawLicense).toHaveBeenCalledTimes(1);65 getRawLicense.mockReturnValue(licensingMock.createLicense({ license: { type: 'gold' } }));66 expect(xpackInfoLicense.getType()).toBe('gold');67 expect(getRawLicense).toHaveBeenCalledTimes(2);68 expect(xpackInfoLicenseUndefined.getType()).toBe(undefined);69 });70 test('getMode returns the mode', () => {71 getRawLicense.mockReturnValue(licensingMock.createLicense({ license: { mode: 'basic' } }));72 expect(xpackInfoLicense.getMode()).toBe('basic');73 expect(getRawLicense).toHaveBeenCalledTimes(1);74 getRawLicense.mockReturnValue(licensingMock.createLicense({ license: { mode: 'gold' } }));75 expect(xpackInfoLicense.getMode()).toBe('gold');76 expect(getRawLicense).toHaveBeenCalledTimes(2);77 expect(xpackInfoLicenseUndefined.getMode()).toBe(undefined);78 });79 test('isActiveLicense returns the true if active and typeChecker matches', () => {80 const expectAbc123 = (type) => type === 'abc123';81 getRawLicense.mockReturnValue(82 licensingMock.createLicense({ license: { status: 'active', mode: 'abc123' } })83 );84 expect(xpackInfoLicense.isActiveLicense(expectAbc123)).toBe(true);85 expect(getRawLicense).toHaveBeenCalledTimes(1);86 getRawLicense.mockReturnValue(87 licensingMock.createLicense({ license: { status: 'NOTactive', mode: 'abc123' } })88 );89 expect(xpackInfoLicense.isActiveLicense(expectAbc123)).toBe(false);90 expect(getRawLicense).toHaveBeenCalledTimes(2);91 getRawLicense.mockReturnValue(92 licensingMock.createLicense({ license: { status: 'NOTactive', mode: 'NOTabc123' } })93 );94 expect(xpackInfoLicense.isActiveLicense(expectAbc123)).toBe(false);95 expect(getRawLicense).toHaveBeenCalledTimes(3);96 getRawLicense.mockReturnValue(97 licensingMock.createLicense({ license: { status: 'active', mode: 'NOTabc123' } })98 );99 expect(xpackInfoLicense.isActiveLicense(expectAbc123)).toBe(false);100 expect(getRawLicense).toHaveBeenCalledTimes(4);101 expect(xpackInfoLicenseUndefined.isActive(expectAbc123)).toBe(false);102 });103 test('isBasic returns the true if active and basic', () => {104 getRawLicense.mockReturnValue(105 licensingMock.createLicense({ license: { status: 'active', mode: 'basic' } })106 );107 expect(xpackInfoLicense.isBasic()).toBe(true);108 expect(getRawLicense).toHaveBeenCalledTimes(1);109 getRawLicense.mockReturnValue(110 licensingMock.createLicense({ license: { status: 'NOTactive', mode: 'gold' } })111 );112 expect(xpackInfoLicense.isBasic()).toBe(false);113 expect(getRawLicense).toHaveBeenCalledTimes(2);114 getRawLicense.mockReturnValue(115 licensingMock.createLicense({ license: { status: 'NOTactive', mode: 'trial' } })116 );117 expect(xpackInfoLicense.isBasic()).toBe(false);118 expect(getRawLicense).toHaveBeenCalledTimes(3);119 getRawLicense.mockReturnValue(120 licensingMock.createLicense({ license: { status: 'active', mode: 'platinum' } })121 );122 expect(xpackInfoLicense.isBasic()).toBe(false);123 expect(getRawLicense).toHaveBeenCalledTimes(4);124 expect(xpackInfoLicenseUndefined.isBasic()).toBe(false);125 });126 test('isNotBasic returns the true if active and not basic', () => {127 getRawLicense.mockReturnValue(128 licensingMock.createLicense({ license: { status: 'active', mode: 'platinum' } })129 );130 expect(xpackInfoLicense.isNotBasic()).toBe(true);131 expect(getRawLicense).toHaveBeenCalledTimes(1);132 getRawLicense.mockReturnValue(133 licensingMock.createLicense({ license: { status: 'NOTactive', mode: 'gold' } })134 );135 expect(xpackInfoLicense.isNotBasic()).toBe(false);136 expect(getRawLicense).toHaveBeenCalledTimes(2);137 getRawLicense.mockReturnValue(138 licensingMock.createLicense({ license: { status: 'NOTactive', mode: 'trial' } })139 );140 expect(xpackInfoLicense.isNotBasic()).toBe(false);141 expect(getRawLicense).toHaveBeenCalledTimes(3);142 getRawLicense.mockReturnValue(143 licensingMock.createLicense({ license: { status: 'active', mode: 'basic' } })144 );145 expect(xpackInfoLicense.isNotBasic()).toBe(false);146 expect(getRawLicense).toHaveBeenCalledTimes(4);147 expect(xpackInfoLicenseUndefined.isNotBasic()).toBe(false);148 });...

Full Screen

Full Screen

PluginOptionsReader.js

Source:PluginOptionsReader.js Github

copy

Full Screen

1"use strict";2Object.defineProperty(exports, "__esModule", { value: true });3exports.PluginOptionsReader = void 0;4var PluginOptionsReader = /** @class */ (function () {5 function PluginOptionsReader(context) {6 this.context = context;7 }8 PluginOptionsReader.prototype.readOptions = function (options) {9 var licenseInclusionTest = options.licenseInclusionTest || (function () { return true; });10 var unacceptableLicenseTest = options.unacceptableLicenseTest || (function () { return false; });11 var perChunkOutput = options.perChunkOutput === undefined || options.perChunkOutput;12 var licenseTemplateDir = options.licenseTemplateDir;13 var licenseTextOverrides = options.licenseTextOverrides || {};14 var licenseTypeOverrides = options.licenseTypeOverrides || {};15 var handleUnacceptableLicense = options.handleUnacceptableLicense || (function () { });16 var handleMissingLicenseText = options.handleMissingLicenseText || (function () { return null; });17 var renderLicenses = options.renderLicenses ||18 (function (modules) {19 return modules20 .sort(function (left, right) {21 return left.name < right.name ? -1 : 1;22 })23 .reduce(function (file, module) {24 return "" + file + module.name + (module.licenseId ? "\n" + module.licenseId : '') + (module.licenseText ? "\n" + module.licenseText : '') + "\n\n";25 }, '')26 .trim() + "\n";27 });28 var renderBanner = options.renderBanner ||29 (function (filename) {30 return "/*! License information is available at " + filename + " */";31 });32 var outputFilename = options.outputFilename ||33 (perChunkOutput ? '[name].licenses.txt' : 'licenses.txt');34 var addBanner = options.addBanner === undefined ? false : options.addBanner;35 var chunkIncludeExcludeTest = options.chunkIncludeExcludeTest || (function () { return true; });36 var modulesDirectories = options.modulesDirectories || null;37 var additionalChunkModules = options.additionalChunkModules || {};38 var additionalModules = options.additionalModules || [];39 var preferredLicenseTypes = options.preferredLicenseTypes || [];40 var handleLicenseAmbiguity = options.handleLicenseAmbiguity ||41 (function (_packageName, licenses) {42 return licenses[0].type;43 });44 var handleMissingLicenseType = options.handleMissingLicenseType || (function () { return null; });45 var licenseFileOverrides = options.licenseFileOverrides || {};46 var excludedPackageTest = options.excludedPackageTest || (function () { return false; });47 var stats = {48 warnings: options.stats && options.stats.warnings !== undefined49 ? options.stats.warnings50 : true,51 errors: options.stats && options.stats.errors !== undefined52 ? options.stats.errors53 : true54 };55 var skipChildCompilers = !!options.skipChildCompilers;56 var constructedOptions = {57 licenseInclusionTest: licenseInclusionTest,58 unacceptableLicenseTest: unacceptableLicenseTest,59 perChunkOutput: perChunkOutput,60 licenseTemplateDir: licenseTemplateDir,61 licenseTextOverrides: licenseTextOverrides,62 licenseFileOverrides: licenseFileOverrides,63 licenseTypeOverrides: licenseTypeOverrides,64 handleUnacceptableLicense: handleUnacceptableLicense,65 handleMissingLicenseText: handleMissingLicenseText,66 renderLicenses: renderLicenses,67 renderBanner: renderBanner,68 outputFilename: outputFilename,69 addBanner: addBanner,70 chunkIncludeExcludeTest: chunkIncludeExcludeTest,71 modulesDirectories: modulesDirectories,72 additionalChunkModules: additionalChunkModules,73 additionalModules: additionalModules,74 preferredLicenseTypes: preferredLicenseTypes,75 handleLicenseAmbiguity: handleLicenseAmbiguity,76 handleMissingLicenseType: handleMissingLicenseType,77 excludedPackageTest: excludedPackageTest,78 stats: stats,79 skipChildCompilers: skipChildCompilers,80 buildRoot: this.context81 };82 return constructedOptions;83 };84 return PluginOptionsReader;85}());...

Full Screen

Full Screen

PluginLicenseTypeIdentifier.js

Source:PluginLicenseTypeIdentifier.js Github

copy

Full Screen

1"use strict";2var __values = (this && this.__values) || function(o) {3 var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;4 if (m) return m.call(o);5 if (o && typeof o.length === "number") return {6 next: function () {7 if (o && i >= o.length) o = void 0;8 return { value: o && o[i++], done: !o };9 }10 };11 throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");12};13Object.defineProperty(exports, "__esModule", { value: true });14exports.PluginLicenseTypeIdentifier = void 0;15var PluginLicenseTypeIdentifier = /** @class */ (function () {16 function PluginLicenseTypeIdentifier(logger, licenseTypeOverrides, preferredLicenseTypes, handleLicenseAmbiguity, handleMissingLicenseType) {17 this.logger = logger;18 this.licenseTypeOverrides = licenseTypeOverrides;19 this.preferredLicenseTypes = preferredLicenseTypes;20 this.handleLicenseAmbiguity = handleLicenseAmbiguity;21 this.handleMissingLicenseType = handleMissingLicenseType;22 }23 PluginLicenseTypeIdentifier.prototype.findLicenseIdentifier = function (compilation, packageName, packageJson) {24 if (this.licenseTypeOverrides && this.licenseTypeOverrides[packageName]) {25 return this.licenseTypeOverrides[packageName];26 }27 var licensePropValue = packageJson.license;28 if (licensePropValue) {29 return typeof licensePropValue === 'string'30 ? licensePropValue31 : licensePropValue.type;32 }33 // handle deprecated "licenses" field in package.json34 if (Array.isArray(packageJson.licenses) &&35 packageJson.licenses.length > 0) {36 if (packageJson.licenses.length === 1) {37 return packageJson.licenses[0].type;38 }39 // handle multiple licenses when we have a preferred license type40 var licenseTypes = packageJson.licenses.map(function (x) { return x.type; });41 var licenseType = this.findPreferredLicense(licenseTypes, this.preferredLicenseTypes);42 if (licenseType !== null) {43 // found preferred license44 return licenseType;45 }46 var resolvedLicenseType = this.handleLicenseAmbiguity(packageName, packageJson.licenses);47 this.logger.warn(compilation, packageName + " specifies multiple licenses: " + licenseTypes + ". Automatically selected " + resolvedLicenseType + ". Use the preferredLicenseTypes or the licenseTypeOverrides option to resolve this warning.");48 return resolvedLicenseType;49 }50 this.logger.warn(compilation, "could not find any license type for " + packageName + " in its package.json");51 return this.handleMissingLicenseType(packageName);52 };53 PluginLicenseTypeIdentifier.prototype.findPreferredLicense = function (licenseTypes, preferredLicenseTypes) {54 var e_1, _a, e_2, _b;55 try {56 for (var preferredLicenseTypes_1 = __values(preferredLicenseTypes), preferredLicenseTypes_1_1 = preferredLicenseTypes_1.next(); !preferredLicenseTypes_1_1.done; preferredLicenseTypes_1_1 = preferredLicenseTypes_1.next()) {57 var preferredLicenseType = preferredLicenseTypes_1_1.value;58 try {59 for (var licenseTypes_1 = (e_2 = void 0, __values(licenseTypes)), licenseTypes_1_1 = licenseTypes_1.next(); !licenseTypes_1_1.done; licenseTypes_1_1 = licenseTypes_1.next()) {60 var licenseType = licenseTypes_1_1.value;61 if (preferredLicenseType === licenseType) {62 return preferredLicenseType;63 }64 }65 }66 catch (e_2_1) { e_2 = { error: e_2_1 }; }67 finally {68 try {69 if (licenseTypes_1_1 && !licenseTypes_1_1.done && (_b = licenseTypes_1.return)) _b.call(licenseTypes_1);70 }71 finally { if (e_2) throw e_2.error; }72 }73 }74 }75 catch (e_1_1) { e_1 = { error: e_1_1 }; }76 finally {77 try {78 if (preferredLicenseTypes_1_1 && !preferredLicenseTypes_1_1.done && (_a = preferredLicenseTypes_1.return)) _a.call(preferredLicenseTypes_1);79 }80 finally { if (e_1) throw e_1.error; }81 }82 return null;83 };84 return PluginLicenseTypeIdentifier;85}());...

Full Screen

Full Screen

check_license.test.js

Source:check_license.test.js Github

copy

Full Screen

1/*2 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one3 * or more contributor license agreements. Licensed under the Elastic License;4 * you may not use this file except in compliance with the Elastic License.5 */6import { set } from 'lodash';7import { checkLicense } from './check_license';8import {9 LICENSE_STATUS_UNAVAILABLE,10 LICENSE_STATUS_EXPIRED,11 LICENSE_STATUS_VALID,12 LICENSE_TYPE_BASIC,13} from '../../../common/constants';14describe('check_license', function () {15 const pluginName = 'Foo';16 const minimumLicenseRequired = LICENSE_TYPE_BASIC;17 let mockLicenseInfo;18 beforeEach(() => (mockLicenseInfo = {}));19 describe('license information is undefined', () => {20 beforeEach(() => (mockLicenseInfo = undefined));21 it('should set status to unavailable', () => {22 expect(checkLicense(pluginName, minimumLicenseRequired, mockLicenseInfo).status).toBe(23 LICENSE_STATUS_UNAVAILABLE24 );25 });26 it('should set a message', () => {27 expect(checkLicense(pluginName, minimumLicenseRequired, mockLicenseInfo).message).not.toBe(28 undefined29 );30 });31 });32 describe('license information is not available', () => {33 beforeEach(() => (mockLicenseInfo.isAvailable = () => false));34 it('should set status to unavailable', () => {35 expect(checkLicense(pluginName, minimumLicenseRequired, mockLicenseInfo).status).toBe(36 LICENSE_STATUS_UNAVAILABLE37 );38 });39 it('should set a message', () => {40 expect(checkLicense(pluginName, minimumLicenseRequired, mockLicenseInfo).message).not.toBe(41 undefined42 );43 });44 });45 describe('license information is available', () => {46 beforeEach(() => {47 mockLicenseInfo.isAvailable = () => true;48 set(mockLicenseInfo, 'license.getType', () => LICENSE_TYPE_BASIC);49 });50 describe('& license is trial, standard, gold, platinum', () => {51 beforeEach(() => set(mockLicenseInfo, 'license.isOneOf', () => true));52 describe('& license is active', () => {53 beforeEach(() => set(mockLicenseInfo, 'license.isActive', () => true));54 it('should set status to valid', () => {55 expect(checkLicense(pluginName, minimumLicenseRequired, mockLicenseInfo).status).toBe(56 LICENSE_STATUS_VALID57 );58 });59 it('should not set a message', () => {60 expect(checkLicense(pluginName, minimumLicenseRequired, mockLicenseInfo).message).toBe(61 undefined62 );63 });64 });65 describe('& license is expired', () => {66 beforeEach(() => set(mockLicenseInfo, 'license.isActive', () => false));67 it('should set status to inactive', () => {68 expect(checkLicense(pluginName, minimumLicenseRequired, mockLicenseInfo).status).toBe(69 LICENSE_STATUS_EXPIRED70 );71 });72 it('should set a message', () => {73 expect(74 checkLicense(pluginName, minimumLicenseRequired, mockLicenseInfo).message75 ).not.toBe(undefined);76 });77 });78 });79 describe('& license is basic', () => {80 beforeEach(() => set(mockLicenseInfo, 'license.isOneOf', () => true));81 describe('& license is active', () => {82 beforeEach(() => set(mockLicenseInfo, 'license.isActive', () => true));83 it('should set status to valid', () => {84 expect(checkLicense(pluginName, minimumLicenseRequired, mockLicenseInfo).status).toBe(85 LICENSE_STATUS_VALID86 );87 });88 it('should not set a message', () => {89 expect(checkLicense(pluginName, minimumLicenseRequired, mockLicenseInfo).message).toBe(90 undefined91 );92 });93 });94 describe('& license is expired', () => {95 beforeEach(() => set(mockLicenseInfo, 'license.isActive', () => false));96 it('should set status to inactive', () => {97 expect(checkLicense(pluginName, minimumLicenseRequired, mockLicenseInfo).status).toBe(98 LICENSE_STATUS_EXPIRED99 );100 });101 it('should set a message', () => {102 expect(103 checkLicense(pluginName, minimumLicenseRequired, mockLicenseInfo).message104 ).not.toBe(undefined);105 });106 });107 });108 });...

Full Screen

Full Screen

generateMarkdown.js

Source:generateMarkdown.js Github

copy

Full Screen

1// TODO: Create a function that returns a license badge based on which license is passed in2// If there is no license, return an empty string3//function renderLicenseBadge(license) {}4// TODO: Create a function that returns the license link5// If there is no license, return an empty string6//function renderLicenseLink(license) {}7// TODO: Create a function that returns the license section of README8// If there is no license, return an empty string9//function renderLicenseSection(license) {}10// TODO: Create a function to generate markdown for README11function generateMarkdown(data) {12 let chosenLicense = `${data.license}`;13 let readLicense = '';14 15 if (chosenLicense === 'MIT License') {16 showLicense = 'MIT License';17 badgeLicense = '![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)';18 readLicense = 'https://opensource.org/licenses/MIT';19 };20 if (chosenLicense === 'GNU AGPLv3') {21 showLicense = 'GNU AGPLv3 License' ;22 badgeLicense = '![License: AGPL v3](https://img.shields.io/badge/License-AGPL_v3-blue.svg)';23 readLicense = 'https://www.gnu.org/licenses/agpl-3.0';24 };25 if (chosenLicense === 'Mozilla Public License 2.0') {26 showLicense = 'Mozilla Public License 2.0';27 badgeLicense = '![License: MPL 2.0](https://img.shields.io/badge/License-MPL_2.0-brightgreen.svg)';28 readLicense = 'https://opensource.org/licenses/MPL-2.0';29 };30 if (chosenLicense === 'Apache License 2.0') {31 showLicense = 'Apache License 2.0';32 badgeLicense = '![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)';33 readLicense = 'https://opensource.org/licenses/Apache-2.0';34 };35 if (chosenLicense === 'Boost Software License 1.0') {36 showLicense = 'Boost Software License 1.0';37 badgeLicense = '![License](https://img.shields.io/badge/License-Boost_1.0-lightblue.svg)';38 readLicense = 'https://www.boost.org/LICENSE_1_0.txt';39 };40 if (chosenLicense === 'The Unlicense') {41 showLicense = 'The Unlicense';42 badgeLicense = '![License: Unlicense](https://img.shields.io/badge/license-Unlicense-blue.svg)';43 readLicense = 'http://unlicense.org/';44 };45return `46# ${data.title}47<br/>48## Project Description49${data.description}50<br/>51## Table of Contents 52- [Installation](#installation)53- [Usage](#usage)54- [Credits](#credits)55- [License](#license)56- [Contributors](#Contributors)57- [Tests](#Tests)58- [Questions](#Questions)59## Deployment60${data.walkthrough}61<br/>62## Usage63${data.usage}64<br/>65## Credits66Third-party assets:67${data.credit}68<br/>69## License70${badgeLicense}71This application uses the ${showLicense}72For more information, please visit: ${readLicense}73<br/>74## Contributors75Project powered by the contributions of:76${data.contributors}77## Tests78${data.test}79## Questions80 If you have any questions, please reach out to a contributor via GitHub:81 [${data.question}](https://github.com/${data.userName})82`;83}...

Full Screen

Full Screen

check_license.js

Source:check_license.js Github

copy

Full Screen

1/*2 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one3 * or more contributor license agreements. Licensed under the Elastic License;4 * you may not use this file except in compliance with the Elastic License.5 */6import { i18n } from '@kbn/i18n';7import {8 LICENSE_STATUS_UNAVAILABLE,9 LICENSE_STATUS_INVALID,10 LICENSE_STATUS_EXPIRED,11 LICENSE_STATUS_VALID,12 RANKED_LICENSE_TYPES,13} from '../../../common/constants';14export function checkLicense(pluginName, minimumLicenseRequired, xpackLicenseInfo) {15 if (!minimumLicenseRequired) {16 throw new Error(17 `Error checking license for plugin "${pluginName}". The minimum license required has not been provided.`18 );19 }20 if (!RANKED_LICENSE_TYPES.includes(minimumLicenseRequired)) {21 throw new Error(`Invalid license type supplied to checkLicense: ${minimumLicenseRequired}`);22 }23 // If, for some reason, we cannot get the license information24 // from Elasticsearch, assume worst case and disable25 if (!xpackLicenseInfo || !xpackLicenseInfo.isAvailable()) {26 return {27 status: LICENSE_STATUS_UNAVAILABLE,28 message: i18n.translate('xpack.server.checkLicense.errorUnavailableMessage', {29 defaultMessage:30 'You cannot use {pluginName} because license information is not available at this time.',31 values: { pluginName },32 }),33 };34 }35 const { license } = xpackLicenseInfo;36 const isLicenseModeValid = license.isOneOf(37 [...RANKED_LICENSE_TYPES].splice(RANKED_LICENSE_TYPES.indexOf(minimumLicenseRequired))38 );39 const isLicenseActive = license.isActive();40 const licenseType = license.getType();41 // License is not valid42 if (!isLicenseModeValid) {43 return {44 status: LICENSE_STATUS_INVALID,45 message: i18n.translate('xpack.server.checkLicense.errorUnsupportedMessage', {46 defaultMessage:47 'Your {licenseType} license does not support {pluginName}. Please upgrade your license.',48 values: { licenseType, pluginName },49 }),50 };51 }52 // License is valid but not active53 if (!isLicenseActive) {54 return {55 status: LICENSE_STATUS_EXPIRED,56 message: i18n.translate('xpack.server.checkLicense.errorExpiredMessage', {57 defaultMessage:58 'You cannot use {pluginName} because your {licenseType} license has expired.',59 values: { licenseType, pluginName },60 }),61 };62 }63 // License is valid and active64 return {65 status: LICENSE_STATUS_VALID,66 };...

Full Screen

Full Screen

PluginLicensePolicy.js

Source:PluginLicensePolicy.js Github

copy

Full Screen

1"use strict";2Object.defineProperty(exports, "__esModule", { value: true });3exports.PluginLicensePolicy = void 0;4var PluginLicensePolicy = /** @class */ (function () {5 function PluginLicensePolicy(licenseTester, unacceptableLicenseTester, unacceptableLicenseHandler, missingLicenseTextHandler) {6 this.licenseTester = licenseTester;7 this.unacceptableLicenseTester = unacceptableLicenseTester;8 this.unacceptableLicenseHandler = unacceptableLicenseHandler;9 this.missingLicenseTextHandler = missingLicenseTextHandler;10 }11 PluginLicensePolicy.prototype.isLicenseWrittenFor = function (licenseType) {12 return this.licenseTester.test(licenseType);13 };14 PluginLicensePolicy.prototype.isLicenseUnacceptableFor = function (licenseType) {15 return this.unacceptableLicenseTester.test(licenseType);16 };17 PluginLicensePolicy.prototype.handleUnacceptableLicense = function (packageName, licenseType) {18 this.unacceptableLicenseHandler(packageName, licenseType);19 };20 PluginLicensePolicy.prototype.handleMissingLicenseText = function (packageName, licenseType) {21 this.missingLicenseTextHandler(packageName, licenseType);22 };23 return PluginLicensePolicy;24}());...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var jasmine = require('jasmine-core');2var jasmineReporters = require('jasmine-reporters');3jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({4}));5jasmine.getEnv().addReporter(new jasmineReporters.TerminalReporter({6}));7jasmine.getEnv().execute();8var Jasmine2HtmlReporter = require('protractor-jasmine2-html-reporter');9exports.config = {10 capabilities: {11 },12 onPrepare: function() {13 browser.driver.manage().window().maximize();14 jasmine.getEnv().addReporter(15 new Jasmine2HtmlReporter({16 })17 );18 }19};20"devDependencies": {21}22"jasmine-core": {23},24"jasmine-reporters": {

Full Screen

Using AI Code Generation

copy

Full Screen

1var Jasmine = require('jasmine-core/lib/jasmine-core/jasmine.js');2var jasmine = new Jasmine();3jasmine.loadConfigFile('spec/support/jasmine.json');4jasmine.execute();5{6}7describe('some test', function() {8 it('should pass', function() {9 expect(1).toBe(1);10 });11});12var Jasmine = require('jasmine-core/lib/jasmine-core/jasmine.js');13var jasmine = new Jasmine();14jasmine.loadConfigFile('spec/support/jasmine.json');15jasmine.execute();16{17}18describe('some test', function() {19 it('should pass', function() {20 expect(1).toBe(1);21 });22});

Full Screen

Using AI Code Generation

copy

Full Screen

1var Jasmine = require('jasmine');2var jasmine = new Jasmine();3jasmine.loadConfigFile('./spec/support/jasmine.json');4jasmine.execute();5{6}7Your name to display (optional):8Your name to display (optional):9var Jasmine = require('jasmine');10var jasmine = new Jasmine();11jasmine.loadConfigFile('./spec/support/jasmine.json');12jasmine.configureDefaultReporter({13 print: function() {}14});15jasmine.execute();16Your name to display (optional):17var Jasmine = require('jasmine');18var jasmine = new Jasmine();19jasmine.loadConfigFile('./spec/support/jasmine.json');20jasmine.configureDefaultReporter({21 print: function() {}22});23jasmine.execute();24Your name to display (optional):

Full Screen

Using AI Code Generation

copy

Full Screen

1jasmine.getEnv().addReporter(new jasmine.TrivialReporter());2jasmine.getEnv().execute();3jasmine.TrivialReporter = function() {4 this.started = false;5 this.finished = false;6};7jasmine.TrivialReporter.prototype = {8 reportRunnerStarting: function(runner) {9 this.started = true;10 this.log(">> Jasmine has started");11 },12 reportRunnerResults: function(runner) {13 this.finished = true;14 var results = runner.results();15 if (results.failedCount === 0) {16 this.log(">> Jasmine has finished successfully!");17 } else {18 this.log(">> Jasmine has finished with " + results.failedCount + " failure(s)");19 }20 },21 reportSuiteResults: function(suite) {22 var results = suite.results();23 this.log(suite.getFullName() + ": " + results.passedCount + " of " + results.totalCount + " passed.");24 },25 reportSpecStarting: function(spec) {26 this.log(">> Running " + spec.getFullName());27 },28 reportSpecResults: function(spec) {29 var results = spec.results();30 for (var i = 0; i < results.getItems().length; i++) {31 var result = results.getItems()[i];32 if (result.type == 'log') {33 this.log(">> Log: " + result.toString());34 } else if (result.type == 'expect' && !result.passed()) {35 this.log(">> Failure: " + result.message);36 }37 }38 },39 log: function(str) {40 console.log(str);41 }42};43jasmine.TrivialReporter.prototype.constructor = jasmine.TrivialReporter;44jasmine.HtmlReporter = function() {45 this.started = false;46 this.finished = false;47 this.suites = [];48 this.currentSuite = null;49 this.results = null;50 this.executedSpecs = 0;51};52jasmine.HtmlReporter.prototype = {53 reportRunnerStarting: function(runner) {54 this.started = true;55 this.suites = [];56 this.currentSuite = null;57 this.results = runner.results();58 },59 reportRunnerResults: function(runner) {60 this.finished = true;61 this.executedSpecs = this.results.totalCount;

Full Screen

Using AI Code Generation

copy

Full Screen

1jasmine.getEnv().addReporter(new jasmine.TrivialReporter());2jasmine.getEnv().execute();3jasmine.TrivialReporter = function() {4 this.reportRunnerResults = function(runner) {5 console.log('jasmine.getEnv().execute();');6 };7};8jasmine.TrivialReporter.prototype = new jasmine.Reporter();9beforeEach(function() {10 jasmine.Ajax.useMock();11});12beforeEach(function() {13 jasmine.Ajax.useMock();14 jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;15});16beforeEach(function() {17 jasmine.Ajax.useMock();18});19beforeEach(function() {20 jasmine.Ajax.useMock();21 jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;22});23beforeEach(function() {24 jasmine.Ajax.useMock();25});26beforeEach(function() {27 jasmine.Ajax.useMock();28 jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;29});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Jasmine-core automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful