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

chore: allow v3 matchers in message metadata #1183

Merged
merged 2 commits into from
Feb 28, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
env:
GIT_COMMIT: ${{ github.sha }}
GIT_REF: ${{ github.ref }}
GIT_BRANCH: ${{ github.head_ref || github.ref_name }}
LOG_LEVEL: info

jobs:
Expand Down
4 changes: 2 additions & 2 deletions examples/messages/consumer/message-consumer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('Message consumer tests', () => {
}),
})
.withMetadata({
queue: 'animals',
queue: like('animals'),
})
.verify(synchronousBodyHandler(dogApiHandler));
});
Expand All @@ -53,7 +53,7 @@ describe('Message consumer tests', () => {
}),
})
.withMetadata({
queue: 'animals',
queue: like('animals'),
})
.verify(synchronousBodyHandler(dogApiHandler));
});
Expand Down
4 changes: 1 addition & 3 deletions examples/messages/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
]
},
"dependencies": {
"@pact-foundation/pact-core": "^14.1.1",
"@pact-foundation/pact-core": "^14.3.0",
"@types/express": "^4.17.11",
"axios": "^1.6.1",
"body-parser": "^1.20.0",
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/build-and-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ npm ci --ignore-scripts
npm run dist
cp package.json ./dist

export GIT_BRANCH=master
export GIT_BRANCH=${GITHUB_HEAD_REF:-${GIT_REF#refs/heads/}}

export PACT_BROKER_USERNAME="dXfltyFMgNOFZAxr8io9wJ37iUpY42M"
export PACT_BROKER_PASSWORD="O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1"
Expand Down
2 changes: 1 addition & 1 deletion src/dsl/matchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export interface ArrayMatcher<T> extends Matcher<T> {
max?: number;
}

export function isMatcher(x: AnyTemplate): x is Matcher<AnyTemplate> {
export function isMatcher(x: unknown): x is Matcher<AnyTemplate> {
return x != null && (x as Matcher<AnyTemplate>).getValue !== undefined;
}

Expand Down
3 changes: 2 additions & 1 deletion src/dsl/message.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AnyJson } from '../common/jsonTypes';
import { Matcher } from './matchers';
import { Matcher as MatcherV3 } from '../v3/matchers';

/**
* Metadata is a map containing message context,
Expand All @@ -8,7 +9,7 @@ import { Matcher } from './matchers';
* @module Message
*/
export interface Metadata {
[name: string]: string | Matcher<string>;
[name: string]: string | Matcher<string> | MatcherV3<string>;
}

/**
Expand Down
5 changes: 1 addition & 4 deletions src/messageConsumerPact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,7 @@ export class MessageConsumerPact {
}

forEachObjIndexed((v, k) => {
this.message.withMetadata(
`${k}`,
typeof v === 'string' ? v : v.getValue()
);
this.message.withMetadata(`${k}`, JSON.stringify(v));
}, metadata);

return this;
Expand Down
6 changes: 2 additions & 4 deletions src/v4/message/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
generateMockServerError,
} from '../../v3/display';
import logger from '../../common/logger';
import { isMatcher as isV3Matcher } from '../../v3/matchers';

const defaultPactDir = './pacts';

Expand Down Expand Up @@ -188,10 +189,7 @@ export class SynchronousMessageWithResponseBuilder
}

forEachObjIndexed((v, k) => {
this.interaction.withMetadata(
`${k}`,
typeof v === 'string' ? v : v.getValue()
);
this.interaction.withMetadata(`${k}`, JSON.stringify(v));
}, metadata);

return this;
Expand Down