How to use addInteraction method in pact-foundation-pact

Best JavaScript code snippet using pact-foundation-pact

facebookwebhooks.js

Source:facebookwebhooks.js Github

copy

Full Screen

...5 const Send = require('./../send.js')(code);6 const Conversation = require('./conversation.js')(code);7 const Config = require('./../config')(code);8 const S = require('./../strings')(code);9 function addInteraction(type, uid){10 let interaction = M.Interaction({11 type: type,12 uid: uid._id,13 time: new Date()14 })15 interaction.save((err)=>{16 if (err) console.log(err);17 })18 }19 function processGetWebhook(req, res) {20 if (req.query['hub.verify_token'] === 'verify_me') {21 res.send(req.query['hub.challenge']);22 }23 else {24 res.send('Error, wrong validation token');25 }26 }27 function processPostWebhook(req, res) {28 let messaging_events = req.body.entry[0].messaging;29 messaging_events.forEach((event) => {30 if ((!event.message || !event.message.is_echo)31 && !event.read && !event.delivery) {32 let uid = { mid: event.sender.id };33 M.User.findOneAndUpdate(34 {mid: uid.mid},35 {interactionTime: (new Date())},36 function(error, user){37 if(error) console.log(error);38 // found user39 if(user){40 uid._id = user._id;41 uid.firstName = user.firstName;42 uid.lastName = user.lastName;43 let convo = user.conversationLocation;44 let inConversation = (convo && convo.conversationName);45 if (!Conversation.consumeWebhookEvent(event, uid, user)) {46 if (event.message && event.message.text && event.message.quick_reply) {47 processQuickReply(event, uid);48 }49 // else if (event.message && event.message.text && !event.message.quick_reply) {50 // // Send.allEvents(uid, S.s.bot.allEventsDefault);51 // }52 else if (event.message && event.message.attachments){53 processAttachment(event, uid);54 }55 else if (event.postback) {56 processPostback(event, uid);57 }58 }59 }60 // new user61 else {62 console.log("New User");63 var get_url = "https://graph.facebook.com/v2.6/" + uid.mid64 + "?fields=first_name,last_name,profile_pic,locale,timezone,gender"65 + "&access_token=" + Config.VERIFICATION_TOKEN;66 request(get_url, (err, response, body) => {67 if (!err && response.statusCode == 200) {68 body = JSON.parse(body);69 let user = M.User({70 mid: uid.mid,71 firstName: body.first_name,72 lastName: body.last_name,73 profilePic: body.profile_pic,74 locale: body.locale,75 gender: body.gender,76 events: [],77 interactionTime: new Date(),78 notifications: "on",79 signedUpDate: new Date()80 });81 user.save((err) => {82 if (err) console.log(err);83 M.Analytics.update({name:"NewUsers"},84 {$push: {activity: {uid:user._id, time: new Date()}}},85 {upsert: true},86 (err)=>{if(err) console.log(err);});87 Conversation.startConversation(uid, "onboarding");88 });89 }90 });91 }92 })93 }94 });95 res.sendStatus(200);96 }97 function processQuickReply(event, uid) {98 let payload = event.message.quick_reply.payload;99 if (payload.substring(0, 16) == "conversationName") {100 Conversation.handleQuickReply(uid, payload);101 }102 else {103 switch(payload.toLowerCase()){104 case("notifications"):105 Send.notifications(uid);106 break;107 case("my events"):108 addInteraction("QuickReply: My Events", uid);109 Send.myEvents(uid);110 break;111 case("my games"):112 addInteraction("QuickReply: My Events", uid);113 Send.myEvents(uid);114 break;115 case("notifications on"):116 Send.notificationsChange(uid, "on");117 break;118 case("notifications off"):119 Send.notificationsChange(uid, "off");120 break;121 default:122 Send.allEvents(uid, S.s.bot.allEventsDefault);123 }124 }125 }126 function processAttachment(event, uid) {127 //Handling like button128 if (event.message.attachments[0].payload.url129 === "https://scontent.xx.fbcdn.net/t39.1997-6/"130 + "851557_369239266556155_759568595_n.png?_nc_ad=z-m"){131 addInteraction("Like", uid);132 Send.menu(uid);133 }134 }135 function processPostback(event, uid) {136 let text = event.postback.payload;137 if (text.substring(0, 4) == "Book") {138 addInteraction("Button: Book", uid);139 Send.book(uid, text);140 }141 else if(text.substring(0, 6) == "Cancel") {142 addInteraction("Button: Cancel", uid);143 Send.cancelBooking(uid, text.split('|')[1]);144 }145 else if(text.substring(0, 5) == "Share") {146 addInteraction("Button: Share", uid);147 Send.shareEvent(uid, text);148 }149 else if(text.substring(0, 9) == "More Info") {150 addInteraction("Button: More Info", uid);151 Send.moreInfo(uid, text.split('|')[1]);152 }153 else {154 switch(text.toLowerCase()) {155 case("my events"):156 addInteraction("Menu: My Events", uid);157 Send.myEvents(uid);158 break;159 case("my games"):160 addInteraction("Menu: My Events", uid);161 Send.myEvents(uid);162 break;163 case("notifications"):164 addInteraction("Menu: Notifications", uid);165 Send.notifications(uid);166 break;167 default:168 addInteraction("Menu: Show Games", uid);169 Send.allEvents(uid, S.s.bot.allEventsDefault);170 }171 }172 }173 return {174 processPostWebhook: processPostWebhook,175 processGetWebhook: processGetWebhook176 }...

Full Screen

Full Screen

fuzz.swagger.v2.spec.js

Source:fuzz.swagger.v2.spec.js Github

copy

Full Screen

...3const { mock, handler } = pactum;4describe('Fuzz', () => {5 before(() => {6 pactum.settings.setLogLevel('ERROR');7 mock.addInteraction({8 request: {9 method: 'GET',10 path: '/swagger.json'11 },12 response: {13 status: 200,14 body: {15 "swagger": "2.0",16 "basePath": "/v2",17 "paths": {18 "/health": {19 "get": {}20 },21 "/info": {22 "post": {}23 },24 "/version": {25 "put": {26 "parameters": [27 {28 "in": "body",29 "schema": {30 "$ref": "#/definitions/Version"31 }32 }33 ]34 }35 }36 },37 "definitions": {38 "Version": {39 "type": "object",40 "properties": {41 "major": {42 "type": "string"43 },44 "minor": {45 "type": "string"46 },47 "patch": {48 "type": "string"49 }50 }51 }52 }53 }54 }55 });56 handler.addInteractionHandler('root invalid path', (ctx) => {57 return {58 strict: false,59 request: {60 method: ctx.data,61 path: '/ROOT/INVALID/PATH'62 },63 response: {64 status: 40465 }66 };67 });68 handler.addInteractionHandler('invalid path', (ctx) => {69 return {70 strict: false,71 request: {72 method: ctx.data.method,73 path: ctx.data.path74 },75 response: {76 status: 40477 }78 };79 });80 handler.addInteractionHandler('invalid method', (ctx) => {81 return {82 request: {83 method: ctx.data.method,84 path: ctx.data.path85 },86 response: {87 status: 40588 }89 };90 });91 mock.addInteraction('root invalid path', 'GET');92 mock.addInteraction('root invalid path', 'POST');93 mock.addInteraction('root invalid path', 'DELETE');94 mock.addInteraction('root invalid path', 'PUT');95 mock.addInteraction('root invalid path', 'PATCH');96 mock.addInteraction('invalid path', { method: 'GET', path: '/v2/health/INVALID/PATH' });97 mock.addInteraction('invalid path', { method: 'POST', path: '/v2/info/INVALID/PATH' });98 mock.addInteraction('invalid path', { method: 'PUT', path: '/v2/version/INVALID/PATH' });99 mock.addInteraction('invalid method', { method: 'POST', path: '/v2/health' });100 mock.addInteraction('invalid method', { method: 'PUT', path: '/v2/health' });101 mock.addInteraction('invalid method', { method: 'PATCH', path: '/v2/health' });102 mock.addInteraction('invalid method', { method: 'DELETE', path: '/v2/health' });103 mock.addInteraction('invalid method', { method: 'GET', path: '/v2/info' });104 mock.addInteraction('invalid method', { method: 'PUT', path: '/v2/info' });105 mock.addInteraction('invalid method', { method: 'PATCH', path: '/v2/info' });106 mock.addInteraction('invalid method', { method: 'DELETE', path: '/v2/info' });107 mock.addInteraction('invalid method', { method: 'GET', path: '/v2/version' });108 mock.addInteraction('invalid method', { method: 'POST', path: '/v2/version' });109 mock.addInteraction('invalid method', { method: 'PATCH', path: '/v2/version' });110 mock.addInteraction('invalid method', { method: 'DELETE', path: '/v2/version' });111 mock.addInteraction({112 strict: false,113 request: {114 method: 'PUT',115 path: '/v2/version'116 },117 response: {118 status: 400119 }120 });121 });122 it('swagger', async () => {123 await pactum.fuzz()124 .onSwagger('http://localhost:9393/swagger.json');125 });...

Full Screen

Full Screen

draw-and-modify-features.js

Source:draw-and-modify-features.js Github

copy

Full Screen

...38 return ol.events.condition.shiftKeyOnly(event) &&39 ol.events.condition.singleClick(event);40 }41});42map.addInteraction(modify);43var draw; // global so we can remove it later44function addInteraction() {45 draw = new ol.interaction.Draw({46 features: features,47 type: /** @type {ol.geom.GeometryType} */ (typeSelect.value)48 });49 map.addInteraction(draw);50}51var typeSelect = document.getElementById('type');52/**53 * Let user change the geometry type.54 * @param {Event} e Change event.55 */56typeSelect.onchange = function(e) {57 map.removeInteraction(draw);58 addInteraction();59};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Pact } = require('@pact-foundation/pact');2const { Matchers } = require('@pact-foundation/pact/dsl/matchers');3const { somethingLike } = Matchers;4const { like } = Matchers;5const { eachLike } = Matchers;6const { term } = Matchers;7const { uuid } = Matchers;8const { integer } = Matchers;9const { string } = Matchers;10const { number } = Matchers;11const { boolean } = Matchers;12const { date } = Matchers;13const { time } = Matchers;14const { dateTime } = Matchers;15const { array } = Matchers;16const { object } = Matchers;17const { PactWeb } = require('@pact-foundation/pact-web');18const { Matchers: PactWebMatchers } = require('@pact-foundation/pact-web/dsl/matchers');19const { PactNode } = require('@pact-foundation/pact-node');20const { Matchers: PactNodeMatchers } = require('@pact-foundation/pact-node/dsl/matchers');21const { PactMockService } = require('@pact-foundation/pact-mock-service');22const { Matchers: PactMockServiceMatchers } = require('@pact-foundation/pact-mock-service/dsl/matchers');23const { PactDslJsonBody } = require('@pact-foundation/pact/dsl/jsonBody');24const { PactDslXmlBody } = require('@pact-foundation/pact/dsl/xmlBody');25const { PactDslMessage } = require('@pact-foundation/pact/dsl/message');26const { PactDslMessageWithProvider } = require('@pact-foundation/pact/dsl/messageWithProvider');27const { PactDslTerm } = require('@pact-foundation/pact/dsl/term');28const { PactDslJsonArray } = require('@pact-foundation/pact/dsl/jsonArray');29const { PactDslJsonRoot } = require('@pact-foundation/pact/dsl/jsonRoot');30const { PactDslJsonBodyLike } = require('@pact-foundation/pact/dsl/jsonBodyLike');31const { PactDslJsonArrayEach

Full Screen

Using AI Code Generation

copy

Full Screen

1var pact = require('./test1.js');2var interaction = require('./test3.js');3pact.addInteraction(interaction)4 .then(function () {5 })6 .then(function () {7 return pact.verify();8 })9 .then(function () {10 return pact.writePacts();11 })12 .then(function () {13 return pact.removeInteractions();14 });

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 pact-foundation-pact 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