Kendrick B
05/23/2022, 2:47 AMActual interactions do not match expected interactions for mock MockService.
Timothy Jones
05/23/2022, 2:49 AMTimothy Jones
05/23/2022, 2:49 AMaws-sdk-mock
, then you're probably not sending real requests. So, pact will be unhappy, because it wants the real requestTimothy Jones
05/23/2022, 2:50 AMTimothy Jones
05/23/2022, 2:50 AMKendrick B
05/23/2022, 2:51 AMTimothy Jones
05/23/2022, 2:52 AMTimothy Jones
05/23/2022, 2:52 AMKendrick B
05/23/2022, 2:53 AMTimothy Jones
05/23/2022, 2:53 AMKendrick B
05/23/2022, 2:54 AMTimothy Jones
05/23/2022, 2:54 AMTimothy Jones
05/23/2022, 2:55 AMTimothy Jones
05/23/2022, 2:56 AMaws-sdk-mock
, because you're spinning up your real providerTimothy Jones
05/23/2022, 2:57 AMTimothy Jones
05/23/2022, 2:57 AMTimothy Jones
05/23/2022, 2:59 AMTimothy Jones
05/23/2022, 3:00 AMKendrick B
05/23/2022, 3:00 AMTimothy Jones
05/23/2022, 3:00 AMlocalstack
, but my experience with that has not been positiveTimothy Jones
05/23/2022, 3:00 AMTimothy Jones
05/23/2022, 3:00 AMTimothy Jones
05/23/2022, 3:00 AMTimothy Jones
05/23/2022, 3:01 AMaws-sdk-mock
is for mocking out aws sdk calls - I assumed that your lambda is calling some AWS services, but do you mean that you're using it to mock the whole lambda invocation?Timothy Jones
05/23/2022, 3:02 AMKendrick B
05/23/2022, 3:09 AMKendrick B
05/23/2022, 3:09 AMtest('Should invoke the ConsumeLambda.', () => {
AWSMock.setSDKInstance(AWS);
AWSMock.mock('Lambda', 'invoke', function mockedInvoke(params, callback) {
callback(null, {
Payload: {
statusCode: 200,
body: {
message: 'This token is valid',
metadata: {}
}
}
});
});
return invokeConsumeLambda('token', 'VALIDATE').then(data => {
expect(data).toMatchObject({
statusCode: 200,
body: {
message: 'This token is valid',
metadata: {}
}
});
});
});
Timothy Jones
05/23/2022, 3:10 AMTimothy Jones
05/23/2022, 3:10 AMTimothy Jones
05/23/2022, 3:11 AMinvokeConsumeLambda
<-- I think this is using the mock set up, rather than invoking it directlyKendrick B
05/23/2022, 3:11 AMTimothy Jones
05/23/2022, 3:11 AMKendrick B
05/23/2022, 3:12 AMinvokeConsumeLambda
Timothy Jones
05/23/2022, 3:12 AMKendrick B
05/23/2022, 3:12 AMTimothy Jones
05/23/2022, 3:12 AMTimothy Jones
05/23/2022, 3:13 AMTimothy Jones
05/23/2022, 3:13 AMKendrick B
05/23/2022, 3:13 AMKendrick B
05/23/2022, 3:13 AMTimothy Jones
05/23/2022, 3:14 AMTimothy Jones
05/23/2022, 3:16 AMinvokeConsumeLambda
would do things like:
• Know how to make the call
• Know how to marshal the request (eg getUser(29)
becomes GET /some/path/user/29
)
• Know how to unmarshall the responseTimothy Jones
05/23/2022, 3:16 AMTimothy Jones
05/23/2022, 3:18 AMmetadata: {}
is returned. I bet you don't need it, so you don't need to tell pact about itTimothy Jones
05/23/2022, 3:18 AMTimothy Jones
05/23/2022, 3:18 AMKendrick B
05/23/2022, 3:21 AMTimothy Jones
05/23/2022, 3:21 AMTimothy Jones
05/23/2022, 3:22 AMKendrick B
05/23/2022, 3:22 AMTimothy Jones
05/23/2022, 3:22 AMTimothy Jones
05/23/2022, 3:22 AMTimothy Jones
05/23/2022, 3:23 AMTimothy Jones
05/23/2022, 3:23 AMbecause i dont know what the endpoint is.Yeah. This is the problem with using pact to test the AWS sdk. The requests are opaque
Kendrick B
05/23/2022, 3:24 AMTimothy Jones
05/23/2022, 3:24 AMTimothy Jones
05/23/2022, 3:25 AMTimothy Jones
05/23/2022, 3:26 AMaws-sdk-mock
suggests that the design of the layers could be improved
• If you can change the design to bring in an API gateway, then you can just make an HTTP request as normal. Then you can use pact, and also your consumer implementation doesn't even need to know it's contacting AWSTimothy Jones
05/23/2022, 3:29 AMThe returned value from aws-sdk-mock suggests that the design of the layers could be improvedBecause the calling layer knows that it's a lamdba API response object. It shouldn't know that - probably it should just get
{
message: 'This token is valid',
metadata: {}
}
(although I don't know your application, so it's hard to say for sure) - this is unrelated to pact / aws-sdk-mock - it's just something I noticed