Skip to content

Commit

Permalink
Version065 (bespoken#65)
Browse files Browse the repository at this point in the history
* support for intent confirmation when an intent's confirmationStatus has not been set

* Force confirmation status to none for non-delegated dialogs

* 0.6.4

* Fix countrycode bug

* 0.6.5

* Set scopes independently
  • Loading branch information
jkelvie authored Jun 5, 2018
1 parent 139a905 commit a3cbbb1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "virtual-alexa",
"license": "Apache-2.0",
"private": false,
"version": "0.6.4-1",
"version": "0.6.5",
"main": "./lib/src/Index.js",
"typings": "./lib/src/Index.d.ts",
"engines": {
Expand Down
29 changes: 22 additions & 7 deletions src/external/AddressAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import {SkillContext} from "../core/SkillContext";

export class AddressAPI {
/** @internal */
private static activeScope: nock.Scope; // We keep the nock scope as a singleton - only one can be active at a time
private static addressScope: nock.Scope; // We keep the nock scope as a singleton - only one can be active at a time
/** @internal */
private static postalScope: nock.Scope; // We keep the nock scope as a singleton - only one can be active at a time
public constructor(private context: SkillContext) {
this.reset();
}
Expand All @@ -13,12 +15,12 @@ export class AddressAPI {
* @param {IStreetAddress} address
*/
public returnsFullAddress(address: IStreetAddress) {
this.configure(200, "/settings/address/countryAndPostalCode", address);
this.configure(200, "/settings/address", address);
const countryAndPostalCode: ICountryAndPostalCode = {
countryCode: address.countryCode,
postalCode: address.postalCode,
};
this.configure(200, "/settings/address", countryAndPostalCode);
this.configure(200, "/settings/address/countryAndPostalCode", countryAndPostalCode);
}

/**
Expand All @@ -40,8 +42,12 @@ export class AddressAPI {
}

public reset() {
if (AddressAPI.activeScope) {
AddressAPI.activeScope.persist(false);
if (AddressAPI.addressScope) {
AddressAPI.addressScope.persist(false);
}

if (AddressAPI.postalScope) {
AddressAPI.postalScope.persist(false);
}
}

Expand All @@ -56,11 +62,20 @@ export class AddressAPI {
}

const baseURL = this.context.apiEndpoint();
AddressAPI.activeScope = nock(baseURL)
// For some reason, in testing this, the get only works if it is function
// Does not work, for certain scenarios, if it is just a string
const scope = nock(baseURL)
.persist()
.get("/v1/devices/" + this.context.device().id() + pathEnd)
.get((path) => {
return path === ("/v1/devices/" + this.context.device().id() + pathEnd);
})
.query(true)
.reply(responseCode, JSON.stringify(payload, null, 2));
if (pathEnd.endsWith("countryAndPostalCode")) {
AddressAPI.postalScope = scope;
} else {
AddressAPI.addressScope = scope;
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions test/AddressAPITest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe("Test address API mocks", function() {
event.context.System.device.deviceId,
true)
.then((response: any) => {
assert.equal(response.payload.addressLine1, "address line 1");
assert.isUndefined(response.payload.addressLine1);
assert.equal(response.payload.countryCode, "country code");
assert.equal(response.statusCode, 200);
}));
Expand All @@ -19,10 +19,11 @@ describe("Test address API mocks", function() {
event.context.System.device.deviceId,
false)
.then((response: any) => {
assert.isUndefined(response.payload.addressLine1);
assert.equal(response.payload.addressLine1, "address line 1");
assert.equal(response.payload.countryCode, "country code");
assert.equal(response.statusCode, 200);
}));

Promise.all(promises).then(() => {
done();
});
Expand Down

0 comments on commit a3cbbb1

Please sign in to comment.