Skip to content

Commit 831f0ec

Browse files
committed
Merge branch 'master' into ryan/hello_types
2 parents 4799717 + 6fa6613 commit 831f0ec

File tree

4 files changed

+18
-43
lines changed

4 files changed

+18
-43
lines changed

src/international_street/Client.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export default class Client {
1818
send(lookup: Lookup): Promise<Lookup> {
1919
if (typeof lookup === "undefined") throw new UndefinedLookupError();
2020

21+
lookup.ensureEnoughInfo();
22+
2123
const request = new Request();
2224
request.parameters = buildInputData(lookup, keyTranslationFormat);
2325

src/international_street/Lookup.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ export type Geocode = "true" | (string & {});
77
const messages = {
88
countryRequired: "Country field is required.",
99
freeformOrAddress1Required: "Either freeform or address1 is required.",
10-
insufficientInformation:
11-
"Insufficient information: One or more required fields were not set on the lookup.",
1210
badGeocode: "Invalid input: geocode can only be set to 'true' (default is 'false'.",
1311
invalidLanguage:
1412
"Invalid input: language can only be set to 'latin' or 'native'. When not set, the the output language will match the language of the input values.",
@@ -72,16 +70,9 @@ export default class Lookup {
7270
ensureEnoughInfo(): boolean {
7371
if (fieldIsMissing(this.country)) throw new UnprocessableEntityError(messages.countryRequired);
7472

75-
if (fieldIsSet(this.freeform)) return true;
76-
77-
if (fieldIsMissing(this.address1))
73+
if (fieldIsMissing(this.freeform) && fieldIsMissing(this.address1))
7874
throw new UnprocessableEntityError(messages.freeformOrAddress1Required);
7975

80-
if (fieldIsSet(this.postalCode)) return true;
81-
82-
if (fieldIsMissing(this.locality) || fieldIsMissing(this.administrativeArea))
83-
throw new UnprocessableEntityError(messages.insufficientInformation);
84-
8576
return true;
8677
}
8778

tests/international_street/test_Client.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ describe("An International Street client", function () {
1313
expect(client.send).to.throw(errors.UndefinedLookupError);
1414
});
1515

16+
it("throws an error if sending an empty lookup.", function () {
17+
let mockSender = new MockSender();
18+
let client = new Client(mockSender);
19+
20+
expect(() => client.send(new Lookup())).to.throw(errors.UnprocessableEntityError, "Country field is required.");
21+
});
22+
23+
it("throws an error if sending a lookup with country but missing freeform and address1.", function () {
24+
let mockSender = new MockSender();
25+
let client = new Client(mockSender);
26+
27+
expect(() => client.send(new Lookup("CA"))).to.throw(errors.UnprocessableEntityError, "Either freeform or address1 is required.");
28+
});
29+
1630
it("correctly assigns request parameters based on lookup input.", function () {
1731
let mockSender = new MockSender();
1832
let client = new Client(mockSender);
@@ -51,7 +65,7 @@ describe("An International Street client", function () {
5165
const expectedMockPayload = [{ address1: "A" }];
5266
let mockSender = new MockSenderWithResponse(expectedMockPayload);
5367
const client = new Client(mockSender);
54-
let lookup = new Lookup();
68+
let lookup = new Lookup("CA", "123 Main St");
5569
let expectedResult = new Candidate({ address1: "A" });
5670

5771
return client.send(lookup).then((_response) => {

tests/international_street/test_Lookup.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ describe("An International Street lookup", function () {
66
const messages = {
77
countryRequired: "Country field is required.",
88
freeformOrAddress1Required: "Either freeform or address1 is required.",
9-
insufficientInformation:
10-
"Insufficient information: One or more required fields were not set on the lookup.",
119
badGeocode: "Invalid input: geocode can only be set to 'true' (default is 'false'.",
1210
invalidLanguage:
1311
"Invalid input: language can only be set to 'latin' or 'native'. When not set, the the output language will match the language of the input values.",
@@ -28,29 +26,6 @@ describe("An International Street lookup", function () {
2826
ensureValidationThrows(new Lookup("a").ensureEnoughInfo, messages.freeformOrAddress1Required);
2927
});
3028

31-
it("rejects lookups with only a country and address 1.", function () {
32-
let lookup = new Lookup("a");
33-
lookup.address1 = "b";
34-
35-
ensureValidationThrows(lookup.ensureEnoughInfo, messages.insufficientInformation);
36-
});
37-
38-
it("rejects lookups with only a country, address 1, and locality.", function () {
39-
let lookup = new Lookup("a");
40-
lookup.address1 = "b";
41-
lookup.locality = "c";
42-
43-
ensureValidationThrows(lookup.ensureEnoughInfo, messages.insufficientInformation);
44-
});
45-
46-
it("rejects lookups with only a country, address 1, and adminstrative area.", function () {
47-
let lookup = new Lookup("a");
48-
lookup.address1 = "b";
49-
lookup.administrativeArea = "c";
50-
51-
ensureValidationThrows(lookup.ensureEnoughInfo, messages.insufficientInformation);
52-
});
53-
5429
it("rejects lookups with an invalid geocode value.", function () {
5530
let lookup = new Lookup();
5631
lookup.geocode = "Blarg!";
@@ -70,16 +45,9 @@ describe("An International Street lookup", function () {
7045

7146
let lookup2 = new Lookup("a");
7247
lookup2.address1 = "b";
73-
lookup2.postalCode = "c";
74-
75-
let lookup3 = new Lookup("a");
76-
lookup3.address1 = "b";
77-
lookup3.locality = "c";
78-
lookup3.administrativeArea = "d";
7948

8049
expect(lookup1.ensureEnoughInfo()).to.equal(true);
8150
expect(lookup2.ensureEnoughInfo()).to.equal(true);
82-
expect(lookup3.ensureEnoughInfo()).to.equal(true);
8351
});
8452

8553
it("accepts lookups with a valid language.", function () {

0 commit comments

Comments
 (0)