Skip to content

Commit

Permalink
Rename Message.latestAction to action
Browse files Browse the repository at this point in the history
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] ably/ably-chat-js#427
[2] ably/specification#254
  • Loading branch information
lawrence-forooghian committed Dec 4, 2024
1 parent 5676cac commit 25e3f41
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Example/AblyChatExample/Mocks/Misc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions Example/AblyChatExample/Mocks/MockClients.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ actor MockMessages: Messages {
let subscription = MockSubscription<Message>(randomElement: {
Message(
serial: "\(Date().timeIntervalSince1970)",
latestAction: .create,
action: .create,
clientID: MockStrings.names.randomElement()!,
roomID: self.roomID,
text: MockStrings.randomPhrase(),
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion Sources/AblyChat/ChatAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion Sources/AblyChat/DefaultMessages.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions Sources/AblyChat/Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ 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
public var createdAt: Date?
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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions Tests/AblyChatTests/ChatAPITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct ChatAPITests {
// Then
let expectedMessage = Message(
serial: "3446456",
latestAction: .create,
action: .create,
clientID: "mockClientId",
roomID: roomId,
text: "hello",
Expand Down Expand Up @@ -91,7 +91,7 @@ struct ChatAPITests {
items: [
Message(
serial: "3446456",
latestAction: .create,
action: .create,
clientID: "random",
roomID: roomId,
text: "hello",
Expand All @@ -101,7 +101,7 @@ struct ChatAPITests {
),
Message(
serial: "3446457",
latestAction: .create,
action: .create,
clientID: "random",
roomID: roomId,
text: "hello response",
Expand Down
2 changes: 1 addition & 1 deletion Tests/AblyChatTests/MessageSubscriptionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private final class MockPaginatedResult<T: Equatable>: 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
Expand Down
8 changes: 4 additions & 4 deletions Tests/AblyChatTests/MessageTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -15,7 +15,7 @@ struct MessageTests {

let laterMessage = Message(
serial: "ABC123@1631840000001-5:2",
latestAction: .create,
action: .create,
clientID: "testClientID",
roomID: "roomId",
text: "hello",
Expand All @@ -26,7 +26,7 @@ struct MessageTests {

let invalidMessage = Message(
serial: "invalid",
latestAction: .create,
action: .create,
clientID: "testClientID",
roomID: "roomId",
text: "hello",
Expand Down Expand Up @@ -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: "",
Expand Down
4 changes: 2 additions & 2 deletions Tests/AblyChatTests/Mocks/MockHTTPPaginatedResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -109,7 +109,7 @@ extension MockHTTPPaginatedResponse {
[
"clientId": "random",
"serial": "3446457",
"latestAction": "message.create",
"action": "message.create",
"roomId": "basketball::$chat::$chatMessages",
"text": "hello response",
"metadata": [:],
Expand Down

0 comments on commit 25e3f41

Please sign in to comment.