Best JavaScript code snippet using pact-foundation-pact
insertOrUpdateEmoji.js
Source: insertOrUpdateEmoji.js
1/* globals RocketChatFileEmojiCustomInstance */2Meteor.methods({3 insertOrUpdateEmoji(emojiData) {4 if (!RocketChat.authz.hasPermission(this.userId, 'manage-emoji')) {5 throw new Meteor.Error('not_authorized');6 }7 if (!s.trim(emojiData.name)) {8 throw new Meteor.Error('error-the-field-is-required', 'The field Name is required', { method: 'insertOrUpdateEmoji', field: 'Name' });9 }10 //let nameValidation = new RegExp('^[0-9a-zA-Z-_+;.]+$');11 //let aliasValidation = new RegExp('^[0-9a-zA-Z-_+;., ]+$');12 //allow all characters except colon, whitespace, comma, >, <, &, ", ', /, \, (, )13 //more practical than allowing specific sets of characters; also allows foreign languages14 let nameValidation = /[\s,:><&"'\/\\\(\)]/;15 let aliasValidation = /[:><&"'\/\\\(\)]/;16 //silently strip colon; this allows for uploading :emojiname: as emojiname17 emojiData.name = emojiData.name.replace(/:/g, '');18 emojiData.aliases = emojiData.aliases.replace(/:/g, '');19 if (nameValidation.test(emojiData.name)) {20 throw new Meteor.Error('error-input-is-not-a-valid-field', `${emojiData.name} is not a valid name`, { method: 'insertOrUpdateEmoji', input: emojiData.name, field: 'Name' });21 }22 if (emojiData.aliases) {23 if (aliasValidation.test(emojiData.aliases)) {24 throw new Meteor.Error('error-input-is-not-a-valid-field', `${emojiData.aliases} is not a valid alias set`, { method: 'insertOrUpdateEmoji', input: emojiData.aliases, field: 'Alias_Set' });25 }26 emojiData.aliases = emojiData.aliases.split(/[\s,]/);27 emojiData.aliases = emojiData.aliases.filter(Boolean);28 emojiData.aliases = _.without(emojiData.aliases, emojiData.name);29 } else {30 emojiData.aliases = [];31 }32 let matchingResults = [];33 if (emojiData._id) {34 matchingResults = RocketChat.models.EmojiCustom.findByNameOrAliasExceptID(emojiData.name, emojiData._id).fetch();35 for (let alias of emojiData.aliases) {36 matchingResults = matchingResults.concat(RocketChat.models.EmojiCustom.findByNameOrAliasExceptID(alias, emojiData._id).fetch());37 }38 } else {39 matchingResults = RocketChat.models.EmojiCustom.findByNameOrAlias(emojiData.name).fetch();40 for (let alias of emojiData.aliases) {41 matchingResults = matchingResults.concat(RocketChat.models.EmojiCustom.findByNameOrAlias(alias).fetch());42 }43 }44 if (matchingResults.length > 0) {45 throw new Meteor.Error('Custom_Emoji_Error_Name_Or_Alias_Already_In_Use', 'The custom emoji or one of its aliases is already in use', { method: 'insertOrUpdateEmoji' });46 }47 if (!emojiData._id) {48 //insert emoji49 let createEmoji = {50 name: emojiData.name,51 aliases: emojiData.aliases,52 extension: emojiData.extension53 };54 let _id = RocketChat.models.EmojiCustom.create(createEmoji);55 RocketChat.Notifications.notifyAll('updateEmojiCustom', {emojiData: createEmoji});56 return _id;57 } else {58 //update emoji59 if (emojiData.newFile) {60 RocketChatFileEmojiCustomInstance.deleteFile(encodeURIComponent(`${emojiData.name}.${emojiData.extension}`));61 RocketChatFileEmojiCustomInstance.deleteFile(encodeURIComponent(`${emojiData.name}.${emojiData.previousExtension}`));62 RocketChatFileEmojiCustomInstance.deleteFile(encodeURIComponent(`${emojiData.previousName}.${emojiData.extension}`));63 RocketChatFileEmojiCustomInstance.deleteFile(encodeURIComponent(`${emojiData.previousName}.${emojiData.previousExtension}`));64 RocketChat.models.EmojiCustom.setExtension(emojiData._id, emojiData.extension);65 } else if (emojiData.name !== emojiData.previousName) {66 let rs = RocketChatFileEmojiCustomInstance.getFileWithReadStream(encodeURIComponent(`${emojiData.previousName}.${emojiData.previousExtension}`));67 if (rs !== null) {68 RocketChatFileEmojiCustomInstance.deleteFile(encodeURIComponent(`${emojiData.name}.${emojiData.extension}`));69 let ws = RocketChatFileEmojiCustomInstance.createWriteStream(encodeURIComponent(`${emojiData.name}.${emojiData.previousExtension}`), rs.contentType);70 ws.on('end', Meteor.bindEnvironment(() =>71 RocketChatFileEmojiCustomInstance.deleteFile(encodeURIComponent(`${emojiData.previousName}.${emojiData.previousExtension}`))72 ));73 rs.readStream.pipe(ws);74 }75 }76 if (emojiData.name !== emojiData.previousName) {77 RocketChat.models.EmojiCustom.setName(emojiData._id, emojiData.name);78 }79 if (emojiData.aliases) {80 RocketChat.models.EmojiCustom.setAliases(emojiData._id, emojiData.aliases);81 } else {82 RocketChat.models.EmojiCustom.setAliases(emojiData._id, []);83 }84 RocketChat.Notifications.notifyAll('updateEmojiCustom', {emojiData});85 return true;86 }87 }...
Using AI Code Generation
1var Pact = require('pact-foundation/pact-node');2var path = require('path');3var opts = {4 pactUrls: [path.resolve(process.cwd(), 'pacts', 'testconsumer-testprovider.json')]5};6Pact.verifyPacts(opts)7 .then(function (output) {8 console.log("Pact Verification Complete!");9 console.log(output);10 })11 .catch(function (e) {12 console.log(e);13 });14Pact.verifyPacts(opts)15 .then(function (output) {16 console.log("Pact Verification Complete!");17 console.log(output);18 var outputObj = JSON.parse(output);19 if (outputObj.results && outputObj.results.success) {20 console.log("Pact Verification Successful");21 } else {22 console.log("Pact Verification Failed");23 }24 })25 .catch(function (e) {26 console.log(e);27 });
Check out the latest blogs from LambdaTest on this topic:
Hey everyone! We hope you had a great Hacktober. At LambdaTest, we thrive to bring you the best with each update. Our engineering and tech teams work at lightning speed to deliver you a seamless testing experience.
Having a good web design can empower business and make your brand stand out. According to a survey by Top Design Firms, 50% of users believe that website design is crucial to an organization’s overall brand. Therefore, businesses should prioritize website design to meet customer expectations and build their brand identity. Your website is the face of your business, so it’s important that it’s updated regularly as per the current web design trends.
In today’s world, an organization’s most valuable resource is its customers. However, acquiring new customers in an increasingly competitive marketplace can be challenging while maintaining a strong bond with existing clients. Implementing a customer relationship management (CRM) system will allow your organization to keep track of important customer information. This will enable you to market your services and products to these customers better.
When I started writing tests with Cypress, I was always going to use the user interface to interact and change the application’s state when running tests.
Sometimes, in our test code, we need to handle actions that apparently could not be done automatically. For example, some mouse actions such as context click, double click, drag and drop, mouse movements, and some special key down and key up actions. These specific actions could be crucial depending on the project context.
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!