Skip to content

Commit a26c237

Browse files
committed
Add tests for BookingsRemote
1 parent b239a5b commit a26c237

File tree

3 files changed

+86
-4
lines changed

3 files changed

+86
-4
lines changed

Modules/Sources/Networking/Model/Bookings/Booking.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,16 @@ public struct Booking: Codable, GeneratedCopiable, Equatable, GeneratedFakeable
8585
alternativeTypes: [.decimal(transform: { NSDecimalNumber(decimal: $0).stringValue })]) ?? ""
8686

8787
let customerID = try container.decode(Int64.self, forKey: .customerID)
88-
let dateCreated = try container.decode(Date.self, forKey: .dateCreated)
89-
let dateModified = try container.decode(Date.self, forKey: .dateModified)
90-
let endDate = try container.decode(Date.self, forKey: .endDate)
88+
let dateCreated = Date(timeIntervalSince1970: try container.decode(Double.self, forKey: .dateCreated))
89+
let dateModified = Date(timeIntervalSince1970: try container.decode(Double.self, forKey: .dateModified))
90+
let endDate = Date(timeIntervalSince1970: try container.decode(Double.self, forKey: .endDate))
9191
let googleCalendarEventID = try container.decodeIfPresent(String.self, forKey: .googleCalendarEventID)
9292
let orderID = try container.decode(Int64.self, forKey: .orderID)
9393
let orderItemID = try container.decode(Int64.self, forKey: .orderItemID)
9494
let parentID = try container.decode(Int64.self, forKey: .parentID)
9595
let productID = try container.decode(Int64.self, forKey: .productID)
9696
let resourceID = try container.decode(Int64.self, forKey: .resourceID)
97-
let startDate = try container.decode(Date.self, forKey: .startDate)
97+
let startDate = Date(timeIntervalSince1970: try container.decode(Double.self, forKey: .startDate))
9898
let statusKey = try container.decode(String.self, forKey: .statusKey)
9999
let localTimezone = try container.decode(String.self, forKey: .localTimezone)
100100

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import Testing
2+
@testable import Networking
3+
4+
struct BookingsRemoteTests {
5+
6+
private let network = MockNetwork()
7+
private let sampleSiteID: Int64 = 1234
8+
9+
@Test func test_loadAllBookings_properly_returns_parsed_bookings() async throws {
10+
// Given
11+
let remote = BookingsRemote(network: network)
12+
network.simulateResponse(requestUrlSuffix: "bookings", filename: "booking-list")
13+
14+
// When
15+
let bookings = try await remote.loadAllBookings(for: sampleSiteID)
16+
17+
// Then
18+
#expect(bookings.count == 2)
19+
let firstBooking = try #require(bookings.first)
20+
#expect(firstBooking.bookingID == 80)
21+
#expect(firstBooking.allDay == false)
22+
#expect(firstBooking.bookingStatus == .unpaid)
23+
#expect(firstBooking.orderID == 79)
24+
#expect(firstBooking.productID == 23)
25+
#expect(firstBooking.customerID == 0)
26+
#expect(firstBooking.siteID == sampleSiteID)
27+
}
28+
29+
@Test func test_loadAllBookings_properly_relays_netwoking_errors() async {
30+
// Given
31+
let remote = BookingsRemote(network: network)
32+
33+
// Then
34+
await #expect(throws: NetworkError.notFound()) {
35+
_ = try await remote.loadAllBookings(for: sampleSiteID)
36+
}
37+
}
38+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"data": [
3+
{
4+
"id": 80,
5+
"start": 1759417200,
6+
"end": 1759420800,
7+
"all_day": false,
8+
"status": "unpaid",
9+
"cost": "30.00",
10+
"currency": "USD",
11+
"customer_id": 0,
12+
"product_id": 23,
13+
"resource_id": 22,
14+
"date_created": 1758531652,
15+
"date_modified": 1758531652,
16+
"google_calendar_event_id": "0",
17+
"order_id": 79,
18+
"order_item_id": 3,
19+
"parent_id": 0,
20+
"person_counts": [],
21+
"local_timezone": "",
22+
},
23+
{
24+
"id": 77,
25+
"start": 1759651200,
26+
"end": 1759654800,
27+
"all_day": false,
28+
"status": "confirmed",
29+
"cost": "35.00",
30+
"currency": "USD",
31+
"customer_id": 2,
32+
"product_id": 23,
33+
"resource_id": 19,
34+
"date_created": 1758530260,
35+
"date_modified": 1758531705,
36+
"google_calendar_event_id": "0",
37+
"order_id": 78,
38+
"order_item_id": 2,
39+
"parent_id": 0,
40+
"person_counts": [],
41+
"local_timezone": "",
42+
}
43+
]
44+
}

0 commit comments

Comments
 (0)