aws-sdk-client-mock
Advanced tools
Comparing version 0.3.1 to 0.4.0
@@ -5,2 +5,13 @@ # Changelog | ||
## [0.4.0](https://github.com/m-radzikowski/aws-sdk-client-mock/compare/v0.3.0...v0.4.0) (2021-05-06) | ||
### ⚠ BREAKING CHANGES | ||
* partial payload matching by default (#16) | ||
### Features | ||
* partial payload matching by default ([#16](https://github.com/m-radzikowski/aws-sdk-client-mock/issues/16)) ([3bdc6bb](https://github.com/m-radzikowski/aws-sdk-client-mock/commit/3bdc6bb3be4a3b2e95be7c7093c8cd5a5625d656)) | ||
### [0.3.1](https://github.com/m-radzikowski/aws-sdk-client-mock/compare/v0.3.0...v0.3.1) (2021-05-01) | ||
@@ -7,0 +18,0 @@ |
@@ -55,6 +55,7 @@ "use strict"; | ||
* @param command Command type to match | ||
* @param input Command payload to (strictly) match | ||
* @param input Command payload to match | ||
* @param strict Should the payload match strictly (default false, will match if all defined payload properties match) | ||
*/ | ||
on(command, input) { | ||
const matcher = sinon_1.match.instanceOf(command).and(this.createInputMatcher(input)); | ||
on(command, input, strict = false) { | ||
const matcher = sinon_1.match.instanceOf(command).and(this.createInputMatcher(input, strict)); | ||
const cmdStub = this.send.withArgs(matcher); | ||
@@ -69,10 +70,13 @@ return new CommandBehavior(this, cmdStub); | ||
* but can be used for readability. | ||
* @param input Command payload to (strictly) match | ||
* @param input Command payload to match | ||
* @param strict Should the payload match strictly (default false, will match if all defined payload properties match) | ||
*/ | ||
onAnyCommand(input) { | ||
const cmdStub = this.send.withArgs(this.createInputMatcher(input)); | ||
onAnyCommand(input, strict = false) { | ||
const cmdStub = this.send.withArgs(this.createInputMatcher(input, strict)); | ||
return new CommandBehavior(this, cmdStub); | ||
} | ||
createInputMatcher(input) { | ||
return input !== undefined ? sinon_1.match.has('input', input) : sinon_1.match.any; | ||
createInputMatcher(input, strict = false) { | ||
return input !== undefined ? | ||
sinon_1.match.has('input', strict ? input : sinon_1.match(input)) | ||
: sinon_1.match.any; | ||
} | ||
@@ -79,0 +83,0 @@ /** |
@@ -52,6 +52,8 @@ import { match } from 'sinon'; | ||
* @param command Command type to match | ||
* @param input Command payload to (strictly) match | ||
* @param input Command payload to match | ||
* @param strict Should the payload match strictly (default false, will match if all defined payload properties match) | ||
*/ | ||
AwsStub.prototype.on = function (command, input) { | ||
var matcher = match.instanceOf(command).and(this.createInputMatcher(input)); | ||
AwsStub.prototype.on = function (command, input, strict) { | ||
if (strict === void 0) { strict = false; } | ||
var matcher = match.instanceOf(command).and(this.createInputMatcher(input, strict)); | ||
var cmdStub = this.send.withArgs(matcher); | ||
@@ -66,10 +68,15 @@ return new CommandBehavior(this, cmdStub); | ||
* but can be used for readability. | ||
* @param input Command payload to (strictly) match | ||
* @param input Command payload to match | ||
* @param strict Should the payload match strictly (default false, will match if all defined payload properties match) | ||
*/ | ||
AwsStub.prototype.onAnyCommand = function (input) { | ||
var cmdStub = this.send.withArgs(this.createInputMatcher(input)); | ||
AwsStub.prototype.onAnyCommand = function (input, strict) { | ||
if (strict === void 0) { strict = false; } | ||
var cmdStub = this.send.withArgs(this.createInputMatcher(input, strict)); | ||
return new CommandBehavior(this, cmdStub); | ||
}; | ||
AwsStub.prototype.createInputMatcher = function (input) { | ||
return input !== undefined ? match.has('input', input) : match.any; | ||
AwsStub.prototype.createInputMatcher = function (input, strict) { | ||
if (strict === void 0) { strict = false; } | ||
return input !== undefined ? | ||
match.has('input', strict ? input : match(input)) | ||
: match.any; | ||
}; | ||
@@ -76,0 +83,0 @@ /** |
@@ -59,5 +59,6 @@ import { Client, Command, MetadataBearer } from '@aws-sdk/types'; | ||
* @param command Command type to match | ||
* @param input Command payload to (strictly) match | ||
* @param input Command payload to match | ||
* @param strict Should the payload match strictly (default false, will match if all defined payload properties match) | ||
*/ | ||
on<TCmdInput extends TInput, TCmdOutput extends TOutput>(command: new (input: TCmdInput) => AwsCommand<TCmdInput, TCmdOutput>, input?: TCmdInput): CommandBehavior<TInput, TOutput, TCmdOutput>; | ||
on<TCmdInput extends TInput, TCmdOutput extends TOutput>(command: new (input: TCmdInput) => AwsCommand<TCmdInput, TCmdOutput>, input?: Partial<TCmdInput>, strict?: boolean): CommandBehavior<TInput, TOutput, TCmdOutput>; | ||
/** | ||
@@ -69,5 +70,6 @@ * Allows specifying the behavior for any Command with given input (parameters). | ||
* but can be used for readability. | ||
* @param input Command payload to (strictly) match | ||
* @param input Command payload to match | ||
* @param strict Should the payload match strictly (default false, will match if all defined payload properties match) | ||
*/ | ||
onAnyCommand<TCmdInput extends TInput>(input?: TCmdInput): CommandBehavior<TInput, TOutput, TOutput>; | ||
onAnyCommand<TCmdInput extends TInput>(input?: Partial<TCmdInput>, strict?: boolean): CommandBehavior<TInput, TOutput, TOutput>; | ||
private createInputMatcher; | ||
@@ -74,0 +76,0 @@ /** |
{ | ||
"name": "aws-sdk-client-mock", | ||
"description": "Easy and powerful mocking of AWS SDK v3 Clients", | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -144,2 +144,15 @@ <div align="center"> | ||
Not all payload parameters must be defined to match | ||
(you can force strict matching by passing third param `strict: true`): | ||
```typescript | ||
snsMock | ||
.on(PublishCommand, { | ||
Message: 'My message', | ||
}) | ||
.resolves({ | ||
MessageId: '12345678-4444-5555-6666-111122223333', | ||
}); | ||
``` | ||
Specify mock behavior on receiving given payload only: | ||
@@ -146,0 +159,0 @@ |
@@ -97,8 +97,9 @@ import {Client, Command, MetadataBearer} from '@aws-sdk/types'; | ||
* @param command Command type to match | ||
* @param input Command payload to (strictly) match | ||
* @param input Command payload to match | ||
* @param strict Should the payload match strictly (default false, will match if all defined payload properties match) | ||
*/ | ||
on<TCmdInput extends TInput, TCmdOutput extends TOutput>( | ||
command: new (input: TCmdInput) => AwsCommand<TCmdInput, TCmdOutput>, input?: TCmdInput, | ||
command: new (input: TCmdInput) => AwsCommand<TCmdInput, TCmdOutput>, input?: Partial<TCmdInput>, strict = false, | ||
): CommandBehavior<TInput, TOutput, TCmdOutput> { | ||
const matcher = match.instanceOf(command).and(this.createInputMatcher(input)); | ||
const matcher = match.instanceOf(command).and(this.createInputMatcher(input, strict)); | ||
const cmdStub = this.send.withArgs(matcher); | ||
@@ -114,11 +115,14 @@ return new CommandBehavior<TInput, TOutput, TCmdOutput>(this, cmdStub); | ||
* but can be used for readability. | ||
* @param input Command payload to (strictly) match | ||
* @param input Command payload to match | ||
* @param strict Should the payload match strictly (default false, will match if all defined payload properties match) | ||
*/ | ||
onAnyCommand<TCmdInput extends TInput>(input?: TCmdInput): CommandBehavior<TInput, TOutput, TOutput> { | ||
const cmdStub = this.send.withArgs(this.createInputMatcher(input)); | ||
onAnyCommand<TCmdInput extends TInput>(input?: Partial<TCmdInput>, strict = false): CommandBehavior<TInput, TOutput, TOutput> { | ||
const cmdStub = this.send.withArgs(this.createInputMatcher(input, strict)); | ||
return new CommandBehavior(this, cmdStub); | ||
} | ||
private createInputMatcher<TCmdInput extends TInput>(input?: TCmdInput) { | ||
return input !== undefined ? match.has('input', input) : match.any; | ||
private createInputMatcher<TCmdInput extends TInput>(input?: Partial<TCmdInput>, strict = false) { | ||
return input !== undefined ? | ||
match.has('input', strict ? input : match(input)) | ||
: match.any; | ||
} | ||
@@ -125,0 +129,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
53038
720
400