Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mock service): add pactfile_write_mode option handling #48

Merged
merged 1 commit into from
May 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/dsl/mockService.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import {Interaction} from './interaction';

export type PactfileWriteMode = "overwrite" | "update" | "smart" | "none";

export class MockService {
constructor (consumer: string, provider: string, port?: number, host?: string, ssl?: boolean);
constructor (
consumer: string,
provider: string,
port?: number,
host?: string,
ssl?: boolean,
pactfileWriteMode?: PactfileWriteMode,
);
addInteraction(interaction: Interaction): Promise<string>;
removeInteractions(): Promise<string>;
verify(): Promise<string>;
Expand Down
7 changes: 5 additions & 2 deletions src/dsl/mockService.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,24 @@ module.exports = class MockService {
* @param {number} port - the mock service port, defaults to 1234
* @param {string} host - the mock service host, defaults to 127.0.0.1
* @param {boolean} ssl - which protocol to use, defaults to false (HTTP)
* @param {string} pactfileWriteMode - 'overwrite' | 'update' | 'smart' | 'none', defaults to 'overwrite'
*/
constructor (consumer, provider, port, host, ssl) {
constructor (consumer, provider, port, host, ssl, pactfileWriteMode) {
if (isNil(consumer) || isNil(provider)) {
throw new Error('Please provide the names of the provider and consumer for this Pact.')
}

port = port || 1234
host = host || '127.0.0.1'
ssl = ssl || false
pactfileWriteMode = pactfileWriteMode || 'overwrite'

this._request = new Request()
this._baseURL = `${ssl ? 'https' : 'http'}://${host}:${port}`
this._pactDetails = {
consumer: { name: consumer },
provider: { name: provider }
provider: { name: provider },
pactfile_write_mode: pactfileWriteMode
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/pact-web.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { InteractionObject } from "./dsl/interaction";
import * as _Matchers from "./dsl/matchers";
import {PactfileWriteMode} from "./dsl/mockService";

declare function pact(opts: pact.PactWebOptions): pact.PactWebProvider;

Expand All @@ -10,6 +11,7 @@ declare namespace pact {
port?: number;
host?: string;
ssl?: boolean;
pactfileWriteMode?: PactfileWriteMode;
}

export interface PactWebProvider {
Expand Down
4 changes: 3 additions & 1 deletion src/pact-web.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var Interaction = require('./dsl/interaction')
* @param {number} opts.port - port of the mock service, defaults to 1234
* @param {string} opts.host - host address of the mock service, defaults to 127.0.0.1
* @param {boolean} opts.ssl - SSL flag to identify the protocol to be used (default false, HTTP)
* @param {string} pactfileWriteMode - 'overwrite' | 'update' | 'smart' | 'none', defaults to 'overwrite'
* @return {@link PactProvider}
* @static
*/
Expand All @@ -40,10 +41,11 @@ module.exports = (opts) => {
var port = opts.port || 1234
var host = opts.host || '127.0.0.1'
var ssl = opts.ssl || false
var pactfileWriteMode = opts.pactfileWriteMode || 'overwrite'

logger.info(`Setting up Pact with Consumer "${consumer}" and Provider "${provider}" using mock service on Port: "${port}"`)

const mockService = new MockService(consumer, provider, port, host, ssl)
const mockService = new MockService(consumer, provider, port, host, ssl, pactfileWriteMode)

/** @namespace PactProvider */
return {
Expand Down
2 changes: 2 additions & 0 deletions src/pact.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {InteractionObject} from "./dsl/interaction";
import * as _Matchers from "./dsl/matchers";
import {PactfileWriteMode} from "./dsl/mockService";
import _Verifier = require("./dsl/verifier");

declare function pact(opts: pact.PactOptions): pact.PactProvider;
Expand All @@ -18,6 +19,7 @@ declare namespace pact {
logLevel?: string;
spec?: number;
cors?: boolean;
pactfileWriteMode?: PactfileWriteMode;
}

export interface PactProvider {
Expand Down
4 changes: 3 additions & 1 deletion src/pact.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const path = require('path')
* @param {string} opts.host - host address of the mock service, defaults to 127.0.0.1
* @param {boolean} opts.ssl - SSL flag to identify the protocol to be used (default false, HTTP)
* @param {boolean} opts.cors - allow CORS OPTION requests to be accepted, defaults to false
* @param {string} pactfileWriteMode - 'overwrite' | 'update' | 'smart' | 'none', defaults to 'overwrite'
* @return {@link PactProvider}
* @static
*/
Expand All @@ -54,6 +55,7 @@ module.exports = (opts) => {
const logLevel = opts.logLevel || 'INFO'
const spec = opts.spec || 2
const cors = opts.cors || false
const pactfileWriteMode = opts.pactfileWriteMode || 'overwrite'

const server = serviceFactory.createServer({
port: port,
Expand All @@ -69,7 +71,7 @@ module.exports = (opts) => {

logger.info(`Setting up Pact with Consumer "${consumer}" and Provider "${provider}" using mock service on Port: "${port}"`)

const mockService = new MockService(consumer, provider, port, host, ssl)
const mockService = new MockService(consumer, provider, port, host, ssl, pactfileWriteMode)

/** @namespace PactProvider */
return {
Expand Down