-
Notifications
You must be signed in to change notification settings - Fork 23
Add additional tests for SubscribeInput and PresenceInput #228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
Tests/PubNubTests/EventEngine/Presence/PresenceInputTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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"] | ||
|
|
@@ -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() { | ||
| let input = SubscribeInput(channels: ["c1", "c2", "c2-pnpres"], channelGroups: ["g1", "g2"]) | ||
| let newInput = input.adding(channels: ["c3", "c3-pnpres"], and: ["g3"]) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could consider testing: |
||
|
|
||
| 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"] | ||
|
|
@@ -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"] | ||
|
|
@@ -109,7 +76,7 @@ class SubscribeInputTests: XCTestCase { | |
| XCTAssertTrue(diff.removedChannelGroups == expRemovedGroups) | ||
| } | ||
|
|
||
| func test_RemovingInputWithPresenceOnly() { | ||
| func test_RemovePresenceOnly() { | ||
| let input1 = SubscribeInput( | ||
| channels: [ | ||
| "c1", | ||
|
|
@@ -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"] | ||
|
|
@@ -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) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.