Skip to content

Commit

Permalink
Improve testing and CI (#5)
Browse files Browse the repository at this point in the history
* Add CODEOWNERS file

* Add more test coverage
  • Loading branch information
fpseverino authored Oct 13, 2024
1 parent e935beb commit 8b0fbc9
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 100 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @fpseverino
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ DerivedData/
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
Package.resolved
.env
.env.*
!.env.example
2 changes: 1 addition & 1 deletion Sources/AppleMapsKit/AppleMapsKitError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ public struct AppleMapsKitError: Error, Sendable {

extension AppleMapsKitError: CustomStringConvertible {
public var description: String {
"AppleMapsKitError(errorType: \(self.errorType)"
"AppleMapsKitError(errorType: \(self.errorType))"
}
}
249 changes: 150 additions & 99 deletions Tests/AppleMapsKitTests/AppleMapsKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import AsyncHTTPClient
import Foundation
import Testing

@Suite("AppleMapsKit Tests", .disabled(if: true, "Needs valid credentials"))
@Suite("AppleMapsKit Tests")
struct AppleMapsKitTests {
var client: AppleMapsClient
// TODO: Replace with `false` when you have valid credentials.
var credentialsAreInvalid = true

init() async throws {
// TODO: Replace the following values with valid ones.
Expand Down Expand Up @@ -37,21 +39,29 @@ struct AppleMapsKitTests {
)
)
func geocode(searchLocation: (latitude: Double, longitude: Double)?, searchRegion: MapRegion?) async throws {
let places = try await client.geocode(
address: "1 Apple Park, Cupertino, CA",
limitToCountries: ["US", "CA"],
lang: "en-US",
searchLocation: searchLocation,
searchRegion: searchRegion,
userLocation: (latitude: 37.78, longitude: -122.42)
)
#expect(!places.isEmpty)
try await withKnownIssue {
let places = try await client.geocode(
address: "1 Apple Park, Cupertino, CA",
limitToCountries: ["US", "CA"],
lang: "en-US",
searchLocation: searchLocation,
searchRegion: searchRegion,
userLocation: (latitude: 37.78, longitude: -122.42)
)
#expect(!places.isEmpty)
} when: {
credentialsAreInvalid
}
}

@Test("Reverse geocode")
func reverseGeocode() async throws {
let places = try await client.reverseGeocode(latitude: 37.33182, longitude: -122.03118, lang: "en-US")
#expect(!places.isEmpty)
try await withKnownIssue {
let places = try await client.reverseGeocode(latitude: 37.33182, longitude: -122.03118, lang: "en-US")
#expect(!places.isEmpty)
} when: {
credentialsAreInvalid
}
}

@Test(
Expand All @@ -68,23 +78,27 @@ struct AppleMapsKitTests {
)
)
func search(searchLocation: (latitude: Double, longitude: Double)?, searchRegion: MapRegion?) async throws {
let searchResponse = try await client.search(
for: "eiffel tower",
excludePoiCategories: [.airport],
includePoiCategories: [.landmark],
limitToCountries: ["US", "CA"],
resultTypeFilter: [.pointOfInterest, .physicalFeature, .poi, .address],
lang: "en-US",
searchLocation: searchLocation,
searchRegion: searchRegion,
userLocation: (latitude: 37.78, longitude: -122.42),
searchRegionPriority: .default,
enablePagination: false,
includeAddressCategories: [.postalCode],
excludeAddressCategories: [.administrativeArea]
)
let results = try #require(searchResponse.results)
#expect(!results.isEmpty)
try await withKnownIssue {
let searchResponse = try await client.search(
for: "eiffel tower",
excludePoiCategories: [.airport],
includePoiCategories: [.landmark],
limitToCountries: ["US", "CA"],
resultTypeFilter: [.pointOfInterest, .physicalFeature, .poi, .address],
lang: "en-US",
searchLocation: searchLocation,
searchRegion: searchRegion,
userLocation: (latitude: 37.78, longitude: -122.42),
searchRegionPriority: .default,
enablePagination: false,
includeAddressCategories: [.postalCode],
excludeAddressCategories: [.administrativeArea]
)
let results = try #require(searchResponse.results)
#expect(!results.isEmpty)
} when: {
credentialsAreInvalid
}
}

@Test(
Expand All @@ -101,21 +115,25 @@ struct AppleMapsKitTests {
)
)
func searchAutoComplete(searchLocation: (latitude: Double, longitude: Double)?, searchRegion: MapRegion?) async throws {
let results = try await client.searchAutoComplete(
for: "eiffel",
excludePoiCategories: [.airport],
includePoiCategories: [.landmark],
limitToCountries: ["US", "CA"],
resultTypeFilter: [.pointOfInterest, .physicalFeature, .poi, .address, .query],
lang: "en-US",
searchLocation: searchLocation,
searchRegion: searchRegion,
userLocation: (latitude: 37.78, longitude: -122.42),
searchRegionPriority: .default,
includeAddressCategories: [.postalCode],
excludeAddressCategories: [.administrativeArea]
)
#expect(!results.isEmpty)
try await withKnownIssue {
let results = try await client.searchAutoComplete(
for: "eiffel",
excludePoiCategories: [.airport],
includePoiCategories: [.landmark],
limitToCountries: ["US", "CA"],
resultTypeFilter: [.pointOfInterest, .physicalFeature, .poi, .address, .query],
lang: "en-US",
searchLocation: searchLocation,
searchRegion: searchRegion,
userLocation: (latitude: 37.78, longitude: -122.42),
searchRegionPriority: .default,
includeAddressCategories: [.postalCode],
excludeAddressCategories: [.administrativeArea]
)
#expect(!results.isEmpty)
} when: {
credentialsAreInvalid
}
}

@Test(
Expand All @@ -132,78 +150,111 @@ struct AppleMapsKitTests {
)
)
func directions(searchLocation: (latitude: Double, longitude: Double)?, searchRegion: MapRegion?) async throws {
let arrivalDirections = try await client.directions(
from: "37.7857,-122.4011",
to: "San Francisco City Hall, CA",
arrivalDate: Date(timeIntervalSinceNow: 3600),
avoid: [.tolls],
lang: "en-US",
requestsAlternateRoutes: true,
searchLocation: searchLocation,
searchRegion: searchRegion,
transportType: .walking,
userLocation: (latitude: 37.78, longitude: -122.42)
)
let arrivalRoutes = try #require(arrivalDirections.routes)
#expect(!arrivalRoutes.isEmpty)
try await withKnownIssue {
let arrivalDirections = try await client.directions(
from: "37.7857,-122.4011",
to: "San Francisco City Hall, CA",
arrivalDate: Date(timeIntervalSinceNow: 3600),
avoid: [.tolls],
lang: "en-US",
requestsAlternateRoutes: true,
searchLocation: searchLocation,
searchRegion: searchRegion,
transportType: .walking,
userLocation: (latitude: 37.78, longitude: -122.42)
)
let arrivalRoutes = try #require(arrivalDirections.routes)
#expect(!arrivalRoutes.isEmpty)
} when: {
credentialsAreInvalid
}

let departureDirections = try await client.directions(
from: "37.7857,-122.4011",
to: "San Francisco City Hall, CA",
avoid: [.tolls],
departureDate: Date(timeIntervalSinceNow: 3600),
lang: "en-US",
requestsAlternateRoutes: true,
searchLocation: searchLocation,
searchRegion: searchRegion,
transportType: .walking,
userLocation: (latitude: 37.78, longitude: -122.42)
)
let departureRoutes = try #require(departureDirections.routes)
#expect(!departureRoutes.isEmpty)
try await withKnownIssue {
let departureDirections = try await client.directions(
from: "37.7857,-122.4011",
to: "San Francisco City Hall, CA",
avoid: [.tolls],
departureDate: Date(timeIntervalSinceNow: 3600),
lang: "en-US",
requestsAlternateRoutes: true,
searchLocation: searchLocation,
searchRegion: searchRegion,
transportType: .walking,
userLocation: (latitude: 37.78, longitude: -122.42)
)
let departureRoutes = try #require(departureDirections.routes)
#expect(!departureRoutes.isEmpty)
} when: {
credentialsAreInvalid
}
}

@Test("ETA", arguments: zip([Date(timeIntervalSinceNow: 3600), nil], [nil, Date(timeIntervalSinceNow: 3600)]))
func eta(arrivalDate: Date?, departureDate: Date?) async throws {
let etas = try await client.eta(
from: (latitude: 37.331423, longitude: -122.030503),
to: [
(latitude: 37.32556561130194, longitude: -121.94635203581443),
(latitude: 37.44176585512703, longitude: -122.17259315798667),
],
transportType: .transit,
departureDate: departureDate,
arrivalDate: arrivalDate
)
#expect(!etas.isEmpty)
try await withKnownIssue {
let etas = try await client.eta(
from: (latitude: 37.331423, longitude: -122.030503),
to: [
(latitude: 37.32556561130194, longitude: -121.94635203581443),
(latitude: 37.44176585512703, longitude: -122.17259315798667),
],
transportType: .transit,
departureDate: departureDate,
arrivalDate: arrivalDate
)
#expect(!etas.isEmpty)
} when: {
credentialsAreInvalid
}
}

@Test("ETA between addresses", arguments: zip([Date(timeIntervalSinceNow: 3600), nil], [nil, Date(timeIntervalSinceNow: 3600)]))
func etaBetweenAddresses(arrivalDate: Date?, departureDate: Date?) async throws {
let etas = try await client.etaBetweenAddresses(
from: "San Francisco City Hall, CA",
to: ["Golden Gate Park, San Francisco"],
transportType: .transit,
departureDate: departureDate,
arrivalDate: arrivalDate
)
#expect(!etas.isEmpty)
try await withKnownIssue {
let etas = try await client.etaBetweenAddresses(
from: "San Francisco City Hall, CA",
to: ["Golden Gate Park, San Francisco"],
transportType: .transit,
departureDate: departureDate,
arrivalDate: arrivalDate
)
#expect(!etas.isEmpty)
} when: {
credentialsAreInvalid
}
}

@Test("Place") func place() async throws {
let place = try await client.place(id: "I7C250D2CDCB364A", lang: "en-US")
#expect(place != nil)
try await withKnownIssue {
let place = try await client.place(id: "I7C250D2CDCB364A", lang: "en-US")
#expect(place != nil)
} when: {
credentialsAreInvalid
}
}

@Test("Places") func places() async throws {
let placesResponse = try await client.places(ids: ["ICFA2FAE5487B94AF", "IA6FD1E86A544F69D"], lang: "en-US")
let errors = try #require(placesResponse.errors)
#expect(!errors.isEmpty)
try await withKnownIssue {
let placesResponse = try await client.places(ids: ["ICFA2FAE5487B94AF", "IA6FD1E86A544F69D"], lang: "en-US")
let errors = try #require(placesResponse.errors)
#expect(!errors.isEmpty)
} when: {
credentialsAreInvalid
}
}

@Test("Alternate Place IDs") func alternatePlaceIDs() async throws {
let alternateIDsResponse = try await client.alternatePlaceIDs(ids: ["I7C250D2CDCB364A", "ICFA2FAE5487B94AF"])
let results = try #require(alternateIDsResponse.results)
#expect(!results.isEmpty)
try await withKnownIssue {
let alternateIDsResponse = try await client.alternatePlaceIDs(ids: ["I7C250D2CDCB364A", "ICFA2FAE5487B94AF"])
let results = try #require(alternateIDsResponse.results)
#expect(!results.isEmpty)
} when: {
credentialsAreInvalid
}
}

@Test("AppleMapsKitError") func appleMapsKitError() {
#expect(AppleMapsKitError.noPlacesFound.description == "AppleMapsKitError(errorType: noPlacesFound)")
#expect(AppleMapsKitError.invalidSearchResultType.description == "AppleMapsKitError(errorType: invalidSearchResultType)")
}
}

0 comments on commit 8b0fbc9

Please sign in to comment.