From 25e3f41b5756fd11635d8b62558faf121e414a41 Mon Sep 17 00:00:00 2001 From: Lawrence Forooghian Date: Wed, 4 Dec 2024 13:42:29 -0300 Subject: [PATCH] Rename `Message.latestAction` to `action` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Upon our integration tests starting to fail, we noticed that Realtime seems to have renamed the `latestAction` property to `action`. This change has not yet been reflected in the spec, but has been in JS [1]. I’ve created an issue to get the spec updated [2] but since this test failure is stopping us from merging anything else I am going to rename this property until we get a more definitive answer. Part of #169. [1] https://github.com/ably/ably-chat-js/pull/427 [2] https://github.com/ably/specification/issues/254 --- Example/AblyChatExample/Mocks/Misc.swift | 2 +- Example/AblyChatExample/Mocks/MockClients.swift | 4 ++-- Sources/AblyChat/ChatAPI.swift | 2 +- Sources/AblyChat/DefaultMessages.swift | 2 +- Sources/AblyChat/Message.swift | 8 ++++---- Tests/AblyChatTests/ChatAPITests.swift | 6 +++--- Tests/AblyChatTests/MessageSubscriptionTests.swift | 2 +- Tests/AblyChatTests/MessageTests.swift | 8 ++++---- Tests/AblyChatTests/Mocks/MockHTTPPaginatedResponse.swift | 4 ++-- 9 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Example/AblyChatExample/Mocks/Misc.swift b/Example/AblyChatExample/Mocks/Misc.swift index 9a0c2587..790b4e19 100644 --- a/Example/AblyChatExample/Mocks/Misc.swift +++ b/Example/AblyChatExample/Mocks/Misc.swift @@ -12,7 +12,7 @@ final class MockMessagesPaginatedResult: PaginatedResult { Array(repeating: 0, count: numberOfMockMessages).map { _ in Message( serial: "\(Date().timeIntervalSince1970)", - latestAction: .create, + action: .create, clientID: self.clientID, roomID: self.roomID, text: MockStrings.randomPhrase(), diff --git a/Example/AblyChatExample/Mocks/MockClients.swift b/Example/AblyChatExample/Mocks/MockClients.swift index 831d7044..1a950d65 100644 --- a/Example/AblyChatExample/Mocks/MockClients.swift +++ b/Example/AblyChatExample/Mocks/MockClients.swift @@ -104,7 +104,7 @@ actor MockMessages: Messages { let subscription = MockSubscription(randomElement: { Message( serial: "\(Date().timeIntervalSince1970)", - latestAction: .create, + action: .create, clientID: MockStrings.names.randomElement()!, roomID: self.roomID, text: MockStrings.randomPhrase(), @@ -130,7 +130,7 @@ actor MockMessages: Messages { func send(params: SendMessageParams) async throws -> Message { let message = Message( serial: "\(Date().timeIntervalSince1970)", - latestAction: .create, + action: .create, clientID: clientID, roomID: roomID, text: params.text, diff --git a/Sources/AblyChat/ChatAPI.swift b/Sources/AblyChat/ChatAPI.swift index 3792d0f8..9ea9978d 100644 --- a/Sources/AblyChat/ChatAPI.swift +++ b/Sources/AblyChat/ChatAPI.swift @@ -46,7 +46,7 @@ internal final class ChatAPI: Sendable { let message = Message( serial: response.serial, - latestAction: .create, + action: .create, clientID: clientId, roomID: roomId, text: params.text, diff --git a/Sources/AblyChat/DefaultMessages.swift b/Sources/AblyChat/DefaultMessages.swift index 5c2fea1b..03339058 100644 --- a/Sources/AblyChat/DefaultMessages.swift +++ b/Sources/AblyChat/DefaultMessages.swift @@ -83,7 +83,7 @@ internal final class DefaultMessages: Messages, EmitsDiscontinuities { let message = Message( serial: serial, - latestAction: action, + action: action, clientID: clientID, roomID: self.roomID, text: text, diff --git a/Sources/AblyChat/Message.swift b/Sources/AblyChat/Message.swift index a9053b7c..b781bad5 100644 --- a/Sources/AblyChat/Message.swift +++ b/Sources/AblyChat/Message.swift @@ -9,7 +9,7 @@ public struct Message: Sendable, Codable, Identifiable, Equatable { public var id: String { serial } public var serial: String - public var latestAction: MessageAction + public var action: MessageAction public var clientID: String public var roomID: String public var text: String @@ -17,9 +17,9 @@ public struct Message: Sendable, Codable, Identifiable, Equatable { public var metadata: MessageMetadata public var headers: MessageHeaders - public init(serial: String, latestAction: MessageAction, clientID: String, roomID: String, text: String, createdAt: Date?, metadata: MessageMetadata, headers: MessageHeaders) { + public init(serial: String, action: MessageAction, clientID: String, roomID: String, text: String, createdAt: Date?, metadata: MessageMetadata, headers: MessageHeaders) { self.serial = serial - self.latestAction = latestAction + self.action = action self.clientID = clientID self.roomID = roomID self.text = text @@ -30,7 +30,7 @@ public struct Message: Sendable, Codable, Identifiable, Equatable { internal enum CodingKeys: String, CodingKey { case serial - case latestAction + case action case clientID = "clientId" case roomID = "roomId" case text diff --git a/Tests/AblyChatTests/ChatAPITests.swift b/Tests/AblyChatTests/ChatAPITests.swift index 8564ed6f..e160d3ff 100644 --- a/Tests/AblyChatTests/ChatAPITests.swift +++ b/Tests/AblyChatTests/ChatAPITests.swift @@ -41,7 +41,7 @@ struct ChatAPITests { // Then let expectedMessage = Message( serial: "3446456", - latestAction: .create, + action: .create, clientID: "mockClientId", roomID: roomId, text: "hello", @@ -91,7 +91,7 @@ struct ChatAPITests { items: [ Message( serial: "3446456", - latestAction: .create, + action: .create, clientID: "random", roomID: roomId, text: "hello", @@ -101,7 +101,7 @@ struct ChatAPITests { ), Message( serial: "3446457", - latestAction: .create, + action: .create, clientID: "random", roomID: roomId, text: "hello response", diff --git a/Tests/AblyChatTests/MessageSubscriptionTests.swift b/Tests/AblyChatTests/MessageSubscriptionTests.swift index 7bbea980..c6d27ade 100644 --- a/Tests/AblyChatTests/MessageSubscriptionTests.swift +++ b/Tests/AblyChatTests/MessageSubscriptionTests.swift @@ -26,7 +26,7 @@ private final class MockPaginatedResult: PaginatedResult { struct MessageSubscriptionTests { let messages = ["First", "Second"].map { text in - Message(serial: "", latestAction: .create, clientID: "", roomID: "", text: text, createdAt: .init(), metadata: [:], headers: [:]) + Message(serial: "", action: .create, clientID: "", roomID: "", text: text, createdAt: .init(), metadata: [:], headers: [:]) } @Test diff --git a/Tests/AblyChatTests/MessageTests.swift b/Tests/AblyChatTests/MessageTests.swift index 115fdbd1..e085d72a 100644 --- a/Tests/AblyChatTests/MessageTests.swift +++ b/Tests/AblyChatTests/MessageTests.swift @@ -4,7 +4,7 @@ import Testing struct MessageTests { let earlierMessage = Message( serial: "ABC123@1631840000000-5:2", - latestAction: .create, + action: .create, clientID: "testClientID", roomID: "roomId", text: "hello", @@ -15,7 +15,7 @@ struct MessageTests { let laterMessage = Message( serial: "ABC123@1631840000001-5:2", - latestAction: .create, + action: .create, clientID: "testClientID", roomID: "roomId", text: "hello", @@ -26,7 +26,7 @@ struct MessageTests { let invalidMessage = Message( serial: "invalid", - latestAction: .create, + action: .create, clientID: "testClientID", roomID: "roomId", text: "hello", @@ -70,7 +70,7 @@ struct MessageTests { func isEqual_whenMessageIsEqual_ReturnsTrue() async throws { let duplicateOfEarlierMessage = Message( serial: "ABC123@1631840000000-5:2", - latestAction: .create, + action: .create, clientID: "random", roomID: "", text: "", diff --git a/Tests/AblyChatTests/Mocks/MockHTTPPaginatedResponse.swift b/Tests/AblyChatTests/Mocks/MockHTTPPaginatedResponse.swift index e31e2086..43587ae7 100644 --- a/Tests/AblyChatTests/Mocks/MockHTTPPaginatedResponse.swift +++ b/Tests/AblyChatTests/Mocks/MockHTTPPaginatedResponse.swift @@ -99,7 +99,7 @@ extension MockHTTPPaginatedResponse { [ "clientId": "random", "serial": "3446456", - "latestAction": "message.create", + "action": "message.create", "createdAt": 1_730_943_049_269, "roomId": "basketball::$chat::$chatMessages", "text": "hello", @@ -109,7 +109,7 @@ extension MockHTTPPaginatedResponse { [ "clientId": "random", "serial": "3446457", - "latestAction": "message.create", + "action": "message.create", "roomId": "basketball::$chat::$chatMessages", "text": "hello response", "metadata": [:],