@@ -17,24 +17,23 @@ final class NetworkingTests: XCTestCase {
1717 URLQueryItem ( name: " params " , value: " swellHeight,airTemperature " ) ,
1818 ]
1919 let components = StormGlassKit . urlComponents ( apiEndpoint: " weather/point " , queryItems: queryItems)
20-
20+
2121 guard let url = components. url else {
2222 XCTFail ( " Components URL was nil " )
2323 return
2424 }
25-
25+
2626 XCTAssertEqual ( url. absoluteString,
2727 " https://api.stormglass.io/v2/weather/point?lat=19.594379&lng=-155.971668¶ms=swellHeight,airTemperature " )
2828 }
29-
30- @ MainActor func testRequestURL ( ) throws {
29+
30+ func testRequestURLIncludesAuthorization ( ) throws {
3131 let apiKey = " iLikeTurtles "
3232 let coordinate = CLLocationCoordinate2D ( latitude: 19.594379 , longitude: - 155.971668 )
3333 let measurements : Set < WeatherMeasurementName > = [ . swellHeight, . airTemperature]
3434 let start = Date ( timeIntervalSince1970: 1635760800.0 )
3535 let end = Date ( timeIntervalSince1970: 1635847200.0 )
36-
37- StormGlassKit . configure ( with: . init( apiKey: apiKey) )
36+
3837 let request = try StormGlassKit . weatherURLRequest (
3938 apiKey: apiKey,
4039 coordinate: coordinate,
@@ -45,4 +44,30 @@ final class NetworkingTests: XCTestCase {
4544 )
4645 XCTAssertEqual ( request. value ( forHTTPHeaderField: " Authorization " ) , apiKey)
4746 }
47+
48+ func testRequestURLsAreDeterministic( ) throws {
49+ let apiKey = " iLikeTurtles "
50+ let coordinate = CLLocationCoordinate2D ( latitude: 19.594379 , longitude: - 155.971668 )
51+ let measurements = Set ( WeatherMeasurementName . allCases)
52+ let start = Date ( timeIntervalSince1970: 1635760800.0 )
53+ let end = Date ( timeIntervalSince1970: 1635847200.0 )
54+ let sources = Set ( WeatherDataSource . allCases)
55+
56+ var previousRequestURL : URL ?
57+ for _ in 0 ..< 100 {
58+ let request = try StormGlassKit . weatherURLRequest (
59+ apiKey: apiKey,
60+ coordinate: coordinate,
61+ parameters: measurements. map ( \. rawValue) ,
62+ start: start,
63+ end: end,
64+ sources: sources
65+ )
66+ let requestURL = try XCTUnwrap ( request. url)
67+ if let previousRequestURL {
68+ XCTAssertEqual ( requestURL. absoluteString, previousRequestURL. absoluteString)
69+ }
70+ previousRequestURL = requestURL
71+ }
72+ }
4873}
0 commit comments