Skip to content

Commit

Permalink
Turn Incident.Impact type into an enumeration (#519)
Browse files Browse the repository at this point in the history
* Implement initial IncidentImpact enum.

* Make Impact codable.

* Update RouteStepTests: add XCTAssert for Incident.Impact.

* Update CHANGELOG.md

Co-authored-by: Minh Nguyễn <[email protected]>
  • Loading branch information
dersim-davaod and 1ec5 authored Feb 18, 2021
1 parent 0351a3b commit 9af4ddd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changes to Mapbox Directions for Swift

## main

* This library requires Turf v2.0.0-alpha.2. ([#517](https://github.com/mapbox/mapbox-directions-swift/pull/517))
* This library does not support tvOS, watchOS, or Linux. Support for these platforms will be restored before the final release. ([#517](https://github.com/mapbox/mapbox-directions-swift/pull/517))
* The `Incident.impact` property is now an `Incident.Impact` value instead of a string. ([#519](https://github.com/mapbox/mapbox-directions-swift/pull/519))

## v1.2.0

### Packaging
Expand Down
22 changes: 18 additions & 4 deletions Sources/MapboxDirections/Incident.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,21 @@ public struct Incident: Codable, Equatable {
/// Weather
case weather = "weather"
}


/// Represents the impact of the incident on local traffic.
public enum Impact: String, Codable {
/// Unknown impact
case unknown
/// Critical impact
case critical
/// Major impact
case major
/// Minor impact
case minor
/// Low impact
case low
}

/// Incident identifier
public var identifier: String
/// The kind of an incident
Expand All @@ -69,7 +83,7 @@ public struct Incident: Codable, Equatable {
/// Date when incident shall end.
public var endDate: Date
/// Shows severity of an incident. May be not available for all incident types.
public var impact: String?
public var impact: Impact?
/// Provides additional classification of an incident. May be not available for all incident types.
public var subtype: String?
/// Breif description of the subtype. May be not available for all incident types and is not available if `subtype` is `nil`
Expand All @@ -91,7 +105,7 @@ public struct Incident: Codable, Equatable {
creationDate: Date,
startDate: Date,
endDate: Date,
impact: String?,
impact: Impact?,
subtype: String?,
subtypeDescription: String?,
alertCodes: Set<Int>,
Expand Down Expand Up @@ -142,7 +156,7 @@ public struct Incident: Codable, Equatable {
debugDescription: "`Intersection.endTime` is encoded with invalid format.")
}

impact = try container.decodeIfPresent(String.self, forKey: .impact)
impact = try container.decodeIfPresent(Impact.self, forKey: .impact)
subtype = try container.decodeIfPresent(String.self, forKey: .subtype)
subtypeDescription = try container.decodeIfPresent(String.self, forKey: .subtypeDescription)
alertCodes = try container.decode(Set<Int>.self, forKey: .alertCodes)
Expand Down
1 change: 1 addition & 0 deletions Tests/MapboxDirectionsTests/RouteStepTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ class RouteStepTests: XCTestCase {
XCTAssertNotNil(newRoute)

XCTAssert(newRoute!.legs.first!.incidents!.first!.kind == Incident.Kind.miscellaneous)
XCTAssert(newRoute!.legs.first!.incidents!.first!.impact == Incident.Impact.minor)
XCTAssert(newRoute!.legs.first!.incidents![0].lanesBlocked!.contains(.right))
XCTAssertNil(newRoute!.legs.first!.incidents![1].lanesBlocked)
XCTAssert(newRoute!.legs.first!.incidents![2].lanesBlocked!.isEmpty)
Expand Down

0 comments on commit 9af4ddd

Please sign in to comment.