Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions PubNub.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@
3D867D1D2E422E6E00B03EEE /* KMPPAMToken.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D867D1C2E422E6E00B03EEE /* KMPPAMToken.swift */; };
3D8BAC102B8C96D70059A5C3 /* DependencyContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D8BAC0F2B8C96D70059A5C3 /* DependencyContainer.swift */; };
3D9134972A1216F7000A5124 /* PubNubPushTargetTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D9134962A1216F7000A5124 /* PubNubPushTargetTests.swift */; };
3DA04F2A2EA8C271007F5733 /* PresenceInputTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DA04F292EA8C271007F5733 /* PresenceInputTests.swift */; };
3DA0C7C92BFDF538000FFE6C /* KMPPubNub.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DA0C7C82BFDF538000FFE6C /* KMPPubNub.swift */; };
3DA0C7D02BFE59AC000FFE6C /* SubscriptionListenersContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DA0C7CF2BFE59AC000FFE6C /* SubscriptionListenersContainer.swift */; };
3DA24A312C2AA972005B959B /* KMPPubNub+Listeners.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DA24A302C2AA972005B959B /* KMPPubNub+Listeners.swift */; };
Expand Down Expand Up @@ -1076,6 +1077,7 @@
3D867D1C2E422E6E00B03EEE /* KMPPAMToken.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMPPAMToken.swift; sourceTree = "<group>"; };
3D8BAC0F2B8C96D70059A5C3 /* DependencyContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DependencyContainer.swift; sourceTree = "<group>"; };
3D9134962A1216F7000A5124 /* PubNubPushTargetTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PubNubPushTargetTests.swift; sourceTree = "<group>"; };
3DA04F292EA8C271007F5733 /* PresenceInputTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PresenceInputTests.swift; sourceTree = "<group>"; };
3DA0C7C82BFDF538000FFE6C /* KMPPubNub.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KMPPubNub.swift; sourceTree = "<group>"; };
3DA0C7CF2BFE59AC000FFE6C /* SubscriptionListenersContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriptionListenersContainer.swift; sourceTree = "<group>"; };
3DA24A302C2AA972005B959B /* KMPPubNub+Listeners.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "KMPPubNub+Listeners.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2225,6 +2227,7 @@
3D38A0042B35AF6A006928E7 /* HeartbeatEffectTests.swift */,
3D38A0052B35AF6A006928E7 /* PresenceTransitionTests.swift */,
3D38A0062B35AF6A006928E7 /* LeaveEffectTests.swift */,
3DA04F292EA8C271007F5733 /* PresenceInputTests.swift */,
);
path = Presence;
sourceTree = "<group>";
Expand Down Expand Up @@ -3317,10 +3320,14 @@
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-PubNubContractTests/Pods-PubNubContractTests-frameworks-${CONFIGURATION}-input-files.xcfilelist",
);
inputPaths = (
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-PubNubContractTests/Pods-PubNubContractTests-frameworks-${CONFIGURATION}-output-files.xcfilelist",
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-PubNubContractTests/Pods-PubNubContractTests-frameworks.sh\"\n";
Expand Down Expand Up @@ -3356,10 +3363,14 @@
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-PubNubContractTestsBeta/Pods-PubNubContractTestsBeta-frameworks-${CONFIGURATION}-input-files.xcfilelist",
);
inputPaths = (
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-PubNubContractTestsBeta/Pods-PubNubContractTestsBeta-frameworks-${CONFIGURATION}-output-files.xcfilelist",
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-PubNubContractTestsBeta/Pods-PubNubContractTestsBeta-frameworks.sh\"\n";
Expand Down Expand Up @@ -3803,6 +3814,7 @@
359152AB22BAA6730048842D /* PubNubConfigurationTests.swift in Sources */,
3D38A00D2B35AF6A006928E7 /* EmitMessagesTests.swift in Sources */,
35FE93C322EF57FA0051C455 /* Session+URLErrorTests.swift in Sources */,
3DA04F2A2EA8C271007F5733 /* PresenceInputTests.swift in Sources */,
35FE940122EF983A0051C455 /* Session+EndpointErrorTests.swift in Sources */,
357AEB8422E6954600C18250 /* Collection+PubNubTests.swift in Sources */,
35D0615223035E4300FDB2F9 /* CryptoTests.swift in Sources */,
Expand Down
114 changes: 114 additions & 0 deletions Tests/PubNubTests/EventEngine/Presence/PresenceInputTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
//
// PresenceInputTests.swift
//
// Copyright (c) PubNub Inc.
// All rights reserved.
//
// This source code is licensed under the license found in the
// LICENSE file in the root directory of this source tree.
//

import Foundation
import XCTest

@testable import PubNubSDK

class PresenceInputTests: XCTestCase {
func test_InitWithChannelsAndGroups() {
let input = PresenceInput(channels: ["c1", "c2"], groups: ["g1", "g2"])

XCTAssertTrue(input.channels.sorted(by: <).elementsEqual(["c1", "c2"]))
XCTAssertTrue(input.groups.sorted(by: <).elementsEqual(["g1", "g2"]))
XCTAssertFalse(input.isEmpty)
}

func test_InitEmpty() {
let input = PresenceInput()

XCTAssertTrue(input.channels.isEmpty)
XCTAssertTrue(input.groups.isEmpty)
XCTAssertTrue(input.isEmpty)
}

func test_InitRemovesDuplicates() {
let input = PresenceInput(channels: ["c1", "c1", "c2"], groups: ["g1", "g2", "g2"])

XCTAssertTrue(input.channels.sorted(by: <).elementsEqual(["c1", "c2"]))
XCTAssertTrue(input.groups.sorted(by: <).elementsEqual(["g1", "g2"]))
}

func test_AdditionOperator() {
let input1 = PresenceInput(channels: ["c1", "c2"], groups: ["g1"])
let input2 = PresenceInput(channels: ["c3"], groups: ["g2", "g3"])
let result = input1 + input2

XCTAssertTrue(result.channels.sorted(by: <).elementsEqual(["c1", "c2", "c3"]))
XCTAssertTrue(result.groups.sorted(by: <).elementsEqual(["g1", "g2", "g3"]))
}

func test_AddWithDuplicates() {
let input1 = PresenceInput(channels: ["c1", "c2"], groups: ["g1", "g2"])
let input2 = PresenceInput(channels: ["c2", "c3"], groups: ["g2", "g3"])
let result = input1 + input2

XCTAssertTrue(result.channels.sorted(by: <).elementsEqual(["c1", "c2", "c3"]))
XCTAssertTrue(result.groups.sorted(by: <).elementsEqual(["g1", "g2", "g3"]))
}

func test_SubtractionOperator() {
let input1 = PresenceInput(channels: ["c1", "c2", "c3"], groups: ["g1", "g2", "g3"])
let input2 = PresenceInput(channels: ["c1", "c3"], groups: ["g1", "g3"])
let result = input1 - input2

XCTAssertTrue(result.channels.sorted(by: <).elementsEqual(["c2"]))
XCTAssertTrue(result.groups.sorted(by: <).elementsEqual(["g2"]))
}

func test_SubtractNonExistent() {
let input1 = PresenceInput(channels: ["c1", "c2"], groups: ["g1", "g2", "g3"])
let input2 = PresenceInput(channels: ["c1", "c3", "c4"], groups: ["g1", "g3", "g5"])
let result = input1 - input2

XCTAssertTrue(result.channels.sorted(by: <).elementsEqual(["c2"]))
XCTAssertTrue(result.groups.sorted(by: <).elementsEqual(["g2"]))
}

func test_Equality() {
let input1 = PresenceInput(channels: ["c1", "c2"], groups: ["g1", "g2"])
let input2 = PresenceInput(channels: ["c2", "c1"], groups: ["g2", "g1"])
let input3 = PresenceInput(channels: ["c1", "c3"], groups: ["g1", "g2"])

XCTAssertTrue(input1 == input2)
XCTAssertFalse(input1 == input3)
}

func test_AddEmptyInput() {
let input1 = PresenceInput(channels: ["c1", "c2"], groups: ["g1", "g2"])
let input2 = PresenceInput()
let result = input1 + input2

XCTAssertTrue(result.channels.sorted(by: <).elementsEqual(["c1", "c2"]))
XCTAssertTrue(result.groups.sorted(by: <).elementsEqual(["g1", "g2"]))
XCTAssertTrue(result == input1)
}

func test_SubtractEmptyInput() {
let input1 = PresenceInput(channels: ["c1", "c2"], groups: ["g1", "g2"])
let input2 = PresenceInput()
let result = input1 - input2

XCTAssertTrue(result.channels.sorted(by: <).elementsEqual(["c1", "c2"]))
XCTAssertTrue(result.groups.sorted(by: <).elementsEqual(["g1", "g2"]))
XCTAssertTrue(result == input1)
}

func test_SubtractAll() {
let input1 = PresenceInput(channels: ["c1", "c2"], groups: ["g1", "g2"])
let input2 = PresenceInput(channels: ["c1", "c2"], groups: ["g1", "g2"])
let result = input1 - input2

XCTAssertTrue(result.channels.isEmpty)
XCTAssertTrue(result.groups.isEmpty)
XCTAssertTrue(result.isEmpty)
}
}
85 changes: 32 additions & 53 deletions Tests/PubNubTests/EventEngine/Subscribe/SubscribeInputTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import XCTest
@testable import PubNubSDK

class SubscribeInputTests: XCTestCase {
func test_ChannelsWithoutPresence() {
func test_WithoutPresence() {
let input = SubscribeInput(channels: ["c1", "c2"])
let expAllSubscribedChannelNames = ["c1", "c2"]
let expSubscribedChannelNames = ["c1", "c2"]
Expand All @@ -37,29 +37,11 @@ class SubscribeInputTests: XCTestCase {
XCTAssertTrue(input.channelGroupNames(withPresence: true).sorted(by: <).elementsEqual(expAllSubscribedGroups))
}

func test_addingInputContainsNoDuplicates() {
let input = SubscribeInput(
channels: [
"c1",
"c2",
"c2-pnpres"
],
channelGroups: [
"g1",
"g2"
]
)
let newInput = input.adding(channels: [
"c1",
"c3",
"c3-pnpres"
], and: [
"g1",
"g3"
])
func test_AddWithDuplicates() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessary but nice to have could be a test that intercept REST call and verify channels name.

let input = SubscribeInput(channels: ["c1", "c2", "c2-pnpres"], channelGroups: ["g1", "g2"])
let newInput = input.adding(channels: ["c3", "c3-pnpres"], and: ["g3"])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could consider testing:
let input = SubscribeInput(channels: ["c1", "c1", "c2"], channelGroups: ["g1", "g2", "g2"])


let diff = newInput.difference(from: input)

let expAllSubscribedChannelNames = ["c1", "c2", "c2-pnpres", "c3", "c3-pnpres"]
let expSubscribedChannelNames = ["c1", "c2", "c3"]
let expAllSubscribedGroupNames = ["g1", "g2", "g3"]
Expand All @@ -73,24 +55,9 @@ class SubscribeInputTests: XCTestCase {
XCTAssertTrue(diff.addedChannelGroups == ["g3"])
}

func test_RemovingInput() {
let input1 = SubscribeInput(
channels: [
"c1",
"c2",
"c3"
],
channelGroups: [
"g1",
"g2",
"g3"
]
)
let newInput = input1.removing(
channels: ["c1", "c3"],
and: ["g1", "g3"]
)

func test_Remove() {
let input1 = SubscribeInput(channels: ["c1", "c2", "c3"], channelGroups: ["g1", "g2", "g3"])
let newInput = input1.removing(channels: ["c1", "c3"], and: ["g1", "g3"])
let diff = newInput.difference(from: input1)

let expAllSubscribedChannelNames = ["c2"]
Expand All @@ -109,7 +76,7 @@ class SubscribeInputTests: XCTestCase {
XCTAssertTrue(diff.removedChannelGroups == expRemovedGroups)
}

func test_RemovingInputWithPresenceOnly() {
func test_RemovePresenceOnly() {
let input1 = SubscribeInput(
channels: [
"c1",
Expand All @@ -130,18 +97,10 @@ class SubscribeInputTests: XCTestCase {
"g4-pnpres"
]
)
let presenceChannelsToRemove: Set<String> = [
"c1-pnpres",
"c3-pnpres"
]
let presenceGroupsToRemove: Set<String> = [
"g1-pnpres",
"g3-pnpres"
]
let newInput = input1.removing(
channels: presenceChannelsToRemove,
and: presenceGroupsToRemove
)

let presenceChannelsToRemove: Set<String> = ["c1-pnpres", "c3-pnpres"]
let presenceGroupsToRemove: Set<String> = ["g1-pnpres", "g3-pnpres"]
let newInput = input1.removing(channels: presenceChannelsToRemove, and: presenceGroupsToRemove)

let expAllSubscribedChannelNames = ["c1", "c2", "c2-pnpres", "c3"]
let expSubscribedChannelNames = ["c1", "c2", "c3"]
Expand All @@ -153,4 +112,24 @@ class SubscribeInputTests: XCTestCase {
XCTAssertTrue(newInput.channelGroupNames(withPresence: false).sorted(by: <).elementsEqual(expSubscribedGroupNames))
XCTAssertTrue(newInput.channelGroupNames(withPresence: true).sorted(by: <).elementsEqual(expAllSubscribedGroupNames))
}

func test_RemoveNonExistent() {
let input = SubscribeInput(channels: ["c1", "c2"], channelGroups: ["g1", "g2", "g3"])
let newInput = input.removing(channels: ["c1", "c3", "c4"], and: ["g1", "g3", "g5"])
let diff = newInput.difference(from: input)

let expChannelNames = ["c2"]
let expGroupNames = ["g2"]

// Verify the diff only contains channels/groups that were actually in the original input
let expRemovedChannels = Set(["c1"])
let expRemovedGroups = Set(["g1", "g3"])

XCTAssertTrue(newInput.channelNames(withPresence: false).sorted(by: <).elementsEqual(expChannelNames))
XCTAssertTrue(newInput.channelGroupNames(withPresence: false).sorted(by: <).elementsEqual(expGroupNames))
XCTAssertTrue(diff.removedChannels == expRemovedChannels)
XCTAssertTrue(diff.removedChannelGroups == expRemovedGroups)
XCTAssertTrue(diff.addedChannels.isEmpty)
XCTAssertTrue(diff.addedChannelGroups.isEmpty)
}
}
Loading