How to use setupStates method in pact-foundation-pact

Best JavaScript code snippet using pact-foundation-pact

verifier.spec.ts

Source:verifier.spec.ts Github

copy

Full Screen

1/* tslint:disable:no-unused-expression no-empty no-string-literal*/2import * as chai from "chai"3import * as chaiAsPromised from "chai-as-promised"4import * as sinon from "sinon"5import { Verifier, VerifierOptions } from "./verifier"6import serviceFactory from "@pact-foundation/pact-node"7import logger from "../common/logger"8import * as http from "http"9import * as express from "express"10chai.use(chaiAsPromised)11const expect = chai.expect12describe("Verifier", () => {13 afterEach(() => {14 sinon.restore()15 })16 const state = "thing exists"17 let v: Verifier18 let opts: VerifierOptions19 let executed: boolean20 const providerBaseUrl = "http://not.exists"21 // Little function to mock out an Event Emitter22 const fakeServer = (event: string) => ({23 on: (registeredEvent: string, cb: any) => {24 if (registeredEvent === event) {25 cb()26 }27 },28 })29 beforeEach(() => {30 executed = false31 opts = {32 providerBaseUrl,33 requestFilter: (req, res, next) => {34 next()35 },36 stateHandlers: {37 [state]: () => {38 executed = true39 return Promise.resolve("done")40 },41 },42 }43 })44 describe("#constructor", () => {45 describe("when given configuration", () => {46 it("sets the configuration on the object", () => {47 v = new Verifier(opts)48 expect(v)49 .to.have.deep.property("config")50 .includes({51 providerBaseUrl,52 })53 expect(v).to.have.nested.property("config.stateHandlers")54 expect(v).to.have.nested.property("config.requestFilter")55 })56 })57 describe("when no configuration is given", () => {58 it("does not set the configuration on the object", () => {59 v = new Verifier()60 expect(v).to.not.have.deep.property("config")61 })62 })63 })64 describe("#setConfig", () => {65 let spy: sinon.SinonSpy66 beforeEach(() => {67 spy = sinon.spy(serviceFactory, "logLevel")68 v = new Verifier(opts)69 })70 context("when logLevel is provided", () => {71 it("sets the log level on pact node", () => {72 v["setConfig"]({73 ...opts,74 logLevel: "debug",75 })76 expect(spy.callCount).to.eql(1)77 })78 })79 context("when logLevel is not provided", () => {80 it("does not modify the log setting", () => {81 v["setConfig"]({82 ...opts,83 })84 expect(spy.callCount).to.eql(0)85 })86 })87 context("when a deprecated field is provided", () => {88 it("logs a warning", () => {89 spy = sinon.spy(logger, "warn")90 v["setConfig"]({91 ...opts,92 providerStatesSetupUrl: "http://foo.com",93 })94 expect(spy.callCount).to.eql(1)95 })96 })97 })98 describe("#setupStates", () => {99 describe("when there are provider states on the pact", () => {100 describe("and there are handlers associated with those states", () => {101 it("executes the handler and returns a set of Promises", async () => {102 v = new Verifier(opts)103 const res = await v["setupStates"]({104 states: [state],105 })106 expect(res).lengthOf(1)107 expect(executed).to.be.true108 })109 })110 describe("and there are no handlers associated with those states", () => {111 it("executes the handler and returns an empty Promise", async () => {112 const spy = sinon.spy(logger, "warn")113 delete opts.stateHandlers114 v = new Verifier(opts)115 const res = await v["setupStates"]({116 states: [state],117 })118 expect(res).lengthOf(0)119 expect(spy.callCount).to.eql(1)120 expect(executed).to.be.false121 })122 })123 })124 describe("when there are no provider states on the pact", () => {125 it("executes the handler and returns an empty Promise", async () => {126 v = new Verifier(opts)127 const res = await v["setupStates"]({})128 expect(res).lengthOf(0)129 })130 })131 })132 describe("#verifyProvider", () => {133 beforeEach(() => {134 v = new Verifier()135 sinon.stub(v, "startProxy" as any).returns({136 close: () => {137 executed = true138 },139 })140 sinon.stub(v, "waitForServerReady" as any).returns(Promise.resolve())141 })142 describe("when no configuration has been given", () => {143 it("fails with an error", () => {144 return expect(v.verifyProvider()).to.eventually.be.rejectedWith(Error)145 })146 })147 describe("when the verifier has been configured", () => {148 context("and the verification runs successfully", () => {149 it("closes the server and returns the result", () => {150 sinon151 .stub(v, "runProviderVerification" as any)152 .returns(Promise.resolve("done"))153 const res = v.verifyProvider(opts)154 return expect(res).to.eventually.be.fulfilled.then(() => {155 expect(executed).to.be.true156 })157 })158 })159 context("and the verification fails", () => {160 it("closes the server and returns the result", () => {161 sinon162 .stub(v, "runProviderVerification" as any)163 .returns(() => Promise.reject("error"))164 const res = v.verifyProvider(opts)165 return expect(res).to.eventually.be.rejected.then(() => {166 expect(executed).to.be.true167 })168 })169 })170 })171 })172 describe("#waitForServerReady", () => {173 beforeEach(() => {174 v = new Verifier()175 })176 context("when the server starts successfully", () => {177 it("returns a successful promise", () => {178 const res = v["waitForServerReady"](179 fakeServer("listening") as http.Server180 )181 return expect(res).to.eventually.be.fulfilled182 })183 })184 context("when the server fails to start", () => {185 it("returns an error", () => {186 const res = v["waitForServerReady"](fakeServer("error") as http.Server)187 return expect(res).to.eventually.be.rejected188 })189 })190 })191 describe("#createProxyStateHandler", () => {192 v = new Verifier()193 let res: any194 const mockResponse = {195 sendStatus: (status: number) => {196 res = status197 },198 status: (status: number) => {199 res = status200 return {201 send: () => {},202 }203 },204 }205 context("when valid state handlers are provided", () => {206 it("returns a 200", () => {207 sinon.stub(v, "setupStates" as any).returns(Promise.resolve())208 const h = v["createProxyStateHandler"]()209 return expect(210 h({} as express.Request, mockResponse as express.Response)211 ).to.eventually.be.fulfilled.then(() => {212 expect(res).to.eql(200)213 })214 })215 })216 context("when there is a problem with a state handler", () => {217 it("returns a 500", () => {218 sinon219 .stub(v, "setupStates" as any)220 .returns(Promise.reject("state error"))221 const h = v["createProxyStateHandler"]()222 return expect(223 h({} as express.Request, mockResponse as express.Response)224 ).to.eventually.be.fulfilled.then(() => {225 expect(res).to.eql(500)226 })227 })228 })229 })230 describe("#startProxy", () => {231 v = new Verifier()232 it("starts a given http.Server", () => {233 v["startProxy"](express())234 })235 })...

Full Screen

Full Screen

Herokit.Router.js

Source:Herokit.Router.js Github

copy

Full Screen

...6 _.each(Herokit.Behavior.OnBeforeActions, function(element, index, list){7 Herokit.Helper.debug.log("Herokit.Behavior.OnBeforeAction apply "+element.type+" rule '"+element.name+"'with options: "+_.toArray(element.options).join(", ")+"", 5);8 element.apply(); //apply now onbefore rules9 });10 this.setupStates();11 Herokit.init.setSetupReady();12};13Herokit.Router.setupStates = function() {14 Herokit.Helper.debug.log("Herokit.Router.setupStates", 5);15 var i=0;16 for (i=0;i<Herokit.Env.Routing.availableRouters.length;i++)17 {18 Herokit.Helper.getRouter(Herokit.Env.Routing.availableRouters[i]).setupStates();19 }20 return i;21}22Herokit.Router.getStates = function() {23 return Herokit.Behavior.States;24};25Herokit.Router.getState = function(name) {26 if (typeof Herokit.Behavior.States[name] === 'undefined') throw new Herokit.Error("State "+name+" unknown.");27 return Herokit.Behavior.States[name];...

Full Screen

Full Screen

setup.controller.js

Source:setup.controller.js Github

copy

Full Screen

1/**2 * @ngdoc controller3 * @name app.setup.controller:Setup4 * @description < description placeholder >5 */6(function(){7 'use strict';8 angular9 .module('app.setup')10 .controller('Setup', Setup);11 /* @ngInject */12 function Setup($state,authentication){13 var vm = this;14 vm.setupStates = [];15 init(); 16 17 /////////////////////18 /**19 * @ngdoc method20 * @name testFunction21 * @param {number} num number is the number of the number22 * @methodOf app.setup.controller:Setup23 * @description24 * My Description rules25 */26 27 function init(){28 $state.get()29 .forEach(function(state){30 if(state.inSetup){31 if(state.userAdminOnly && authentication.isUserAdmin()){32 vm.setupStates.push(state);33 }34 else if(!state.userAdminOnly){35 vm.setupStates.push(state);36 }37 }38 });39 }40 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const pact = require('@pact-foundation/pact');2const { somethingLike: like } = require('@pact-foundation/pact').Matchers;3const { eachLike } = require('@pact-foundation/pact').Matchers;4const { like: like2 } = require('@pact-foundation/pact').Matchers;5const { somethingLike: like3 } = require('@pact-foundation/pact').Matchers;6const { somethingLike: like4 } = require('@pact-foundation/pact').Matchers;7const { somethingLike: like5 } = require('@pact-foundation/pact').Matchers;8const { somethingLike: like6 } = require('@pact-foundation/pact').Matchers;9const { somethingLike: like7 } = require('@pact-foundation/pact').Matchers;10const { somethingLike: like8 } = require('@pact-foundation/pact').Matchers;11const { somethingLike: like9 } = require('@pact-foundation/pact').Matchers;12const { somethingLike: like10 } = require('@pact-foundation/pact').Matchers;13const { somethingLike: like11 } = require('@pact-foundation/pact').Matchers;14const { somethingLike: like12 } = require('@pact-foundation/pact').Matchers;15const { somethingLike: like13 } = require('@pact-foundation/pact').Matchers;16const { somethingLike: like14 } = require('@pact-foundation/pact').Matchers;17const { somethingLike: like15 } = require('@pact-foundation/pact').Matchers;18const { somethingLike: like16 } = require('@pact-foundation/pact').Matchers;19const { somethingLike: like17 } = require('@pact-foundation/pact').Matchers;20const { somethingLike: like18 } = require('@pact-foundation/pact').Matchers;21const { somethingLike: like19 } = require('@pact-foundation/pact').Matchers;22const { somethingLike: like20 } = require('@pact-foundation/pact').Matchers;23const { somethingLike: like21 } = require('@pact-foundation/pact').Matchers;24const { somethingLike: like22 } = require('@pact-foundation/pact').Matchers;25const { somethingLike: like23 } = require('@pact-foundation/pact').Matchers;26const { somethingLike: like24 } = require('@

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