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 08:17] – pradnya | pact_contract_test [2026/01/05 08:27] (current) – [Overview] pradnya | ||
|---|---|---|---|
| Line 75: | Line 75: | ||
| Login Pact test lives in: | Login Pact test lives in: | ||
| < | < | ||
| - | / | + | |
| + | / | ||
| </ | </ | ||
| - | Helper Setup File | + | **Helper Setup File** |
| + | |||
| + | < | ||
| + | pact/ | ||
| - | < | ||
| </ | </ | ||
| + | |||
| + | Create pact | ||
| < | < | ||
| < | < | ||
| + | import path from " | ||
| + | import { PactV3 } from " | ||
| - | import { createPact } from " | + | export function createPact(providerName: |
| - | import { MatchersV3 } from " | + | 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 " | import axios from " | ||
| Line 98: | Line 120: | ||
| it(" | it(" | ||
| - | provider | + | provider |
| - | .given(" | + | .given(" |
| - | .uponReceiving(" | + | .uponReceiving(" |
| - | .withRequest({ | + | .withRequest({ |
| - | method: " | + | method: " |
| - | path: "/ | + | path: "/ |
| - | body: { username: " | + | body: { username: " |
| - | }) \\ | + | }) |
| - | .willRespondWith({ | + | .willRespondWith({ |
| - | status: 200, \\ | + | status: 200, |
| - | body: { \\ | + | body: { |
| - | accessToken: | + | accessToken: |
| - | refreshToken: | + | refreshToken: |
| - | user: { \\ | + | user: { |
| - | id: like(" | + | id: like(" |
| - | roles: eachLike(" | + | roles: eachLike(" |
| - | } \\ | + | } |
| - | } \\ | + | } |
| }); | }); | ||
| - | await provider.executeTest(async mockServer => { \\ | + | await provider.executeTest(async mockServer => { |
| - | const res = await axios.post( | + | const res = await axios.post( |
| - | `${mockServer.url}/ | + | `${mockServer.url}/ |
| - | { username: " | + | { username: " |
| - | ); \\ | + | ); |
| - | expect(res.status).toBe(200); | + | expect(res.status).toBe(200); |
| - | }); \\ | + | }); |
| - | }); \\ | + | }); |
| - | }); \\ | + | }); |
| </ | </ | ||
| + | |||
| + | |||
| + | ====== Generated Pact Files ====== | ||
| + | |||
| + | Pacts output to: | ||
| + | |||
| + | < | ||
| + | /pacts | ||
| + | ┗ BFF-Service-Auth-Service.json | ||
| + | |||
| + | </ | ||
pact_contract_test.1767601067.txt.gz · Last modified: by pradnya
