Skip to content

Commit

Permalink
Added format to lookup for project-usa (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjohnsonsmarty authored Oct 26, 2023
1 parent c98bd02 commit 2b34bd2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Sources/SmartyStreets/USStreet/USStreetClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public class USStreetClient: NSObject {
populate(value: lookup.addressee, field: "addressee", request: request)
populate(value: lookup.urbanization, field: "urbanization", request: request)
populate(value: lookup.matchStrategy, field: "match", request: request)
populate(value: lookup.outputFormat, field: "format", request: request)

}

func populate(value:String!, field:String, request:SmartyRequest) {
Expand Down
3 changes: 2 additions & 1 deletion Sources/SmartyStreets/USStreet/USStreetLookup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import Foundation
}
}
public var matchStrategy:String?
public var outputFormat:String?

override public init() {
self.maxCandidates = 1
Expand Down Expand Up @@ -70,7 +71,7 @@ import Foundation
dictionary = addValueToDictionary(value: self.urbanization, key: "urbanization", dictionary: dictionary)
dictionary = addValueToDictionary(value: self.maxCandidates, key: "candidates", dictionary: dictionary)
dictionary = addValueToDictionary(value: self.matchStrategy, key: "match", dictionary: dictionary)

dictionary = addValueToDictionary(value: self.outputFormat, key: "format", dictionary: dictionary)
return dictionary
}

Expand Down
29 changes: 27 additions & 2 deletions Tests/SmartyStreetsTests/USStreetTests/USStreetClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class USStreetClientTests: XCTestCase {
let sender = URLPrefixSender(urlPrefix: "http://localhost/", inner: capturingSender)
let client = USStreetClient(sender: sender, serializer: serializer)
var lookup = USStreetLookup()

lookup.addressee = "0"
lookup.street = "1"
lookup.secondary = "2"
Expand All @@ -49,10 +49,35 @@ class USStreetClientTests: XCTestCase {
lookup.lastline = "8"
lookup.setMaxCandidates(max: 9, error: &self.error)
XCTAssertNil(self.error)


_ = client.sendLookup(lookup: &lookup, error: &self.error)
XCTAssertNil(self.error)
XCTAssertNotNil(capturingSender.request.getUrl())
}

func testSendingSingleFullyPopulatedLookupWithFormatField() {
let capturingSender = RequestCapturingSender()
let sender = URLPrefixSender(urlPrefix: "http://localhost/", inner: capturingSender)
let client = USStreetClient(sender: sender, serializer: serializer)
var lookup = USStreetLookup()

lookup.addressee = "0"
lookup.street = "1"
lookup.secondary = "2"
lookup.street2 = "3"
lookup.urbanization = "4"
lookup.city = "5"
lookup.state = "6"
lookup.zipCode = "7"
lookup.lastline = "8"
lookup.setMaxCandidates(max: 9, error: &self.error)
lookup.outputFormat = "10"
XCTAssertNil(self.error)

_ = client.sendLookup(lookup: &lookup, error: &self.error)
XCTAssertNil(self.error)
XCTAssertNotNil(capturingSender.request.getUrl())
XCTAssertTrue(capturingSender.request.getUrl().contains("format=10"))
}

func testFullBatch() {
Expand Down

0 comments on commit 2b34bd2

Please sign in to comment.