Skip to content

Commit

Permalink
fix: update format
Browse files Browse the repository at this point in the history
  • Loading branch information
Mercy811 committed Oct 24, 2023
1 parent 2c397cf commit 2be2931
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 4 additions & 2 deletions Sources/Amplitude/Utilities/HttpClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ class HttpClient {
return request
}

func getRequestData(events: String) -> Data? {
func getRequestData(events: String, currentTime: Date = Date()) -> Data? {
let apiKey = configuration.apiKey
let clientUploadTime: String = ISO8601DateFormatter().string(from: Date())
let formatter = ISO8601DateFormatter()
formatter.formatOptions.insert(.withFractionalSeconds)
let clientUploadTime: String = formatter.string(from: currentTime)
var requestPayload = """
{"api_key":"\(apiKey)","client_upload_time":"\(clientUploadTime)","events":\(events)
"""
Expand Down
8 changes: 3 additions & 5 deletions Tests/AmplitudeTests/Utilities/HttpClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,13 @@ final class HttpClientTests: XCTestCase {
let httpClient = HttpClient(configuration: configuration)
let event = BaseEvent(userId: "unit-test user", eventType: "unit-test event")

let dateFormatter = ISO8601DateFormatter()
let currentDate = Date()
let expectedClientUploadTime = dateFormatter.string(from: currentDate)
let currentTime = Date(timeIntervalSince1970: 1698171384)

let expectedRequestPayload = """
{"api_key":"testApiKey","client_upload_time":"\(expectedClientUploadTime)","events":[\(event.toString())]}
{"api_key":"testApiKey","client_upload_time":"2023-10-24T18:16:24.000Z","events":[\(event.toString())]}
""".data(using: .utf8)

let result = httpClient.getRequestData(events: "[\(event.toString())]")
let result = httpClient.getRequestData(events: "[\(event.toString())]", currentTime: currentTime)

XCTAssertEqual(result, expectedRequestPayload)
}
Expand Down

0 comments on commit 2be2931

Please sign in to comment.