smartystreets-javascript-sdk 3.3.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/node-tests.yml +1 -1
- package/Makefile +2 -2
- package/examples/international_address_autocomplete.js +31 -20
- package/package.json +4 -4
- package/src/BaseUrlSender.js +1 -1
- package/src/ClientBuilder.js +1 -1
- package/src/InputData.js +6 -1
- package/src/Request.js +1 -0
- package/src/international_address_autocomplete/Client.js +7 -8
- package/src/international_address_autocomplete/Lookup.js +5 -5
- package/src/international_address_autocomplete/Suggestion.js +3 -0
- package/src/us_autocomplete_pro/Client.js +3 -23
- package/src/us_extract/Client.js +3 -10
- package/src/util/apiToSDKKeyMap.js +29 -0
- package/tests/international_address_autocomplete/test_Client.js +8 -19
- package/tests/international_address_autocomplete/test_Lookup.js +28 -23
- package/tests/us_autocomplete_pro/test_Client.js +7 -12
package/Makefile
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/make -f
|
|
2
2
|
|
|
3
|
-
VERSION := $(shell tagit -
|
|
3
|
+
VERSION := $(shell tagit -p --dry-run)
|
|
4
4
|
VERSION_FILE1 := package.json
|
|
5
5
|
VERSION_FILE2 := package-lock.json
|
|
6
6
|
|
|
@@ -11,7 +11,7 @@ node_modules:
|
|
|
11
11
|
npm install
|
|
12
12
|
|
|
13
13
|
publish: test version upload unversion
|
|
14
|
-
tagit -
|
|
14
|
+
tagit -p
|
|
15
15
|
git push origin --tags
|
|
16
16
|
|
|
17
17
|
upload:
|
|
@@ -2,38 +2,49 @@ const SmartySDK = require("smartystreets-javascript-sdk");
|
|
|
2
2
|
const SmartyCore = SmartySDK.core;
|
|
3
3
|
const Lookup = SmartySDK.internationalAddressAutocomplete.Lookup;
|
|
4
4
|
|
|
5
|
-
//
|
|
6
|
-
let
|
|
5
|
+
// for Server-to-server requests, use this code:
|
|
6
|
+
// let authId = process.env.SMARTY_AUTH_ID;
|
|
7
|
+
// let authToken = process.env.SMARTY_AUTH_TOKEN;
|
|
8
|
+
// const credentials = new SmartyCore.StaticCredentials(authId, authToken);
|
|
9
|
+
|
|
10
|
+
// for client-side requests (browser/mobile), use this code:
|
|
11
|
+
const key = process.env.SMARTY_EMBEDDED_KEY;
|
|
7
12
|
const credentials = new SmartyCore.SharedCredentials(key);
|
|
8
13
|
|
|
9
14
|
// The appropriate license values to be used for your subscriptions
|
|
10
15
|
// can be found on the Subscription page of the account dashboard.
|
|
11
16
|
// https://www.smarty.com/docs/cloud/licensing
|
|
12
|
-
|
|
17
|
+
const clientBuilder = new SmartyCore.ClientBuilder(credentials).withLicenses(["international-autocomplete-v2-cloud"])
|
|
13
18
|
// .withBaseUrl("");
|
|
14
|
-
|
|
19
|
+
const client = clientBuilder.buildInternationalAddressAutocompleteClient();
|
|
15
20
|
|
|
16
21
|
// Documentation for input fields can be found at:
|
|
17
|
-
//www.smarty.com/docs/cloud/international-address-autocomplete-api#pro-http-request-input-fields
|
|
18
|
-
|
|
19
|
-
let lookup = new Lookup("Ave", "CAN");
|
|
20
|
-
await handleRequest(lookup, "Simple Request");
|
|
21
|
-
|
|
22
|
-
// *** Using Filter and Prefer ***
|
|
23
|
-
lookup = new Lookup("Ave", "CAN");
|
|
24
|
-
|
|
25
|
-
lookup.maxResults = 10;
|
|
26
|
-
// lookup.include_only_administrative_area = "";
|
|
27
|
-
lookup.include_only_locality = "Sherwood Park";
|
|
28
|
-
// lookup.include_only_postal_code = "";
|
|
22
|
+
// www.smarty.com/docs/cloud/international-address-autocomplete-api#pro-http-request-input-fields
|
|
23
|
+
const country = "CAN";
|
|
29
24
|
|
|
30
|
-
|
|
25
|
+
const summaryLookup = new Lookup({search: "123 Anson", country});
|
|
26
|
+
await handleRequest(summaryLookup, "Response of summary results");
|
|
31
27
|
|
|
28
|
+
const detailedLookup = new Lookup({addressId: summaryLookup.result[0].addressId, country});
|
|
29
|
+
await handleRequest(detailedLookup, "Response using an address ID to get detailed results");
|
|
32
30
|
|
|
33
31
|
function logSuggestions(response, message) {
|
|
34
|
-
console.log(message);
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
console.log("*** " + message + " ***");
|
|
33
|
+
|
|
34
|
+
response.result.forEach(suggestion => {
|
|
35
|
+
if (suggestion.addressText) {
|
|
36
|
+
console.log("Entries: ", suggestion.entries);
|
|
37
|
+
console.log("Address Text: ", suggestion.addressText);
|
|
38
|
+
console.log("Address ID: ", suggestion.addressId);
|
|
39
|
+
} else {
|
|
40
|
+
console.log("Street: ", suggestion.street);
|
|
41
|
+
console.log("Locality: ", suggestion.locality);
|
|
42
|
+
console.log("Administrative Area: ", suggestion.administrativeArea);
|
|
43
|
+
console.log("Postal Code: ", suggestion.postalCode);
|
|
44
|
+
console.log("Country: ", suggestion.countryIso3);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
console.log("\n");
|
|
37
48
|
}
|
|
38
49
|
|
|
39
50
|
async function handleRequest(lookup, lookupType) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "smartystreets-javascript-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "Quick and easy Smarty address validation.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"smarty",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"chai": "^4.3.6",
|
|
36
|
-
"mocha": "^
|
|
36
|
+
"mocha": "^10.2.0"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"axios": "^
|
|
40
|
-
"axios-retry": "
|
|
39
|
+
"axios": "^1.6.2",
|
|
40
|
+
"axios-retry": "4.0.0"
|
|
41
41
|
}
|
|
42
42
|
}
|
package/src/BaseUrlSender.js
CHANGED
|
@@ -6,7 +6,7 @@ class BaseUrlSender {
|
|
|
6
6
|
|
|
7
7
|
send(request) {
|
|
8
8
|
return new Promise((resolve, reject) => {
|
|
9
|
-
request.baseUrl = this.urlOverride
|
|
9
|
+
request.baseUrl = `${this.urlOverride}${request.baseUrlParam ? `/${request.baseUrlParam}` : ""}`;
|
|
10
10
|
|
|
11
11
|
this.sender.send(request)
|
|
12
12
|
.then(resolve)
|
package/src/ClientBuilder.js
CHANGED
|
@@ -28,7 +28,7 @@ const US_EXTRACT_API_URL = "https://us-extract.api.smarty.com/";
|
|
|
28
28
|
const US_STREET_API_URL = "https://us-street.api.smarty.com/street-address";
|
|
29
29
|
const US_ZIP_CODE_API_URL = "https://us-zipcode.api.smarty.com/lookup";
|
|
30
30
|
const US_REVERSE_GEO_API_URL = "https://us-reverse-geo.api.smarty.com/lookup";
|
|
31
|
-
const INTERNATIONAL_ADDRESS_AUTOCOMPLETE_API_URL = "https://international-autocomplete.api.smarty.com/lookup";
|
|
31
|
+
const INTERNATIONAL_ADDRESS_AUTOCOMPLETE_API_URL = "https://international-autocomplete.api.smarty.com/v2/lookup";
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
34
|
* The ClientBuilder class helps you build a client object for one of the supported Smarty APIs.<br>
|
package/src/InputData.js
CHANGED
|
@@ -5,7 +5,12 @@ class InputData {
|
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
add(apiField, lookupField) {
|
|
8
|
-
if (this.lookupFieldIsPopulated(lookupField)) this.data[apiField] = this.lookup[lookupField];
|
|
8
|
+
if (this.lookupFieldIsPopulated(lookupField)) this.data[apiField] = this.formatData(this.lookup[lookupField]);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
formatData(field) {
|
|
12
|
+
if (Array.isArray(field)) return field.join(";");
|
|
13
|
+
else return field;
|
|
9
14
|
}
|
|
10
15
|
|
|
11
16
|
lookupFieldIsPopulated(lookupField) {
|
package/src/Request.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const Errors = require("../Errors");
|
|
2
2
|
const Request = require("../Request");
|
|
3
3
|
const Suggestion = require("./Suggestion");
|
|
4
|
+
const buildInputData = require("../util/buildInputData");
|
|
5
|
+
const keyTranslationFormat = require("../util/apiToSDKKeyMap").internationalAddressAutocomplete;
|
|
4
6
|
|
|
5
7
|
class Client {
|
|
6
8
|
constructor(sender) {
|
|
@@ -11,14 +13,11 @@ class Client {
|
|
|
11
13
|
if (typeof lookup === "undefined") throw new Errors.UndefinedLookupError();
|
|
12
14
|
|
|
13
15
|
let request = new Request();
|
|
14
|
-
request.parameters =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
include_only_locality: lookup.include_only_locality,
|
|
20
|
-
include_only_postal_code: lookup.include_only_postal_code,
|
|
21
|
-
};
|
|
16
|
+
request.parameters = buildInputData(lookup, keyTranslationFormat);
|
|
17
|
+
|
|
18
|
+
if (lookup.addressId) {
|
|
19
|
+
request.baseUrlParam = lookup.addressId;
|
|
20
|
+
}
|
|
22
21
|
|
|
23
22
|
return new Promise((resolve, reject) => {
|
|
24
23
|
this.sender.send(request)
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
class Lookup {
|
|
2
|
-
constructor(search
|
|
2
|
+
constructor({search, addressId, country, maxResults = 5, includeOnlyLocality, includeOnlyPostalCode} = {}) {
|
|
3
3
|
this.result = [];
|
|
4
4
|
|
|
5
5
|
this.search = search;
|
|
6
|
+
this.addressId = addressId;
|
|
6
7
|
this.country = country;
|
|
7
|
-
this.
|
|
8
|
-
this.
|
|
9
|
-
this.
|
|
10
|
-
this.include_only_postal_code = include_only_postal_code;
|
|
8
|
+
this.maxResults = maxResults;
|
|
9
|
+
this.includeOnlyLocality = includeOnlyLocality;
|
|
10
|
+
this.includeOnlyPostalCode = includeOnlyPostalCode;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
|
|
@@ -5,6 +5,9 @@ class Suggestion {
|
|
|
5
5
|
this.administrativeArea = responseData.administrative_area;
|
|
6
6
|
this.postalCode = responseData.postal_code;
|
|
7
7
|
this.countryIso3 = responseData.country_iso3;
|
|
8
|
+
this.entries = responseData.entries;
|
|
9
|
+
this.addressText = responseData.address_text;
|
|
10
|
+
this.addressId = responseData.address_id;
|
|
8
11
|
}
|
|
9
12
|
}
|
|
10
13
|
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const Errors = require("../Errors");
|
|
2
2
|
const Request = require("../Request");
|
|
3
3
|
const Suggestion = require("./Suggestion");
|
|
4
|
+
const buildInputData = require("../util/buildInputData");
|
|
5
|
+
const keyTranslationFormat = require("../util/apiToSDKKeyMap").usAutocompletePro;
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* This client sends lookups to the Smarty US Autocomplete Pro API, <br>
|
|
@@ -15,7 +17,7 @@ class Client {
|
|
|
15
17
|
if (typeof lookup === "undefined") throw new Errors.UndefinedLookupError();
|
|
16
18
|
|
|
17
19
|
let request = new Request();
|
|
18
|
-
request.parameters =
|
|
20
|
+
request.parameters = buildInputData(lookup, keyTranslationFormat);
|
|
19
21
|
|
|
20
22
|
return new Promise((resolve, reject) => {
|
|
21
23
|
this.sender.send(request)
|
|
@@ -28,28 +30,6 @@ class Client {
|
|
|
28
30
|
.catch(reject);
|
|
29
31
|
});
|
|
30
32
|
|
|
31
|
-
function buildRequestParameters(lookup) {
|
|
32
|
-
return {
|
|
33
|
-
search: lookup.search,
|
|
34
|
-
selected: lookup.selected,
|
|
35
|
-
max_results: lookup.maxResults,
|
|
36
|
-
include_only_cities: joinFieldWith(lookup.includeOnlyCities, ";"),
|
|
37
|
-
include_only_states: joinFieldWith(lookup.includeOnlyStates, ";"),
|
|
38
|
-
include_only_zip_codes: joinFieldWith(lookup.includeOnlyZIPCodes, ";"),
|
|
39
|
-
exclude_states: joinFieldWith(lookup.excludeStates, ";"),
|
|
40
|
-
prefer_cities: joinFieldWith(lookup.preferCities, ";"),
|
|
41
|
-
prefer_states: joinFieldWith(lookup.preferStates, ";"),
|
|
42
|
-
prefer_zip_codes: joinFieldWith(lookup.preferZIPCodes, ";"),
|
|
43
|
-
prefer_ratio: lookup.preferRatio,
|
|
44
|
-
prefer_geolocation: lookup.preferGeolocation,
|
|
45
|
-
source: lookup.source,
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
function joinFieldWith(field, delimiter) {
|
|
49
|
-
if (field.length) return field.join(delimiter);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
33
|
function buildSuggestionsFromResponse(payload) {
|
|
54
34
|
if (payload.suggestions === null) return [];
|
|
55
35
|
|
package/src/us_extract/Client.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const Errors = require("../Errors");
|
|
2
2
|
const Request = require("../Request");
|
|
3
3
|
const Result = require("./Result");
|
|
4
|
+
const buildInputData = require("../util/buildInputData");
|
|
5
|
+
const keyTranslationFormat = require("../util/apiToSDKKeyMap").usExtract;
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* This client sends lookups to the Smarty US Extract API, <br>
|
|
@@ -15,7 +17,7 @@ class Client {
|
|
|
15
17
|
if (typeof lookup === "undefined") throw new Errors.UndefinedLookupError();
|
|
16
18
|
|
|
17
19
|
let request = new Request(lookup.text);
|
|
18
|
-
request.parameters =
|
|
20
|
+
request.parameters = buildInputData(lookup, keyTranslationFormat);
|
|
19
21
|
|
|
20
22
|
return new Promise((resolve, reject) => {
|
|
21
23
|
this.sender.send(request)
|
|
@@ -27,15 +29,6 @@ class Client {
|
|
|
27
29
|
})
|
|
28
30
|
.catch(reject);
|
|
29
31
|
});
|
|
30
|
-
|
|
31
|
-
function buildRequestParams(lookup) {
|
|
32
|
-
return {
|
|
33
|
-
html: lookup.html,
|
|
34
|
-
aggressive: lookup.aggressive,
|
|
35
|
-
addr_line_breaks: lookup.addressesHaveLineBreaks,
|
|
36
|
-
addr_per_line: lookup.addressesPerLine,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
32
|
}
|
|
40
33
|
}
|
|
41
34
|
|
|
@@ -13,6 +13,21 @@ module.exports = {
|
|
|
13
13
|
"format": "format",
|
|
14
14
|
"candidates": "maxCandidates",
|
|
15
15
|
},
|
|
16
|
+
usAutocompletePro: {
|
|
17
|
+
search: "search",
|
|
18
|
+
selected: "selected",
|
|
19
|
+
max_results: "maxResults",
|
|
20
|
+
include_only_cities: "includeOnlyCities",
|
|
21
|
+
include_only_states: "includeOnlyStates",
|
|
22
|
+
include_only_zip_codes: "includeOnlyZIPCodes",
|
|
23
|
+
exclude_states: "excludeStates",
|
|
24
|
+
prefer_cities: "preferCities",
|
|
25
|
+
prefer_states: "preferStates",
|
|
26
|
+
prefer_zip_codes: "preferZIPCodes",
|
|
27
|
+
prefer_ratio: "preferRatio",
|
|
28
|
+
prefer_geolocation: "preferGeolocation",
|
|
29
|
+
source: "source",
|
|
30
|
+
},
|
|
16
31
|
usZipcode: {
|
|
17
32
|
"city": "city",
|
|
18
33
|
"state": "state",
|
|
@@ -32,9 +47,23 @@ module.exports = {
|
|
|
32
47
|
"geocode": "geocode",
|
|
33
48
|
"language": "language",
|
|
34
49
|
},
|
|
50
|
+
internationalAddressAutocomplete: {
|
|
51
|
+
search: "search",
|
|
52
|
+
country: "country",
|
|
53
|
+
max_results: "maxResults",
|
|
54
|
+
include_only_administrative_area: "includeOnlyAdministrativeArea",
|
|
55
|
+
include_only_locality: "includeOnlyLocality",
|
|
56
|
+
include_only_postal_code: "includeOnlyPostalCode",
|
|
57
|
+
},
|
|
35
58
|
usReverseGeo: {
|
|
36
59
|
"latitude": "latitude",
|
|
37
60
|
"longitude": "longitude",
|
|
38
61
|
"source": "source"
|
|
62
|
+
},
|
|
63
|
+
usExtract: {
|
|
64
|
+
html: "html",
|
|
65
|
+
aggressive: "aggressive",
|
|
66
|
+
addr_line_breaks: "addressesHaveLineBreaks",
|
|
67
|
+
addr_per_line: "addressesPerLine",
|
|
39
68
|
}
|
|
40
69
|
};
|
|
@@ -12,14 +12,10 @@ describe("An International Address Autocomplete Client", function () {
|
|
|
12
12
|
let mockSender = new MockSender();
|
|
13
13
|
let client = new Client(mockSender);
|
|
14
14
|
let search = "(";
|
|
15
|
-
let lookup = new Lookup(search);
|
|
15
|
+
let lookup = new Lookup({search});
|
|
16
16
|
let expectedParameters = {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
include_only_administrative_area: "",
|
|
20
|
-
include_only_locality: "",
|
|
21
|
-
include_only_postal_code: "",
|
|
22
|
-
country: "United States",
|
|
17
|
+
max_results: 5,
|
|
18
|
+
search: "(",
|
|
23
19
|
};
|
|
24
20
|
|
|
25
21
|
client.send(lookup);
|
|
@@ -30,15 +26,12 @@ describe("An International Address Autocomplete Client", function () {
|
|
|
30
26
|
let mockSender = new MockSender();
|
|
31
27
|
let client = new Client(mockSender);
|
|
32
28
|
let search = "(";
|
|
33
|
-
let lookup = new Lookup(search);
|
|
29
|
+
let lookup = new Lookup({search});
|
|
34
30
|
lookup.search = search;
|
|
35
31
|
lookup.country = "Russia";
|
|
36
32
|
let expectedParameters = {
|
|
37
33
|
country: "Russia",
|
|
38
|
-
max_results:
|
|
39
|
-
include_only_administrative_area: "",
|
|
40
|
-
include_only_locality: "",
|
|
41
|
-
include_only_postal_code: "",
|
|
34
|
+
max_results: 5,
|
|
42
35
|
search: search,
|
|
43
36
|
};
|
|
44
37
|
|
|
@@ -50,15 +43,11 @@ describe("An International Address Autocomplete Client", function () {
|
|
|
50
43
|
let mockSender = new MockSender();
|
|
51
44
|
let client = new Client(mockSender);
|
|
52
45
|
let search = "(";
|
|
53
|
-
let lookup = new Lookup(search);
|
|
46
|
+
let lookup = new Lookup({search});
|
|
54
47
|
lookup.search = search;
|
|
55
|
-
lookup.
|
|
48
|
+
lookup.maxResults = 10;
|
|
56
49
|
let expectedParameters = {
|
|
57
|
-
country: "United States",
|
|
58
50
|
max_results: 10,
|
|
59
|
-
include_only_administrative_area: "",
|
|
60
|
-
include_only_locality: "",
|
|
61
|
-
include_only_postal_code: "",
|
|
62
51
|
search: search,
|
|
63
52
|
};
|
|
64
53
|
|
|
@@ -87,7 +76,7 @@ describe("An International Address Autocomplete Client", function () {
|
|
|
87
76
|
|
|
88
77
|
let mockSender = new MockSenderWithResponse(responseData);
|
|
89
78
|
let client = new Client(mockSender);
|
|
90
|
-
let lookup = new Lookup("f");
|
|
79
|
+
let lookup = new Lookup({search: "f"});
|
|
91
80
|
let expectedSuggestion = new Suggestion(responseData.candidates[0]);
|
|
92
81
|
|
|
93
82
|
return client.send(lookup).then(() => {
|
|
@@ -5,45 +5,50 @@ const Lookup = require("../../src/international_address_autocomplete/Lookup");
|
|
|
5
5
|
describe("An International Address Autocomplete lookup", function () {
|
|
6
6
|
it("Can be newed up with a prefix", function () {
|
|
7
7
|
const expectedPrefix = "z";
|
|
8
|
-
let lookup = new Lookup(expectedPrefix);
|
|
8
|
+
let lookup = new Lookup({search: expectedPrefix});
|
|
9
9
|
expect(lookup.search).to.equal(expectedPrefix);
|
|
10
10
|
});
|
|
11
11
|
|
|
12
|
-
it("
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
it("Set address ID", function () {
|
|
13
|
+
const addressId = "111";
|
|
14
|
+
let lookup = new Lookup({addressId});
|
|
15
|
+
expect(lookup.addressId).to.equal(addressId);
|
|
15
16
|
});
|
|
16
17
|
|
|
17
|
-
it("
|
|
18
|
+
it("Set country", function () {
|
|
18
19
|
const country = "Russia";
|
|
19
|
-
|
|
20
|
-
let lookup = new Lookup(expectedPrefix, country);
|
|
20
|
+
let lookup = new Lookup({country});
|
|
21
21
|
expect(lookup.country).to.equal(country);
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
-
it("Set
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
expect(lookup.include_only_administrative_area).to.equal(administrativeArea);
|
|
24
|
+
it("Set max results", function () {
|
|
25
|
+
const maxResults = 10000;
|
|
26
|
+
let lookup = new Lookup({maxResults});
|
|
27
|
+
expect(lookup.maxResults).to.equal(maxResults);
|
|
29
28
|
});
|
|
30
29
|
|
|
31
|
-
it("Set include only locality param", function () {
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
expect(lookup.include_only_locality).to.equal(locality);
|
|
30
|
+
it("Set include only include locality param", function () {
|
|
31
|
+
const onlyIncludeLocality = "locality";
|
|
32
|
+
let lookup = new Lookup({includeOnlyLocality: onlyIncludeLocality});
|
|
33
|
+
expect(lookup.includeOnlyLocality).to.equal(onlyIncludeLocality);
|
|
36
34
|
});
|
|
37
35
|
|
|
38
|
-
it("Set include only postal code param", function () {
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
expect(lookup.include_only_postal_code).to.equal(postalCode);
|
|
36
|
+
it("Set include only include postal code param", function () {
|
|
37
|
+
const onlyIncludePostalCode = "post code";
|
|
38
|
+
let lookup = new Lookup({includeOnlyPostalCode: onlyIncludePostalCode});
|
|
39
|
+
expect(lookup.includeOnlyPostalCode).to.equal(onlyIncludePostalCode);
|
|
43
40
|
});
|
|
44
41
|
|
|
45
42
|
it("Checking defaults of params on instantiation ", function () {
|
|
46
|
-
const defaultLookup =
|
|
43
|
+
const defaultLookup = {
|
|
44
|
+
result: [],
|
|
45
|
+
search: undefined,
|
|
46
|
+
addressId: undefined,
|
|
47
|
+
country: undefined,
|
|
48
|
+
maxResults: 5,
|
|
49
|
+
includeOnlyLocality: undefined,
|
|
50
|
+
includeOnlyPostalCode: undefined,
|
|
51
|
+
};
|
|
47
52
|
let lookup = new Lookup();
|
|
48
53
|
expect(lookup).to.deep.equal(defaultLookup);
|
|
49
54
|
});
|
|
@@ -14,19 +14,14 @@ describe("A US Autocomplete Pro Client", function () {
|
|
|
14
14
|
let search = '(>")>#';
|
|
15
15
|
let lookup = new Lookup(search);
|
|
16
16
|
let expectedParameters = {
|
|
17
|
+
exclude_states: "",
|
|
18
|
+
include_only_cities: "",
|
|
19
|
+
include_only_states: "",
|
|
20
|
+
include_only_zip_codes: "",
|
|
21
|
+
prefer_cities: "",
|
|
22
|
+
prefer_states: "",
|
|
23
|
+
prefer_zip_codes: "",
|
|
17
24
|
search: search,
|
|
18
|
-
selected: undefined,
|
|
19
|
-
max_results: undefined,
|
|
20
|
-
include_only_cities: undefined,
|
|
21
|
-
include_only_states: undefined,
|
|
22
|
-
include_only_zip_codes: undefined,
|
|
23
|
-
exclude_states: undefined,
|
|
24
|
-
prefer_cities: undefined,
|
|
25
|
-
prefer_states: undefined,
|
|
26
|
-
prefer_zip_codes: undefined,
|
|
27
|
-
prefer_ratio: undefined,
|
|
28
|
-
prefer_geolocation: undefined,
|
|
29
|
-
source: undefined,
|
|
30
25
|
};
|
|
31
26
|
|
|
32
27
|
client.send(lookup);
|