smartystreets-javascript-sdk
Advanced tools
Comparing version 5.1.4 to 5.2.0
{ | ||
"name": "smartystreets-javascript-sdk", | ||
"version": "5.1.4", | ||
"version": "5.2.0", | ||
"description": "Quick and easy Smarty address validation.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -70,4 +70,44 @@ const Errors = require("../Errors"); | ||
} | ||
sendSecondary(lookup) { | ||
if (typeof lookup === "undefined") throw new Errors.UndefinedLookupError(); | ||
let request = new Request(); | ||
request.parameters = buildInputData(lookup, keyTranslationFormat); | ||
request.baseUrlParam = lookup.smartyKey + "/secondary"; | ||
return new Promise((resolve, reject) => { | ||
this.sender.send(request) | ||
.then(response => { | ||
if (response.error) reject(response.error); | ||
lookup.response = response.payload; | ||
resolve(lookup); | ||
}) | ||
.catch(reject); | ||
}); | ||
} | ||
sendSecondaryCount(lookup) { | ||
if (typeof lookup === "undefined") throw new Errors.UndefinedLookupError(); | ||
let request = new Request(); | ||
request.parameters = buildInputData(lookup, keyTranslationFormat); | ||
request.baseUrlParam = lookup.smartyKey + "/secondary/count"; | ||
return new Promise((resolve, reject) => { | ||
this.sender.send(request) | ||
.then(response => { | ||
if (response.error) reject(response.error); | ||
lookup.response = response.payload; | ||
resolve(lookup); | ||
}) | ||
.catch(reject); | ||
}); | ||
} | ||
} | ||
module.exports = Client; |
@@ -44,2 +44,24 @@ const chai = require("chai"); | ||
it("composes secondary url path properly", function () { | ||
let mockSender = new MockSender(); | ||
let client = new Client(mockSender); | ||
let smartyKey = "0"; | ||
let lookup = new Lookup(smartyKey); | ||
client.sendSecondary(lookup); | ||
expect(mockSender.request.baseUrlParam).to.deep.equal("0/secondary"); | ||
}) | ||
it("composes secondary count url path properly", function () { | ||
let mockSender = new MockSender(); | ||
let client = new Client(mockSender); | ||
let smartyKey = "0"; | ||
let lookup = new Lookup(smartyKey); | ||
client.sendSecondaryCount(lookup); | ||
expect(mockSender.request.baseUrlParam).to.deep.equal("0/secondary/count"); | ||
}) | ||
it("correctly builds parameters for a smartyKey only principal lookup.", function () { | ||
@@ -90,6 +112,36 @@ let mockSender = new MockSender(); | ||
it("correctly builds parameters for a smartyKey only secondary lookup.", function () { | ||
let mockSender = new MockSender(); | ||
let client = new Client(mockSender); | ||
let smartyKey = '(>")>#'; | ||
let include = "1"; | ||
let lookup = new Lookup(smartyKey, include); | ||
let expectedParameters = { | ||
include: include, | ||
}; | ||
client.sendSecondary(lookup); | ||
expect(mockSender.request.parameters).to.deep.equal(expectedParameters); | ||
}); | ||
it("correctly builds parameters for a smartyKey only secondary count lookup.", function () { | ||
let mockSender = new MockSender(); | ||
let client = new Client(mockSender); | ||
let smartyKey = '(>")>#'; | ||
let include = "1"; | ||
let lookup = new Lookup(smartyKey, include); | ||
let expectedParameters = { | ||
include: include, | ||
}; | ||
client.sendSecondaryCount(lookup); | ||
expect(mockSender.request.parameters).to.deep.equal(expectedParameters); | ||
}); | ||
it("correctly builds parameters for a fully-populated principal lookup.", function () { | ||
let mockSender = new MockSender(); | ||
let client = new Client(mockSender); | ||
let lookup = new Lookup("0","1","2","3","4"); | ||
let lookup = new Lookup("0", "1", "2", "3", "4"); | ||
@@ -110,3 +162,3 @@ let expectedParameters = { | ||
let client = new Client(mockSender); | ||
let lookup = new Lookup("0","1","2","3","4"); | ||
let lookup = new Lookup("0", "1", "2", "3", "4"); | ||
@@ -127,3 +179,3 @@ let expectedParameters = { | ||
let client = new Client(mockSender); | ||
let lookup = new Lookup("0","1","2","3","4"); | ||
let lookup = new Lookup("0", "1", "2", "3", "4"); | ||
@@ -141,2 +193,34 @@ let expectedParameters = { | ||
it("correctly builds parameters for a fully-populated secondary lookup.", function () { | ||
let mockSender = new MockSender(); | ||
let client = new Client(mockSender); | ||
let lookup = new Lookup("0", "1", "2", "3", "4"); | ||
let expectedParameters = { | ||
include: "1", | ||
exclude: "2", | ||
dataset: "3", | ||
data_subset: "4", | ||
}; | ||
client.sendSecondary(lookup); | ||
expect(mockSender.request.parameters).to.deep.equal(expectedParameters); | ||
}); | ||
it("correctly builds parameters for a fully-populated secondary count lookup.", function () { | ||
let mockSender = new MockSender(); | ||
let client = new Client(mockSender); | ||
let lookup = new Lookup("0", "1", "2", "3", "4"); | ||
let expectedParameters = { | ||
include: "1", | ||
exclude: "2", | ||
dataset: "3", | ||
data_subset: "4", | ||
}; | ||
client.sendSecondaryCount(lookup); | ||
expect(mockSender.request.parameters).to.deep.equal(expectedParameters); | ||
}); | ||
it("throws an error if sending without a principal lookup.", function () { | ||
@@ -160,2 +244,14 @@ let mockSender = new MockSender(); | ||
it("throws an error if sending without a secondary lookup.", function () { | ||
let mockSender = new MockSender(); | ||
let client = new Client(mockSender); | ||
expect(client.sendSecondary).to.throw(errors.UndefinedLookupError); | ||
}); | ||
it("throws an error if sending without a secondary count lookup.", function () { | ||
let mockSender = new MockSender(); | ||
let client = new Client(mockSender); | ||
expect(client.sendSecondaryCount).to.throw(errors.UndefinedLookupError); | ||
}); | ||
it("rejects with an exception if the principal response comes back with an error.", function () { | ||
@@ -167,3 +263,5 @@ let expectedError = new Error("I'm the error."); | ||
return client.sendPrincipal(lookup).catch((e) => {expect(e).to.equal(expectedError);}); | ||
return client.sendPrincipal(lookup).catch((e) => { | ||
expect(e).to.equal(expectedError); | ||
}); | ||
}); | ||
@@ -177,3 +275,5 @@ | ||
return client.sendFinancial(lookup).catch((e) => {expect(e).to.equal(expectedError);}); | ||
return client.sendFinancial(lookup).catch((e) => { | ||
expect(e).to.equal(expectedError); | ||
}); | ||
}); | ||
@@ -187,5 +287,29 @@ | ||
return client.sendGeo(lookup).catch((e) => {expect(e).to.equal(expectedError);}); | ||
return client.sendGeo(lookup).catch((e) => { | ||
expect(e).to.equal(expectedError); | ||
}); | ||
}); | ||
it("rejects with an exception if the secondary response comes back with an error.", function () { | ||
let expectedError = new Error("I'm the error."); | ||
let mockSender = new MockSenderWithResponse("", expectedError); | ||
let client = new Client(mockSender); | ||
let lookup = new Lookup("¯\\_(ツ)_/¯"); | ||
return client.sendSecondary(lookup).catch((e) => { | ||
expect(e).to.equal(expectedError); | ||
}); | ||
}); | ||
it("rejects with an exception if the secondary count response comes back with an error.", function () { | ||
let expectedError = new Error("I'm the error."); | ||
let mockSender = new MockSenderWithResponse("", expectedError); | ||
let client = new Client(mockSender); | ||
let lookup = new Lookup("¯\\_(ツ)_/¯"); | ||
return client.sendSecondaryCount(lookup).catch((e) => { | ||
expect(e).to.equal(expectedError); | ||
}); | ||
}); | ||
it("returns an empty array when no principal respo are returned.", () => { | ||
@@ -221,2 +345,22 @@ let mockSender = new MockSenderWithResponse({}); | ||
it("returns an empty array when no secondary suggestions are returned.", () => { | ||
let mockSender = new MockSenderWithResponse({}); | ||
let client = new Client(mockSender); | ||
let lookup = new Lookup("smartyKey"); | ||
return client.sendSecondary(lookup).then(response => { | ||
expect(lookup.response).to.deep.equal({}); | ||
}); | ||
}); | ||
it("returns an empty array when no secondary count suggestions are returned.", () => { | ||
let mockSender = new MockSenderWithResponse({}); | ||
let client = new Client(mockSender); | ||
let lookup = new Lookup("smartyKey"); | ||
return client.sendSecondaryCount(lookup).then(response => { | ||
expect(lookup.response).to.deep.equal({}); | ||
}); | ||
}); | ||
it("attaches response to a principal lookup.", function () { | ||
@@ -281,2 +425,42 @@ const rawMockResponse = { | ||
}) | ||
it("attaches response to a secondary lookup.", function () { | ||
const rawMockResponse = { | ||
smarty_key: "a", | ||
data_set_name: "b", | ||
data_subset_name: "c", | ||
attributes: { | ||
assessed_improvement_percent: "1" | ||
}, | ||
}; | ||
let mockResponse = new Response(rawMockResponse); | ||
let mockSender = new MockSenderWithResponse(mockResponse); | ||
let client = new Client(mockSender); | ||
let lookup = new Lookup("smartyKey"); | ||
return client.sendSecondary(lookup).then(response => { | ||
expect(lookup.response).to.deep.equal(mockResponse); | ||
}); | ||
}) | ||
it("attaches response to a secondary count lookup.", function () { | ||
const rawMockResponse = { | ||
smarty_key: "a", | ||
data_set_name: "b", | ||
data_subset_name: "c", | ||
attributes: { | ||
assessed_improvement_percent: "1" | ||
}, | ||
}; | ||
let mockResponse = new Response(rawMockResponse); | ||
let mockSender = new MockSenderWithResponse(mockResponse); | ||
let client = new Client(mockSender); | ||
let lookup = new Lookup("smartyKey"); | ||
return client.sendSecondaryCount(lookup).then(response => { | ||
expect(lookup.response).to.deep.equal(mockResponse); | ||
}); | ||
}) | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
278202
5708