From 1b2d98b49df9eb4427d5a318d9609bbaac905764 Mon Sep 17 00:00:00 2001 From: Francesco Paolo Severino <96546612+fpseverino@users.noreply.github.com> Date: Mon, 14 Oct 2024 19:37:08 +0200 Subject: [PATCH] Add `.codecov.yml` and README badges (#7) * Add `.codecov.yml` and README badges * Add more code coverage --- .github/.codecov.yml | 35 ++++++++++++ README.md | 3 + Sources/AppleMapsKit/AppleMapsKitError.swift | 4 -- .../Authorization/TokenResponse.swift | 2 +- .../AppleMapsKitTests/AppleMapsKitTests.swift | 55 ++++++++++++++++++- ...erTests.swift => AuthorizationTests.swift} | 18 +++++- 6 files changed, 109 insertions(+), 8 deletions(-) create mode 100644 .github/.codecov.yml rename Tests/AppleMapsKitTests/{AuthorizationProviderTests.swift => AuthorizationTests.swift} (50%) diff --git a/.github/.codecov.yml b/.github/.codecov.yml new file mode 100644 index 0000000..21fccac --- /dev/null +++ b/.github/.codecov.yml @@ -0,0 +1,35 @@ +codecov: + notify: + after_n_builds: 1 + wait_for_ci: false + require_ci_to_pass: false +comment: + behavior: default + layout: diff, files + require_changes: true +coverage: + status: + patch: + default: + branches: + - ^main$ + informational: true + only_pulls: false + paths: + - ^Sources.* + target: auto + project: + default: + branches: + - ^main$ + informational: true + only_pulls: false + paths: + - ^Sources.* + target: auto +github_checks: + annotations: true +ignore: +- ^Tests/.* +- ^.build/.* +slack_app: false \ No newline at end of file diff --git a/README.md b/README.md index 2ee93ec..32b9c22 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,9 @@ [![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Ffpseverino%2Fapple-maps-kit%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/fpseverino/apple-maps-kit) [![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Ffpseverino%2Fapple-maps-kit%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/fpseverino/apple-maps-kit) +[![](https://img.shields.io/github/actions/workflow/status/fpseverino/apple-maps-kit/test.yml?event=push&style=plastic&logo=github&label=tests&logoColor=%23ccc)](https://github.com/fpseverino/apple-maps-kit/actions/workflows/test.yml) +[![](https://img.shields.io/codecov/c/github/fpseverino/apple-maps-kit?style=plastic&logo=codecov&label=codecov)](https://codecov.io/github/fpseverino/apple-maps-kit) + ## Overview Use this web-based service to streamline your app’s API by moving georelated searches for places, points of interest, geocoding, directions, possible autocompletions for searches, and estimated time of arrival (ETA) calculations from inside your app to your server. diff --git a/Sources/AppleMapsKit/AppleMapsKitError.swift b/Sources/AppleMapsKit/AppleMapsKitError.swift index c83f0a4..0a791b4 100644 --- a/Sources/AppleMapsKit/AppleMapsKitError.swift +++ b/Sources/AppleMapsKit/AppleMapsKitError.swift @@ -32,10 +32,6 @@ public struct AppleMapsKitError: Error, Sendable { public var errorType: ErrorType { backing.errorType } - private init(backing: Backing) { - self.backing = backing - } - private init(errorType: ErrorType) { self.backing = .init(errorType: errorType) } diff --git a/Sources/AppleMapsKit/Authorization/TokenResponse.swift b/Sources/AppleMapsKit/Authorization/TokenResponse.swift index 34ad249..c9483ef 100644 --- a/Sources/AppleMapsKit/Authorization/TokenResponse.swift +++ b/Sources/AppleMapsKit/Authorization/TokenResponse.swift @@ -9,7 +9,7 @@ struct TokenResponse: Codable { let expiresInSeconds: Int /// A date that indicates when then token will expire. - let expirationDate: Date + private let expirationDate: Date init(from decoder: any Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) diff --git a/Tests/AppleMapsKitTests/AppleMapsKitTests.swift b/Tests/AppleMapsKitTests/AppleMapsKitTests.swift index c276c11..bbd4cbb 100644 --- a/Tests/AppleMapsKitTests/AppleMapsKitTests.swift +++ b/Tests/AppleMapsKitTests/AppleMapsKitTests.swift @@ -1,8 +1,9 @@ -import AppleMapsKit import AsyncHTTPClient import Foundation import Testing +@testable import AppleMapsKit + @Suite("AppleMapsKit Tests") struct AppleMapsKitTests { var client: AppleMapsClient @@ -101,6 +102,34 @@ struct AppleMapsKitTests { } } + @Test("Search with invalid Result Type") func searchWithInvalidResultType() async throws { + do { + let _ = try await client.search( + for: "eiffel tower", + resultTypeFilter: [.pointOfInterest, .physicalFeature, .poi, .address, .query] + ) + Issue.record("This call should throw an error") + } catch let error as AppleMapsKitError { + #expect(error.errorType.base == .invalidSearchResultType) + } + } + + @Test("Search with Page Token") func searchWithPageToken() async throws { + try await withKnownIssue { + let searchResponse = try await client.search( + for: "eiffel tower", + resultTypeFilter: [.pointOfInterest, .physicalFeature, .poi, .address], + lang: "en-US", + enablePagination: true, + pageToken: "test" + ) + let results = try #require(searchResponse.results) + #expect(!results.isEmpty) + } when: { + credentialsAreInvalid + } + } + @Test( "Search Auto Complete", arguments: zip( @@ -257,4 +286,28 @@ struct AppleMapsKitTests { #expect(AppleMapsKitError.noPlacesFound.description == "AppleMapsKitError(errorType: noPlacesFound)") #expect(AppleMapsKitError.invalidSearchResultType.description == "AppleMapsKitError(errorType: invalidSearchResultType)") } + + @Test("MapRegion.toString") func mapRegionToString() throws { + let mapRegion = MapRegion(northLatitude: 38, eastLongitude: -122.1, southLatitude: 37.5, westLongitude: -122.5) + #expect(mapRegion.toString == "38.0,-122.1,37.5,-122.5") + + let jsonMapRegionWithNil = """ + { + "northLatitude": 38.0, + "eastLongitude": -122.1, + "southLatitude": 37.5 + } + """ + let mapRegionWithNil = try JSONDecoder().decode(MapRegion.self, from: jsonMapRegionWithNil.data(using: .utf8)!) + #expect(mapRegionWithNil.northLatitude == 38.0) + #expect(mapRegionWithNil.eastLongitude == -122.1) + #expect(mapRegionWithNil.southLatitude == 37.5) + #expect(mapRegionWithNil.westLongitude == nil) + #expect(mapRegionWithNil.toString == nil) + } + + @Test("ErrorResponse.description") func errorResponseDescription() { + let errorResponse = ErrorResponse(details: ["detail1", "detail2"], message: "message") + #expect(errorResponse.description == #"AppleMapsKitError(message: message, details: ["detail1", "detail2"])"#) + } } diff --git a/Tests/AppleMapsKitTests/AuthorizationProviderTests.swift b/Tests/AppleMapsKitTests/AuthorizationTests.swift similarity index 50% rename from Tests/AppleMapsKitTests/AuthorizationProviderTests.swift rename to Tests/AppleMapsKitTests/AuthorizationTests.swift index 33ab0ce..17d1f8a 100644 --- a/Tests/AppleMapsKitTests/AuthorizationProviderTests.swift +++ b/Tests/AppleMapsKitTests/AuthorizationTests.swift @@ -5,12 +5,13 @@ // Created by FarouK on 12/10/2024. // +import Foundation import Testing @testable import AppleMapsKit -@Suite("AuthorizationProvider Tests") -struct AuthorizationProviderTests { +@Suite("Authorization Tests") +struct AuthorizationTests { // It's actually 1 second due to the expiration buffer on the token. let token = TokenResponse(accessToken: "test", expiresInSeconds: 11) @@ -22,4 +23,17 @@ struct AuthorizationProviderTests { @Test("Valid Access Token") func validToken() { #expect(token.isValid) } + + @Test("Decoding TokenResponse") func decodingTokenResponse() async throws { + let jsonToken = """ + { + "accessToken": "test", + "expiresInSeconds": 11 + } + """ + let token = try JSONDecoder().decode(TokenResponse.self, from: jsonToken.data(using: .utf8)!) + #expect(token.accessToken == "test") + #expect(token.expiresInSeconds == 11) + #expect(token.isValid) + } }