Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
grdsdev committed Nov 4, 2024
1 parent 72fccff commit cc147e6
Showing 1 changed file with 45 additions and 26 deletions.
71 changes: 45 additions & 26 deletions Tests/RealtimeTests/RealtimeMessageV2Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit cc147e6

Please sign in to comment.