bespoken / virtual-alexa

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

Unable to mock countryAndPostalCode call due to missing nock for Options call #113

Closed ImperviousPanda closed 5 years ago

ImperviousPanda commented 5 years ago

Description:

I am trying to use the mock for the countryAndPostalCode Alexa API call:

const alexa = virtualAlexa.VirtualAlexa.Builder()
  .handler('functions/index.handler')
  .interactionModelFile('./functions/interaction-model.json')
  .create();

alexa.addressAPI().returnsCountryAndPostalCode({
  countryCode: 'US',
  postalCode: '45708'
});

When this is used though I get the following error:

    Error: Error: Nock: No match for request {
      "method": "OPTIONS",
      "url": "https://api.amazonalexa.com/v1/devices/virtualAlexa.deviceID.<ID>/settings/address/countryAndPostalCode",
      "headers": {
        "origin": "http://localhost",
        "access-control-request-method": "GET",
        "access-control-request-headers": "Authorization",
        "user-agent": "Mozilla/5.0 (darwin) AppleWebKit/537.36 (KHTML, like Gecko) jsdom/11.12.0",
        "host": "api.amazonalexa.com",
        "content-length": 0
      }
    }

How can I add nock support for the options call? Does this currently work for anyone?

Environment:

Steps To Reproduce

Use the code above to create the virtual alexa and mock the postal code call. Run the test for an intent that gets an address from the alexa API.

Expected behavior

Mock should work and fetch the postal code I specified.

Actual behavior

I get an error stating that nock does not match the options call.

ImperviousPanda commented 5 years ago

I needed to add "'@babel/preset-env'" to my project.

jkelvie commented 5 years ago

Hi @ImperviousPanda thanks for updating this issue. What version of node are you using? Just wondering if this something other users will face.

jkelvie commented 5 years ago

Never mind - I see the node version is 8.1.0. Thanks.