-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add commandCall method to AwsStub
fixes: #240
- Loading branch information
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,6 +131,33 @@ export class AwsStub<TInput extends object, TOutput extends MetadataBearer, TCon | |
}); | ||
} | ||
|
||
/** | ||
* Returns n-th call of given Command only. | ||
* @param n Index of the call | ||
* @param commandType Command type to match | ||
* @param input Command payload to match | ||
* @param strict Should the payload match strictly (default false, will match if all defined payload properties match) | ||
*/ | ||
commandCall<TCmd extends AwsCommand<any, any>, | ||
TCmdInput extends TCmd extends AwsCommand<infer TIn, any> ? TIn : never, | ||
TCmdOutput extends TCmd extends AwsCommand<any, infer TOut> ? TOut : never, | ||
>( | ||
n: number, | ||
commandType: new (input: TCmdInput) => TCmd, | ||
input?: Partial<TCmdInput>, | ||
strict?: boolean, | ||
): SinonSpyCall<[TCmd], Promise<TCmdOutput>> { | ||
const calls = this.commandCalls(commandType, input, strict); | ||
if (n < 0) { | ||
n += calls.length; | ||
} | ||
if (n >= calls.length) { | ||
// @ts-expect-error | ||
Check failure on line 155 in packages/aws-sdk-client-mock/src/awsClientStub.ts GitHub Actions / Test and build
|
||
return null; | ||
} | ||
return calls[n]; | ||
} | ||
|
||
/** | ||
* Allows specifying the behavior for any Command with given input (parameters). | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters