Skip to content

Commit

Permalink
chore: allow v3 matchers in message metadata
Browse files Browse the repository at this point in the history
Fixes #1133
  • Loading branch information
mefellows committed Feb 28, 2024
1 parent 3ac5e0c commit 3fcd919
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 23 deletions.
4 changes: 2 additions & 2 deletions examples/messages/consumer/message-consumer.spec.ts
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
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
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
@@ -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
7 changes: 3 additions & 4 deletions src/messageConsumerPact.ts
@@ -1,3 +1,4 @@
/* eslint-disable no-nested-ternary */
/**
* @module Message
*/
Expand All @@ -23,6 +24,7 @@ import ConfigurationError from './errors/configurationError';
import { version as pactPackageVersion } from '../package.json';
import { numberToSpec } from './common/spec';
import { SpecificationVersion } from './v3';
import { isMatcher } from './dsl/matchers';

Check failure on line 27 in src/messageConsumerPact.ts

View workflow job for this annotation

GitHub Actions / build-and-test (16.x, macos-latest)

'isMatcher' is defined but never used

Check failure on line 27 in src/messageConsumerPact.ts

View workflow job for this annotation

GitHub Actions / build-and-test (16.x, ubuntu-latest)

'isMatcher' is defined but never used

Check failure on line 27 in src/messageConsumerPact.ts

View workflow job for this annotation

GitHub Actions / build-and-test (16.x, windows-latest)

'isMatcher' is defined but never used

Check failure on line 27 in src/messageConsumerPact.ts

View workflow job for this annotation

GitHub Actions / build-and-test (18.x, macos-latest)

'isMatcher' is defined but never used

Check failure on line 27 in src/messageConsumerPact.ts

View workflow job for this annotation

GitHub Actions / build-and-test (18.x, ubuntu-latest)

'isMatcher' is defined but never used

Check failure on line 27 in src/messageConsumerPact.ts

View workflow job for this annotation

GitHub Actions / build-and-test (18.x, windows-latest)

'isMatcher' is defined but never used

Check failure on line 27 in src/messageConsumerPact.ts

View workflow job for this annotation

GitHub Actions / build-and-test (20.x, macos-latest)

'isMatcher' is defined but never used

Check failure on line 27 in src/messageConsumerPact.ts

View workflow job for this annotation

GitHub Actions / build-and-test (20.x, ubuntu-latest)

'isMatcher' is defined but never used

Check failure on line 27 in src/messageConsumerPact.ts

View workflow job for this annotation

GitHub Actions / build-and-test (20.x, windows-latest)

'isMatcher' is defined but never used

const DEFAULT_PACT_DIR = './pacts';

Expand Down Expand Up @@ -169,10 +171,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
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 3fcd919

Please sign in to comment.