Skip to content

Commit

Permalink
feat: allow v3 matchers in message metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed Feb 28, 2024
1 parent 414429f commit 58b1251
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 29 deletions.
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.

65 changes: 52 additions & 13 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 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

0 comments on commit 58b1251

Please sign in to comment.