From cc147e6dffb6c82492054ba3a4626553fce23320 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Mon, 4 Nov 2024 15:01:53 -0300 Subject: [PATCH] fix test --- .../RealtimeMessageV2Tests.swift | 71 ++++++++++++------- 1 file changed, 45 insertions(+), 26 deletions(-) diff --git a/Tests/RealtimeTests/RealtimeMessageV2Tests.swift b/Tests/RealtimeTests/RealtimeMessageV2Tests.swift index fb29b19b..0df944a6 100644 --- a/Tests/RealtimeTests/RealtimeMessageV2Tests.swift +++ b/Tests/RealtimeTests/RealtimeMessageV2Tests.swift @@ -5,56 +5,75 @@ // Created by Guilherme Souza on 26/06/24. // -@testable import Realtime import XCTest +@testable import Realtime + final class RealtimeMessageV2Tests: XCTestCase { func testStatus() { - var message = RealtimeMessageV2(joinRef: nil, ref: nil, topic: "heartbeat", event: "event", payload: ["status": "ok"]) + var message = RealtimeMessageV2( + joinRef: nil, ref: nil, topic: "heartbeat", event: "event", payload: ["status": "ok"]) XCTAssertEqual(message.status, .ok) - message = RealtimeMessageV2(joinRef: nil, ref: nil, topic: "heartbeat", event: "event", payload: ["status": "timeout"]) + message = RealtimeMessageV2( + joinRef: nil, ref: nil, topic: "heartbeat", event: "event", payload: ["status": "timeout"]) XCTAssertEqual(message.status, .timeout) - message = RealtimeMessageV2(joinRef: nil, ref: nil, topic: "heartbeat", event: "event", payload: ["status": "error"]) + message = RealtimeMessageV2( + joinRef: nil, ref: nil, topic: "heartbeat", event: "event", payload: ["status": "error"]) XCTAssertEqual(message.status, .error) - message = RealtimeMessageV2(joinRef: nil, ref: nil, topic: "heartbeat", event: "event", payload: ["status": "invalid"]) + message = RealtimeMessageV2( + joinRef: nil, ref: nil, topic: "heartbeat", event: "event", payload: ["status": "invalid"]) XCTAssertNil(message.status) } func testEventType() { - let payloadWithTokenExpiredMessage: JSONObject = ["message": "access token has expired"] let payloadWithStatusOK: JSONObject = ["status": "ok"] let payloadWithNoStatus: JSONObject = [:] - let systemEventMessage = RealtimeMessageV2(joinRef: nil, ref: nil, topic: "topic", event: ChannelEvent.system, payload: payloadWithStatusOK) - let postgresChangesEventMessage = RealtimeMessageV2(joinRef: nil, ref: nil, topic: "topic", event: ChannelEvent.postgresChanges, payload: payloadWithNoStatus) - let tokenExpiredEventMessage = RealtimeMessageV2(joinRef: nil, ref: nil, topic: "topic", event: ChannelEvent.system, payload: payloadWithTokenExpiredMessage) + let systemEventMessage = RealtimeMessageV2( + joinRef: nil, ref: nil, topic: "topic", event: ChannelEvent.system, + payload: payloadWithStatusOK) + let postgresChangesEventMessage = RealtimeMessageV2( + joinRef: nil, ref: nil, topic: "topic", event: ChannelEvent.postgresChanges, + payload: payloadWithNoStatus) - XCTAssertEqual(systemEventMessage.eventType, .system) - XCTAssertEqual(postgresChangesEventMessage.eventType, .postgresChanges) - XCTAssertEqual(tokenExpiredEventMessage.eventType, .tokenExpired) + XCTAssertEqual(systemEventMessage._eventType, .system) + XCTAssertEqual(postgresChangesEventMessage._eventType, .postgresChanges) - let broadcastEventMessage = RealtimeMessageV2(joinRef: nil, ref: nil, topic: "topic", event: ChannelEvent.broadcast, payload: payloadWithNoStatus) - XCTAssertEqual(broadcastEventMessage.eventType, .broadcast) + let broadcastEventMessage = RealtimeMessageV2( + joinRef: nil, ref: nil, topic: "topic", event: ChannelEvent.broadcast, + payload: payloadWithNoStatus) + XCTAssertEqual(broadcastEventMessage._eventType, .broadcast) - let closeEventMessage = RealtimeMessageV2(joinRef: nil, ref: nil, topic: "topic", event: ChannelEvent.close, payload: payloadWithNoStatus) - XCTAssertEqual(closeEventMessage.eventType, .close) + let closeEventMessage = RealtimeMessageV2( + joinRef: nil, ref: nil, topic: "topic", event: ChannelEvent.close, + payload: payloadWithNoStatus) + XCTAssertEqual(closeEventMessage._eventType, .close) - let errorEventMessage = RealtimeMessageV2(joinRef: nil, ref: nil, topic: "topic", event: ChannelEvent.error, payload: payloadWithNoStatus) - XCTAssertEqual(errorEventMessage.eventType, .error) + let errorEventMessage = RealtimeMessageV2( + joinRef: nil, ref: nil, topic: "topic", event: ChannelEvent.error, + payload: payloadWithNoStatus) + XCTAssertEqual(errorEventMessage._eventType, .error) - let presenceDiffEventMessage = RealtimeMessageV2(joinRef: nil, ref: nil, topic: "topic", event: ChannelEvent.presenceDiff, payload: payloadWithNoStatus) - XCTAssertEqual(presenceDiffEventMessage.eventType, .presenceDiff) + let presenceDiffEventMessage = RealtimeMessageV2( + joinRef: nil, ref: nil, topic: "topic", event: ChannelEvent.presenceDiff, + payload: payloadWithNoStatus) + XCTAssertEqual(presenceDiffEventMessage._eventType, .presenceDiff) - let presenceStateEventMessage = RealtimeMessageV2(joinRef: nil, ref: nil, topic: "topic", event: ChannelEvent.presenceState, payload: payloadWithNoStatus) - XCTAssertEqual(presenceStateEventMessage.eventType, .presenceState) + let presenceStateEventMessage = RealtimeMessageV2( + joinRef: nil, ref: nil, topic: "topic", event: ChannelEvent.presenceState, + payload: payloadWithNoStatus) + XCTAssertEqual(presenceStateEventMessage._eventType, .presenceState) - let replyEventMessage = RealtimeMessageV2(joinRef: nil, ref: nil, topic: "topic", event: ChannelEvent.reply, payload: payloadWithNoStatus) - XCTAssertEqual(replyEventMessage.eventType, .reply) + let replyEventMessage = RealtimeMessageV2( + joinRef: nil, ref: nil, topic: "topic", event: ChannelEvent.reply, + payload: payloadWithNoStatus) + XCTAssertEqual(replyEventMessage._eventType, .reply) - let unknownEventMessage = RealtimeMessageV2(joinRef: nil, ref: nil, topic: "topic", event: "unknown_event", payload: payloadWithNoStatus) - XCTAssertNil(unknownEventMessage.eventType) + let unknownEventMessage = RealtimeMessageV2( + joinRef: nil, ref: nil, topic: "topic", event: "unknown_event", payload: payloadWithNoStatus) + XCTAssertNil(unknownEventMessage._eventType) } }