How to use withOperation method in pact-foundation-pact

Best JavaScript code snippet using pact-foundation-pact

graphql.spec.ts

Source:graphql.spec.ts Github

copy

Full Screen

...12 describe("#withOperation", () => {13 describe("when given a valid operation", () => {14 it("creates a GraphQL Interaction", () => {15 interaction.uponReceiving("a request")16 interaction.withOperation("query")17 interaction.withQuery("{ hello }")18 const json: any = interaction.json()19 expect(json.request.body.operationName).to.eq("query")20 })21 })22 describe("when given an invalid operation", () => {23 it("fails with an error", () => {24 expect(interaction.withOperation.bind("aoeu")).to.throw(Error)25 })26 })27 })28 describe("#withVariables", () => {29 describe("when given a set of variables", () => {30 it("adds the variables to the payload", () => {31 interaction.uponReceiving("a request")32 interaction.withOperation("query")33 interaction.withQuery("{ hello }")34 interaction.withVariables({35 foo: "bar",36 })37 const json: any = interaction.json()38 expect(json.request.body.variables).to.deep.eq({ foo: "bar" })39 })40 })41 describe("when no variables are provided", () => {42 it("does not add the variables property to the payload", () => {43 interaction.uponReceiving("a request")44 interaction.withOperation("query")45 interaction.withQuery("{ hello }")46 const json: any = interaction.json()47 expect(json.request.body).to.not.have.property("variables")48 })49 })50 describe("when an empty variables object is presented", () => {51 it("adds the variables property to the payload", () => {52 interaction.uponReceiving("a request")53 interaction.withOperation("query")54 interaction.withQuery("{ hello }")55 interaction.withVariables({})56 const json: any = interaction.json()57 expect(json.request.body).to.have.property("variables")58 })59 })60 })61 describe("#withQuery", () => {62 beforeEach(() => {63 interaction.uponReceiving("a request")64 interaction.withOperation("query")65 interaction.withQuery("{ hello }")66 interaction.withVariables({67 foo: "bar",68 })69 })70 describe("when given an empty query", () => {71 it("fails with an error", () => {72 expect(() => interaction.withQuery(null as any)).to.throw()73 })74 })75 describe("when given an invalid query", () => {76 it("fails with an error", () => {77 expect(() =>78 interaction.withQuery("{ not properly terminated")79 ).to.throw(Error)80 })81 })82 describe("when given a valid query", () => {83 describe("without variables", () => {84 it("adds regular expressions for the whitespace in the query", () => {85 const json: any = interaction.json()86 expect(isMatcher(json.request.body.query)).to.eq(true)87 const r = new RegExp(json.request.body.query.data.matcher.s, "g")88 const lotsOfWhitespace = `{ hello89 }`90 expect(r.test(lotsOfWhitespace)).to.eq(true)91 })92 })93 describe("and variables", () => {94 it("adds regular expressions for the whitespace in the query", () => {95 interaction.withQuery(`{96 Hello(id: $id) {97 name98 }99 }`)100 interaction.withVariables({101 name: "bar",102 })103 const json: any = interaction.json()104 expect(isMatcher(json.request.body.query)).to.eq(true)105 const r = new RegExp(json.request.body.query.data.matcher.s, "g")106 const lotsOfWhitespace = `{ Hello(id: \$id) { name } }`107 expect(r.test(lotsOfWhitespace)).to.eq(true)108 })109 })110 })111 })112 describe("#json", () => {113 context("when query is empty", () => {114 it("fails with an error", () => {115 expect(() => interaction.json()).to.throw()116 })117 })118 context("when description is empty", () => {119 it("fails with an error", () => {120 interaction.withQuery("{ hello }")121 return expect(() => interaction.json()).to.throw()122 })123 })124 describe("when no operation is provided", () => {125 it("does not be present in unmarshaled body", () => {126 interaction.uponReceiving("a request")127 interaction.withQuery("{ hello }")128 const json: any = interaction.json()129 expect(json.request.body).to.not.have.property("operationName")130 })131 })132 })133 context("when given a valid query", () => {134 it("marshals the query to JSON", () => {135 interaction.uponReceiving("a request")136 interaction.withOperation("query")137 interaction.withQuery("{ hello }")138 const json: any = interaction.json()139 expect(isMatcher(json.request.body.query)).to.eq(true)140 expect(json.request.body.query.getValue()).to.eq("{ hello }")141 })142 })...

Full Screen

Full Screen

script.js

Source:script.js Github

copy

Full Screen

1$(document).ready(function () {2 // Variables3 let panel = '0'4 let withOperation = false5 // Init6 function init(button) {7 // Clean and Remove8 if (button === 'C')9 clear()10 else if (button === '<')11 remove()12 // Operations13 else if (button === '%')14 addOperation(button)15 else if (button === '/')16 addOperation(button)17 else if (button === 'x')18 addOperation(button)19 else if (button === '+')20 addOperation(button)21 else if (button === '-')22 addOperation(button)23 // Result24 else if (button === '=') {25 if (!withOperation) {26 alert('ERRO: Nenhum operador aritmético foi definido, portanto, zeramos o visor!')27 } else {28 calculate()29 }30 } else {31 if (isAnotherKey(button)) return32 panel === '0' && button != '.' ? panel = button : panel += button33 }34 35 $('#panel').empty()36 $('#panel').append(panel)37 }38 // Clear panel39 function clear() {40 panel = '0'41 withOperation = false42 $('#panel').empty()43 $('#panel').append(panel)44 }45 // Remove the last caracter46 function remove() {47 if (panel.length > 1)48 panel = panel.substring(0, panel.length - 1)49 else50 panel = '0'51 }52 // Adding operation to panel53 function addOperation(op) {54 if (withOperation) {55 alert('ERRO: Adicione apenas uma operação por vez!')56 } else {57 withOperation = true58 panel += ' ' + op + ' '59 }60 }61 // Calculating result62 function calculate() {63 let result = panel.split(' ')64 let operation = result[1]65 let num1 = parseFloat(result[0])66 let num2 = parseFloat(result[2])67 68 if (operation == '+')69 result = num1 + num270 else if (operation == '-')71 result = num1 - num272 else if (operation == 'x')73 result = num1 * num274 else if (operation == '/')75 result = num1 / num276 else if (operation == '%')77 result = (num1 * num2) / 10078 withOperation = false79 panel = result.toString()80 }81 // Verify if key exist82 function isAnotherKey(value) {83 if (84 value === '0' || 85 value === '1' || 86 value === '2' ||87 value === '3' ||88 value === '4' ||89 value === '5' ||90 value === '6' ||91 value === '7' ||92 value === '8' ||93 value === '9' ||94 value === '.'95 )96 return false97 else98 return true99 }100 // Get key101 function getKey(key) {102 if (key === 'Enter') key = '='103 else if (key === '*') key = 'x'104 else if (key === 'c') key = 'C'105 else if (key === 'd') key = '<'106 else if (key === ',') key = '.'107 else if (key === 'x') key = ''108 init(key)109 }110 // Click event111 $('#calculator .row div').click(function () { 112 init($(this).text())113 })114 // Key press event115 $(document).keypress(function (e) {116 getKey(e.key)117 })...

Full Screen

Full Screen

index.ts

Source:index.ts Github

copy

Full Screen

1import { Injectable, NgModule } from '@angular/core';2import {3 ApolloLink,4 Operation,5 FetchResult,6 Observable as LinkObservable,7} from 'apollo-link';8import {9 BehaviorSubject,10 Subject,11 asyncScheduler,12 pipe,13 MonoTypeOperatorFunction,14} from 'rxjs';15import { observeOn, distinctUntilChanged, share } from 'rxjs/operators';16export function event<T>(): MonoTypeOperatorFunction<T> {17 return pipe(18 share(),19 observeOn(asyncScheduler),20 );21}22interface WithOperation {23 operation: Operation;24}25interface OnRequest extends WithOperation {}26interface OnSuccess extends WithOperation {27 result: FetchResult;28}29interface OnError extends WithOperation {30 error: any;31}32interface OnCancel extends WithOperation {}33@Injectable()34export class ApolloNetworkStatus extends ApolloLink {35 private count = 0;36 private pending$ = new BehaviorSubject<boolean>(false);37 private request$ = new Subject<OnRequest>();38 private success$ = new Subject<OnSuccess>();39 private error$ = new Subject<OnError>();40 private cancel$ = new Subject<OnCancel>();41 public isPending = this.pending$.asObservable().pipe(42 event(),43 distinctUntilChanged(),44 );45 public onRequest = this.request$.asObservable().pipe(event());46 public onSuccess = this.success$.asObservable().pipe(event());47 public onError = this.error$.asObservable().pipe(event());48 public onCancel = this.cancel$.asObservable().pipe(event());49 constructor() {50 super();51 }52 request(operation, forward) {53 this._onRequest({ operation });54 const subscriber = forward(operation);55 return new LinkObservable(observer => {56 let isPending = true;57 const subscription = subscriber.subscribe({58 next: result => {59 isPending = false;60 this._onSuccess({ operation, result });61 observer.next(result);62 },63 error: error => {64 isPending = false;65 this._onError({ operation, error });66 observer.error(error);67 },68 complete: () => {69 observer.complete();70 },71 });72 return () => {73 if (isPending) this._onCancel({ operation });74 if (subscription) subscription.unsubscribe();75 };76 });77 }78 _onRequest(data: OnRequest) {79 this.request$.next(data);80 this.increase();81 }82 _onSuccess(data: OnSuccess) {83 this.success$.next(data);84 this.decrease();85 }86 _onError(data: OnError) {87 this.error$.next(data);88 this.decrease();89 }90 _onCancel(data: OnCancel) {91 this.cancel$.next(data);92 this.decrease();93 }94 increase() {95 this.count++;96 this.update();97 }98 decrease() {99 this.count--;100 this.update();101 }102 update() {103 this.pending$.next(this.count > 0);104 }105}106@NgModule({107 providers: [ApolloNetworkStatus],108})...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const pact = require('pact-foundation-pact');2const { somethingLike } = require('@pact-foundation/pact/dsl/matchers');3const { like, term, eachLike } = require('@pact-foundation/pact/dsl/matchers');4const { Matchers } = require('@pact-foundation/pact');5const { somethingLike: somethingLike2 } = Matchers;6const { somethingLike: somethingLike3 } = require('@pact-foundation/pact/dsl/matchers');7const { somethingLike: somethingLike4 } = require('@pact-foundation/pact/dsl/matchers');8const { somethingLike: somethingLike5 } = require('@pact-foundation/pact/dsl/matchers');9const { somethingLike: somethingLike6 } = require('@pact-foundation/pact/dsl/matchers');10const { somethingLike: somethingLike7 } = require('@pact-foundation/pact/dsl/matchers');11const { somethingLike: somethingLike8 } = require('@pact-foundation/pact/dsl/matchers');12const { somethingLike: somethingLike9 } = require('@pact-foundation/pact/dsl/matchers');13const { somethingLike: somethingLike10 } = require('@pact-foundation/pact/dsl/matchers');14const { somethingLike: somethingLike11 } = require('@pact-foundation/pact/dsl/matchers');15const { somethingLike: somethingLike12 } = require('@pact-foundation/pact/dsl/matchers');16const { somethingLike: somethingLike13 } = require('@pact-foundation/pact/dsl/matchers');17const { somethingLike: somethingLike14 } = require('@pact-foundation/pact/dsl/matchers');18const { somethingLike: somethingLike15 } = require('@pact-foundation/pact/dsl/matchers');19const { somethingLike: somethingLike16 } = require('@pact-foundation/pact/dsl/matchers');20const { somethingLike: somethingLike17 } = require('@pact-foundation/pact/dsl/matchers');21const { somethingLike: somethingLike18 } = require('@pact-foundation/pact/dsl/matchers');22const { somethingLike: somethingLike19 } = require('@pact-foundation/pact/dsl/matchers');23const { somethingLike: somethingLike20

Full Screen

Using AI Code Generation

copy

Full Screen

1const { Matchers } = require('@pact-foundation/pact');2const { somethingLike } = Matchers;3module.exports = {4 withRequest: {5 headers: {6 },7 },8 willRespondWith: {9 headers: {10 'Content-Type': 'application/json; charset=utf-8',11 },12 body: somethingLike({13 }),14 },15};16const { Matchers } = require('@pact-foundation/pact');17const { somethingLike } = Matchers;18module.exports = {19 withRequest: {20 headers: {21 'Content-Type': 'application/json;charset=utf-8',22 },23 },24 willRespondWith: {25 headers: {26 'Content-Type': 'application/json; charset=utf-8',27 },28 body: somethingLike({29 }),30 },31};32const { Matchers } = require('@pact-foundation/pact');33const { somethingLike } = Matchers;34module.exports = {35 withRequest: {36 headers: {37 'Content-Type': 'application/json;charset=utf-8',38 },39 },40 willRespondWith: {41 headers: {42 'Content-Type': 'application/json; charset=utf-8',43 },44 body: somethingLike({45 }),46 },47};

Full Screen

Using AI Code Generation

copy

Full Screen

1var pact = require('pact-foundation/pact-node');2var opts = {3};4 .removeInteractions(opts)5 .then(function () {6 .addInteraction(opts, {7 withRequest: {8 headers: {9 }10 },11 willRespondWith: {12 headers: {13 },14 body: {15 }16 }17 });18 })19 .then(function () {20 return pact.verifyPacts(opts);21 })22 .then(function () {23 return pact.writePact(opts);24 })25 .then(function () {26 return pact.publishPacts(opts);27 })28 .then(function () {29 console.log('Pact contract testing complete!');30 console.log('');31 })32 .catch(function (e) {33 console.log(e);34 });

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