bespoken / virtual-alexa

:robot: Easily test and debug Alexa skills programmatically
https://bespoken.io
Apache License 2.0
112 stars 35 forks source link

Question about virtual-alexa dynamodb mocking and address api mocking #87

Closed AngavaiS closed 6 years ago

AngavaiS commented 6 years ago

Hello,

I've been using 'virtual-alexa' for my end-to-end testing needs and it's pretty neat!

However, I am stuck on mocking dynamodb calls and the address api calls.

I tried using 'virtualAlexa.dynamoDB().mock();' but that does not seem to help me when I'm querying using: AWS.DynamoDB.DocumentClient().

This is how it's being used:

this.docClient = new AWS.DynamoDB.DocumentClient();

getUser(alexaUserId) { const params = { //TableName: process.env.user_table_name, TableName: 'UserAttributes', KeyConditionExpression: '#alexaUserId = :alexaUserId', ExpressionAttributeNames: { '#alexaUserId': 'alexaUserId', }, ExpressionAttributeValues: { ':alexaUserId': alexaUserId, }, };

return this.docClient.query(params).promise();

}

In the readme: https://github.com/bespoken/virtual-alexa/blob/master/docs/Externals.md#dynamodb

it says that I can make normal calls to DynamoDB but it does not seem to be working. I'm running into something like below:

**TypeError [ERR_INVALID_ARG_TYPE]: The "key" argument must be one of type string, TypedArray, or DataView

  at Object.hmac (node_modules/aws-sdk/lib/util.js:401:30)
  at Object.getSigningKey (node_modules/aws-sdk/lib/signers/v4_credentials.js:62:8)
  at V4.signature (node_modules/aws-sdk/lib/signers/v4.js:97:36)
  at V4.authorization (node_modules/aws-sdk/lib/signers/v4.js:92:36)
  at V4.addAuthorization (node_modules/aws-sdk/lib/signers/v4.js:34:12)
  at node_modules/aws-sdk/lib/event_listeners.js:223:18
  at finish (node_modules/aws-sdk/lib/config.js:320:7)
  at node_modules/aws-sdk/lib/config.js:338:9**

Earlier, I was running into this error: MissingRequiredParameter: Missing required key 'TableName' in params and I fixed it by changing: TableName: process.env.user_table_name, to: TableName: 'UserAttributes',

The key error seems to deal with the KeyConditionExpression formatting. I'd like some more help on this

Also, regarding address api, I tried using the example here: https://github.com/bespoken/virtual-alexa/blob/master/docs/Externals.md#address-api

However, after filling out the mocked address info, I am running into this error: FetchError: request to https://api.amazonalexa.com/v1/devices/virtualAlexa.deviceID.b9d8670b-ec22-4525-bb7c-d1f091bcba30/settings/address failed, reason: Nock: No match for request { "method": "GET", "url": "https://api.amazonalexa.com/v1/devices/virtualAlexa.deviceID.b9d8670b-ec22-4525-bb7c-d1f091bcba30/settings/address", "headers": { "authorization": [ "Bearer virtualAlexa.accessToken.201f95ed-1da2-4597-84ef-c165a09ed0c9" ], "accept-encoding": [ "gzip,deflate" ], "user-agent": [ "node-fetch/1.0 (+https://github.com/bitinn/node-fetch)" ], "connection": [ "close" ], "accept": [ "/" ] } }

  at OverriddenClientRequest.<anonymous> (node_modules/node-fetch/index.js:133:11)
  at node_modules/nock/lib/request_overrider.js:221:11

I'm stumped on why this is happening. Help would be much appreciated.

Thank you, John Chung jonnnc@gmail.com (714) 337-0112

jkelvie commented 6 years ago

Hi @AngavaiS - with regard to Dynamo, we do not mock all Dynamo functions, just get and put. If you want to mock the query operation, you can use our code as a template for adding your own nock mock: https://github.com/bespoken/virtual-alexa/blob/master/src/external/DynamoDB.ts#L104

With regard to your question about the Address API - can you share with us the code you are using to call it?

jkelvie commented 6 years ago

I'm closing this issue for the time being since there has been no response. @AngavaiS if you have more details, please re-open and add here. Thanks.