pact_contract_test
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| pact_contract_test [2026/01/05 07:43] – [Overview] pradnya | pact_contract_test [2026/01/05 08:27] (current) – [Overview] pradnya | ||
|---|---|---|---|
| Line 42: | Line 42: | ||
| Recommended Test Directory Structure | Recommended Test Directory Structure | ||
| - | < | + | < |
| - | ┣ unit | + | /tests |
| - | ┃ ┣ api | + | ┣ unit |
| - | ┃ ┣ domain | + | ┃ ┣ api |
| - | ┃ ┗ infrastructure | + | ┃ ┣ domain |
| - | ┣ integration | + | ┃ ┗ infrastructure |
| - | ┃ ┣ api | + | ┣ integration |
| - | ┃ ┗ data | + | ┃ ┣ api |
| - | ┗ pact | + | ┃ ┗ data |
| - | ┣ consumers | + | ┗ pact |
| - | ┃ ┗ auth | + | ┣ consumers |
| - | | + | ┃ ┗ auth |
| - | ┣ providers | + | |
| - | ┃ ┗ auth | + | ┣ providers |
| - | | + | ┃ ┗ auth |
| - | ┗ helpers | + | |
| - | ┗ pact-setup.ts | + | ┗ helpers |
| + | ┗ pact-setup.ts | ||
| </ | </ | ||
| Line 71: | Line 72: | ||
| |'' | |'' | ||
| |'' | |'' | ||
| + | |||
| + | Login Pact test lives in: | ||
| + | < | ||
| + | |||
| + | / | ||
| + | |||
| + | </ | ||
| + | |||
| + | **Helper Setup File** | ||
| + | |||
| + | < | ||
| + | pact/ | ||
| + | |||
| + | </ | ||
| + | |||
| + | Create pact | ||
| + | < | ||
| + | |||
| + | < | ||
| + | import path from " | ||
| + | import { PactV3 } from " | ||
| + | |||
| + | export function createPact(providerName: | ||
| + | return new PactV3({ | ||
| + | consumer: " | ||
| + | provider: providerName, | ||
| + | dir: path.resolve(process.cwd(), | ||
| + | logLevel: " | ||
| + | }); | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | **login.pact.test.ts** <font 9px/ | ||
| + | |||
| + | < | ||
| + | import { createPact } from " | ||
| + | import { MatchersV3 } from " | ||
| + | import axios from " | ||
| + | |||
| + | const { like, eachLike } = MatchersV3; | ||
| + | |||
| + | describe(" | ||
| + | |||
| + | const provider = createPact(" | ||
| + | |||
| + | it(" | ||
| + | |||
| + | provider | ||
| + | .given(" | ||
| + | .uponReceiving(" | ||
| + | .withRequest({ | ||
| + | method: " | ||
| + | path: "/ | ||
| + | body: { username: " | ||
| + | }) | ||
| + | .willRespondWith({ | ||
| + | status: 200, | ||
| + | body: { | ||
| + | accessToken: | ||
| + | refreshToken: | ||
| + | user: { | ||
| + | id: like(" | ||
| + | roles: eachLike(" | ||
| + | } | ||
| + | } | ||
| + | }); | ||
| + | |||
| + | await provider.executeTest(async mockServer => { | ||
| + | const res = await axios.post( | ||
| + | `${mockServer.url}/ | ||
| + | { username: " | ||
| + | ); | ||
| + | expect(res.status).toBe(200); | ||
| + | }); | ||
| + | }); | ||
| + | }); | ||
| + | |||
| + | </ | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | ====== Generated Pact Files ====== | ||
| + | |||
| + | Pacts output to: | ||
| + | |||
| + | < | ||
| + | /pacts | ||
| + | ┗ BFF-Service-Auth-Service.json | ||
| + | |||
| + | </ | ||
pact_contract_test.1767599023.txt.gz · Last modified: by pradnya
