Skip to content

Commit

Permalink
Add .codecov.yml and README badges (#7)
Browse files Browse the repository at this point in the history
* Add `.codecov.yml` and README badges

* Add more code coverage
  • Loading branch information
fpseverino authored Oct 14, 2024
1 parent 054c12f commit 1b2d98b
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 8 deletions.
35 changes: 35 additions & 0 deletions .github/.codecov.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 0 additions & 4 deletions Sources/AppleMapsKit/AppleMapsKitError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/AppleMapsKit/Authorization/TokenResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
55 changes: 54 additions & 1 deletion Tests/AppleMapsKitTests/AppleMapsKitTests.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import AppleMapsKit
import AsyncHTTPClient
import Foundation
import Testing

@testable import AppleMapsKit

@Suite("AppleMapsKit Tests")
struct AppleMapsKitTests {
var client: AppleMapsClient
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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"])"#)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
}
}

0 comments on commit 1b2d98b

Please sign in to comment.