File tree Expand file tree Collapse file tree 2 files changed +26
-3
lines changed
Sources/AppStoreServerLibrary
Tests/AppStoreServerLibraryTests Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,11 @@ internal func getJsonDecoder() -> JSONDecoder {
19
19
}
20
20
21
21
internal func getJsonEncoder( ) -> JSONEncoder {
22
- let decoder = JSONEncoder ( )
23
- decoder. dateEncodingStrategy = . millisecondsSince1970
24
- return decoder
22
+ let encoder = JSONEncoder ( )
23
+ encoder. dateEncodingStrategy = . custom( { date, e in
24
+ // To encode the same as millisecondsSince1970, however truncating the decimal part
25
+ var container = e. singleValueContainer ( )
26
+ try container. encode ( ( date. timeIntervalSince1970 * 1000.0 ) . rounded ( . towardZero) )
27
+ } )
28
+ return encoder
25
29
}
Original file line number Diff line number Diff line change @@ -246,6 +246,25 @@ final class AppStoreServerAPIClientTests: XCTestCase {
246
246
TestingUtility . confirmCodableInternallyConsistent ( notificationHistoryResponse)
247
247
}
248
248
249
+ public func testGetNotificationHistoryWithMicrosecondValues( ) async throws {
250
+ let client = try getClientWithBody ( " resources/models/getNotificationHistoryResponse.json " ) { request, body in
251
+ let decodedJson = try ! JSONSerialization . jsonObject ( with: body!) as! [ String : Any ]
252
+ XCTAssertEqual ( 1698148900000 , decodedJson [ " startDate " ] as! Int )
253
+ XCTAssertEqual ( 1698148950000 , decodedJson [ " endDate " ] as! Int )
254
+ }
255
+
256
+ let notificationHistoryRequest = NotificationHistoryRequest (
257
+ startDate: Date ( timeIntervalSince1970: 1698148900 ) . advanced ( by: 0.000_9 ) , // 900 microseconds
258
+ endDate: Date ( timeIntervalSince1970: 1698148950 ) . advanced ( by: 0.000_001 ) , // 1 microsecond
259
+ notificationType: NotificationTypeV2 . subscribed,
260
+ notificationSubtype: Subtype . initialBuy,
261
+ transactionId: " 999733843 " ,
262
+ onlyFailures: true
263
+ )
264
+
265
+ let _ = await client. getNotificationHistory ( paginationToken: " a036bc0e-52b8-4bee-82fc-8c24cb6715d6 " , notificationHistoryRequest: notificationHistoryRequest)
266
+ }
267
+
249
268
public func testGetTransactionHistoryV1( ) async throws {
250
269
let client = try getClientWithBody ( " resources/models/transactionHistoryResponse.json " ) { request, body in
251
270
XCTAssertEqual ( . GET, request. method)
You can’t perform that action at this time.
0 commit comments