Skip to content

Commit

Permalink
feat(mock-service): pass arguments to CLI not API
Browse files Browse the repository at this point in the history
- Passes arguments through CLI instead of API.
- Deprecates consumer/provider in MockService.ts
- Passes consumer/provider through the underlying mock server
  CLI.

Fixes #105
  • Loading branch information
mefellows committed Dec 10, 2017
1 parent 9ca25de commit 2b9053c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
]
},
"dependencies": {
"@pact-foundation/pact-node": "^6.4.1",
"@pact-foundation/pact-node": "^6.5.0",
"cli-color": "^1.1.0",
"lodash": "^4.17.4",
"lodash.isfunction": "3.0.8",
Expand Down
12 changes: 5 additions & 7 deletions src/dsl/mockService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { logger } from "../common/logger";
import { Request } from "../common/request";
import { Interaction } from "./interaction";

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

export interface Pacticipant {
name: string;
Expand All @@ -32,21 +32,19 @@ export 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' | 'none', defaults to 'overwrite'
* @param {string} pactfileWriteMode - 'overwrite' | 'update' | 'merge', defaults to 'overwrite'
*/
constructor(
// Deprecated as at https://github.com/pact-foundation/pact-js/issues/105
private consumer?: string,
private provider?: string,

// Valid
private port = 1234,
private host = "127.0.0.1",
private ssl = false,
private pactfileWriteMode: PactfileWriteMode = "overwrite") {

if (isEmpty(consumer) || isEmpty(provider)) {
logger.warn("Warning: Consumer\Provider details not provided, ensure " +
"that the mock service has been started with this information");
}

this.request = new Request();
this.baseUrl = `${ssl ? "https" : "http"}://${host}:${port}`;
this.pactDetails = {
Expand Down
11 changes: 4 additions & 7 deletions src/pact-web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,12 @@ export class PactWeb {

this.opts = { ...defaults, ...config } as PactOptionsComplete;

if (isEmpty(this.opts.consumer) || isEmpty(this.opts.provider)) {
logger.info(`Setting up Pact using mock service on port: "${this.opts.port}"`);
} else {
logger.info(`Setting up Pact with Consumer "${this.opts.consumer}" and Provider
"${this.opts.provider}" using mock service on port: "${this.opts.port}"`);
if (!isEmpty(this.opts.consumer) || !isEmpty(this.opts.provider)) {
logger.warn(`Passing in consumer/provider to PactWeb is deprecated,
and will be removed in the next major version`);
}

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

this.mockService = new MockService(this.opts.consumer, this.opts.provider, this.opts.port, this.opts.host,
this.opts.ssl, this.opts.pactfileWriteMode);
Expand Down
5 changes: 4 additions & 1 deletion src/pact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,14 @@ export class Pact {
}

this.server = serviceFactory.createServer({
consumer: this.opts.consumer,
cors: this.opts.cors,
dir: this.opts.dir,
host: this.opts.host,
log: this.opts.log,
pactfileWriteMode: this.opts.pactfileWriteMode,
port: this.opts.port,
provider: this.opts.provider,
spec: this.opts.spec,
ssl: this.opts.ssl,
sslcert: this.opts.sslcert,
Expand All @@ -71,7 +74,7 @@ export class Pact {
logger.info(`Setting up Pact with Consumer "${this.opts.consumer}" and Provider "${this.opts.provider}"
using mock service on Port: "${this.opts.port}"`);

this.mockService = new MockService(this.opts.consumer, this.opts.provider, this.opts.port, this.opts.host,
this.mockService = new MockService(undefined, undefined, this.opts.port, this.opts.host,
this.opts.ssl, this.opts.pactfileWriteMode);
}

Expand Down

0 comments on commit 2b9053c

Please sign in to comment.