Skip to content

Commit 021d2d4

Browse files
committed
feat(functions): Add ability to give a collection of arguments an invocation name
1 parent a577a3f commit 021d2d4

21 files changed

Lines changed: 741 additions & 96 deletions

packages/case-core-plugin-function-dsl/src/dsl/matchers.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,30 @@ export interface CoreFunctionErrorResultMatcher {
3232
export const functionArgumentsMatcher = (
3333
expectedArguments: AnyCaseMatcherOrData[],
3434
functionName: string,
35+
invocationName: string | undefined,
3536
): CoreFunctionArgumentsMatcher => ({
3637
'_case:matcher:type': FUNCTION_ARGUMENTS_MATCHER_TYPE,
38+
...(invocationName ? { '_case:matcher:uniqueName': invocationName } : {}),
3739
arguments: expectedArguments,
3840
functionName,
3941
});
4042

4143
export const functionReturnSuccessMatcher = (
4244
returnValue: AnyCaseMatcherOrData,
45+
responseName: string | undefined,
4346
): CoreFunctionSuccessResultMatcher => ({
4447
'_case:matcher:type': FUNCTION_RESULT_MATCHER_TYPE,
48+
...(responseName ? { '_case:matcher:uniqueName': responseName } : {}),
4549
success: returnValue,
4650
});
4751

4852
export const functionThrowsErrorMatcher = (
4953
errorClassName: AnyCaseMatcherOrData,
5054
message?: AnyCaseMatcherOrData,
55+
responseName?: string | undefined,
5156
): CoreFunctionErrorResultMatcher => ({
5257
'_case:matcher:type': FUNCTION_RESULT_MATCHER_TYPE,
58+
...(responseName ? { '_case:matcher:uniqueName': responseName } : {}),
5359
errorClassName,
5460
...(message != null ? { message } : {}),
5561
});

packages/case-definition-dsl/api-extractor/case-definition-dsl.api.json

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,60 @@
582582
"endIndex": 2
583583
}
584584
},
585+
{
586+
"kind": "PropertySignature",
587+
"canonicalReference": "@contract-case/case-definition-dsl!interactions.functions.FunctionExecutionExample#invocationName:member",
588+
"docComment": "/**\n * A name for this specific combination of arguments - must be unique in this contract.\n */\n",
589+
"excerptTokens": [
590+
{
591+
"kind": "Content",
592+
"text": "readonly invocationName?: "
593+
},
594+
{
595+
"kind": "Content",
596+
"text": "string"
597+
},
598+
{
599+
"kind": "Content",
600+
"text": ";"
601+
}
602+
],
603+
"isReadonly": true,
604+
"isOptional": true,
605+
"releaseTag": "Public",
606+
"name": "invocationName",
607+
"propertyTypeTokenRange": {
608+
"startIndex": 1,
609+
"endIndex": 2
610+
}
611+
},
612+
{
613+
"kind": "PropertySignature",
614+
"canonicalReference": "@contract-case/case-definition-dsl!interactions.functions.FunctionExecutionExample#responseName:member",
615+
"docComment": "/**\n * A name for this specific return value - must be unique in this contract.\n */\n",
616+
"excerptTokens": [
617+
{
618+
"kind": "Content",
619+
"text": "readonly responseName?: "
620+
},
621+
{
622+
"kind": "Content",
623+
"text": "string"
624+
},
625+
{
626+
"kind": "Content",
627+
"text": ";"
628+
}
629+
],
630+
"isReadonly": true,
631+
"isOptional": true,
632+
"releaseTag": "Public",
633+
"name": "responseName",
634+
"propertyTypeTokenRange": {
635+
"startIndex": 1,
636+
"endIndex": 2
637+
}
638+
},
585639
{
586640
"kind": "PropertySignature",
587641
"canonicalReference": "@contract-case/case-definition-dsl!interactions.functions.FunctionExecutionExample#returnValue:member",
@@ -715,6 +769,33 @@
715769
"endIndex": 2
716770
}
717771
},
772+
{
773+
"kind": "PropertySignature",
774+
"canonicalReference": "@contract-case/case-definition-dsl!interactions.functions.ThrowingFunctionExecutionExample#invocationName:member",
775+
"docComment": "/**\n * A name for this specific combination of arguments - must be unique in this contract.\n */\n",
776+
"excerptTokens": [
777+
{
778+
"kind": "Content",
779+
"text": "readonly invocationName?: "
780+
},
781+
{
782+
"kind": "Content",
783+
"text": "string"
784+
},
785+
{
786+
"kind": "Content",
787+
"text": ";"
788+
}
789+
],
790+
"isReadonly": true,
791+
"isOptional": true,
792+
"releaseTag": "Public",
793+
"name": "invocationName",
794+
"propertyTypeTokenRange": {
795+
"startIndex": 1,
796+
"endIndex": 2
797+
}
798+
},
718799
{
719800
"kind": "PropertySignature",
720801
"canonicalReference": "@contract-case/case-definition-dsl!interactions.functions.ThrowingFunctionExecutionExample#message:member",
@@ -742,6 +823,33 @@
742823
"startIndex": 1,
743824
"endIndex": 2
744825
}
826+
},
827+
{
828+
"kind": "PropertySignature",
829+
"canonicalReference": "@contract-case/case-definition-dsl!interactions.functions.ThrowingFunctionExecutionExample#responseName:member",
830+
"docComment": "/**\n * A name for this specific exception, must be unique in this\n */\n",
831+
"excerptTokens": [
832+
{
833+
"kind": "Content",
834+
"text": "readonly responseName?: "
835+
},
836+
{
837+
"kind": "Content",
838+
"text": "string"
839+
},
840+
{
841+
"kind": "Content",
842+
"text": ";"
843+
}
844+
],
845+
"isReadonly": true,
846+
"isOptional": true,
847+
"releaseTag": "Public",
848+
"name": "responseName",
849+
"propertyTypeTokenRange": {
850+
"startIndex": 1,
851+
"endIndex": 2
852+
}
745853
}
746854
],
747855
"extendsTokenRanges": []

packages/case-definition-dsl/api-extractor/case-definition-dsl.api.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@ class FunctionArguments extends AnyMatcher {
325325
interface FunctionExecutionExample {
326326
readonly arguments: AnyMatcherOrData[];
327327
readonly functionName: string;
328+
readonly invocationName?: string;
329+
readonly responseName?: string;
328330
readonly returnValue: AnyMatcherOrData;
329331
}
330332

@@ -640,7 +642,9 @@ interface ThrowingFunctionExecutionExample {
640642
readonly arguments: AnyMatcherOrData[];
641643
readonly errorClassName: AnyMatcherOrData;
642644
readonly functionName: string;
645+
readonly invocationName?: string;
643646
readonly message?: AnyMatcherOrData;
647+
readonly responseName?: string;
644648
}
645649

646650
// @public

0 commit comments

Comments
 (0)