-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(options): remove PactOptions redefinition, introduce JestPactOptions
BREAKING CHANGE To avoid needing to modify PactOptions every time it changes, we now union it with the extra options in a type called JestPactOptions
- Loading branch information
1 parent
9df21f7
commit b622f01
Showing
3 changed files
with
71 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,71 @@ | ||
import { InteractionObject } from "@pact-foundation/pact"; | ||
import * as supertest from "supertest"; | ||
import { pactWith } from "../index"; | ||
import { InteractionObject } from '@pact-foundation/pact'; | ||
import * as supertest from 'supertest'; | ||
import { getProviderBaseUrl, pactWith } from '../index'; | ||
|
||
const getClient = (provider: any) => supertest(provider.mockService.baseUrl); | ||
const pactPort: number = 5001; | ||
|
||
const postValidRequest: InteractionObject = { | ||
state: "A pet 1845563262948980200 exists", | ||
uponReceiving: "A get request to get a pet 1845563262948980200", | ||
state: 'A pet 1845563262948980200 exists', | ||
uponReceiving: 'A get request to get a pet 1845563262948980200', | ||
willRespondWith: { | ||
status: 200 | ||
status: 200, | ||
}, | ||
withRequest: { | ||
method: "GET", | ||
path: "/v2/pet/1845563262948980200", | ||
headers: { api_key: "[]" } | ||
} | ||
method: 'GET', | ||
path: '/v2/pet/1845563262948980200', | ||
headers: { api_key: '[]' }, | ||
}, | ||
}; | ||
|
||
pactWith( | ||
{ consumer: "MyConsumer", provider: "pactWith", port: pactPort }, | ||
{ consumer: 'MyConsumer', provider: 'pactWith', port: pactPort }, | ||
(provider: any) => { | ||
describe("pact integration", () => { | ||
describe('pact integration', () => { | ||
beforeEach(() => provider.addInteraction(postValidRequest)); | ||
|
||
test("should be be able to hide the pact stuff behind the scenes with a port of the users choosing", () => | ||
test('should be be able to hide the pact stuff behind the scenes with a port of the users choosing', () => | ||
getClient(provider) | ||
.get("/v2/pet/1845563262948980200") | ||
.set("api_key", "[]") | ||
.get('/v2/pet/1845563262948980200') | ||
.set('api_key', '[]') | ||
.expect(200)); | ||
}); | ||
|
||
describe("provider object", () => { | ||
test("should show the specified port in the URL", () => { | ||
describe('provider object', () => { | ||
test('should show the specified port in the URL', () => { | ||
expect(provider.mockService.baseUrl).toMatch( | ||
new RegExp(`${pactPort}$`) | ||
new RegExp(`${pactPort}$`), | ||
); | ||
}); | ||
test('should return the port on getProviderBaseUrl', () => { | ||
expect(getProviderBaseUrl(provider)).toEqual( | ||
`http://127.0.0.1:${pactPort}`, | ||
); | ||
}); | ||
}); | ||
} | ||
}, | ||
); | ||
|
||
pactWith({ consumer: "MyConsumer", provider: "pactWith2" }, (provider: any) => { | ||
describe("pact integration", () => { | ||
pactWith({ consumer: 'MyConsumer', provider: 'pactWith2' }, (provider: any) => { | ||
describe('pact integration', () => { | ||
beforeEach(() => provider.addInteraction(postValidRequest)); | ||
|
||
test("should be ok if i dont provide a port", () => | ||
test('should be ok if i dont provide a port', () => | ||
getClient(provider) | ||
.get("/v2/pet/1845563262948980200") | ||
.set("api_key", "[]") | ||
.get('/v2/pet/1845563262948980200') | ||
.set('api_key', '[]') | ||
.expect(200)); | ||
}); | ||
|
||
describe("provider object", () => { | ||
test("should show the randomly assigned port in the URL", () => { | ||
describe('provider object', () => { | ||
test('should show the randomly assigned port in the URL', () => { | ||
expect(provider.mockService.baseUrl).toMatch(new RegExp(`\\d{4,5}$`)); | ||
}); | ||
|
||
test('should return the host on getProviderBaseUrl', () => { | ||
expect(getProviderBaseUrl(provider)).toMatch( | ||
new RegExp('^http://127.0.0.1:\\d{4,5}$'), | ||
); | ||
}); | ||
}); | ||
}); |