Skip to content

Commit

Permalink
Fixes according to review
Browse files Browse the repository at this point in the history
* Introduce new method for removing Channel metadata
* Fixes for acceptance tests
  • Loading branch information
jguz-pubnub committed Nov 27, 2024
1 parent d84ae06 commit ca74368
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 25 deletions.
23 changes: 22 additions & 1 deletion Sources/PubNub/APIs/Objects+PubNub.swift
Original file line number Diff line number Diff line change
Expand Up @@ -793,16 +793,37 @@ public extension PubNub {
/// - completion: The async `Result` of the method call
/// - **Success**: The Channel identifier of the removed object
/// - **Failure**: An `Error` describing the failure
@available(*, deprecated, renamed: "removeChannelMetadata(_:custom:completion:)")
func remove(
channel metadataId: String,
custom requestConfig: RequestConfiguration = RequestConfiguration(),
completion: ((Result<String, Error>) -> Void)?
) {
removeChannelMetadata(
metadataId,
custom: requestConfig,
completion: completion
)
}

/// Remove metadata for a specified channel.
///
/// - Parameters:
/// - metadataId: Unique Channel Metadata identifier to remove.
/// - custom: Custom configuration overrides for this request
/// - completion: The async `Result` of the method call
/// - **Success**: The Channel identifier of the removed object
/// - **Failure**: An `Error` describing the failure
func removeChannelMetadata(
_ metadataId: String,
custom requestConfig: RequestConfiguration = RequestConfiguration(),
completion: ((Result<String, Error>) -> Void)?
) {
let router = ObjectsChannelRouter(
.remove(metadataId: metadataId),
configuration: requestConfig.customConfiguration ?? configuration
)

route(
router,
responseDecoder: GenericServiceResponseDecoder(),
Expand Down
4 changes: 2 additions & 2 deletions Sources/PubNub/KMP/KMPPubNub+AppContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ public extension KMPPubNub {
}

func removeChannelMetadata(
channel: String,
metadataId: String,
onSuccess: @escaping ((String) -> Void),
onFailure: @escaping ((Error) -> Void)
) {
pubnub.remove(channel: channel) {
pubnub.removeChannelMetadata(metadataId) {
switch $0 {
case .success(let channel):
onSuccess(channel)
Expand Down
2 changes: 1 addition & 1 deletion Tests/PubNubContractTest/PubNubContractTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ let defaultPublishKey = "demo-36"
/// Objects acceptance testins.
PubNubObjectsContractTests().setup()
PubNubObjectsChannelMetadataContractTestSteps().setup()
PubNubObjectsUUIDMetadataContractTestSteps().setup()
PubNubObjectsUserMetadataContractTestSteps().setup()
PubNubObjectsMembershipsContractTestSteps().setup()
PubNubObjectsMembersContractTestSteps().setup()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class PubNubObjectsChannelMetadataContractTestSteps: PubNubObjectsContrac
return
}

self.client.remove(channel: channelMetadataId) { result in
self.client.removeChannelMetadata(channelMetadataId) { result in
switch result {
case let .success(removedChannelMetadataId):
self.handleResult(result: removedChannelMetadataId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Foundation
import PubNubSDK
import XCTest

public class PubNubObjectsUUIDMetadataContractTestSteps: PubNubObjectsContractTests {
public class PubNubObjectsUserMetadataContractTestSteps: PubNubObjectsContractTests {
override public func setup() {
startCucumberHookEventsListening()

Expand All @@ -33,7 +33,7 @@ public class PubNubObjectsUUIDMetadataContractTestSteps: PubNubObjectsContractTe

self.client.fetchUserMetadata(
self.setUserIdAsCurrentUser ? nil : uuidMetadataId,
include: PubNub.IncludeFields(custom: true)
include: PubNub.UserIncludeFields(custom: true)
) { result in
switch result {
case let .success(metadata):
Expand Down Expand Up @@ -111,7 +111,7 @@ public class PubNubObjectsUUIDMetadataContractTestSteps: PubNubObjectsContractTe
includeCustom = PubNub.IncludeFields(custom: flags.contains("with custom"), totalCount: false)
}

self.client.allUserMetadata(include: PubNub.IncludeFields(custom: true)) { result in
self.client.allUserMetadata(include: PubNub.UserIncludeFields(custom: true)) { result in
switch result {
case let .success(metadata):
for uuidMetadata in metadata.users {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class ChannelObjectsEndpointIntegrationTests: XCTestCase {
metadataId: "testCreateAndFetchEndpoint", name: "Swift ITest"
)

client.set(channel: testChannel) { _ in
client.fetch(channel: testChannel.metadataId) { result in
client.setChannelMetadata(testChannel) { _ in
client.fetchChannelMetadata(testChannel.metadataId) { result in
switch result {
case let .success(channel):
XCTAssertEqual(channel.metadataId, testChannel.metadataId)
Expand All @@ -64,8 +64,8 @@ class ChannelObjectsEndpointIntegrationTests: XCTestCase {
metadataId: "testDeleteAndCreateEndpoint", name: "Swift ITest"
)

client.remove(channel: testChannel.metadataId) { _ in
client.set(channel: testChannel) { result in
client.removeChannelMetadata(testChannel.metadataId) { _ in
client.setChannelMetadata(testChannel) { result in
switch result {
case let .success(channel):
XCTAssertEqual(channel.metadataId, testChannel.metadataId)
Expand All @@ -88,8 +88,8 @@ class ChannelObjectsEndpointIntegrationTests: XCTestCase {
metadataId: "testCreateAndDeleteEndpoint", name: "Swift ITest"
)

client.set(channel: testChannel) { _ in
client.remove(channel: testChannel.metadataId) { result in
client.setChannelMetadata(testChannel) { _ in
client.removeChannelMetadata(testChannel.metadataId) { result in
switch result {
case let .success(metadataId):
XCTAssertEqual(metadataId, testChannel.metadataId)
Expand All @@ -115,14 +115,15 @@ class ChannelObjectsEndpointIntegrationTests: XCTestCase {
metadataId: "testFetchMembersChannel", name: "Swift ITest"
)
let membership = PubNubMembershipMetadataBase(
uuidMetadataId: testUser.metadataId,
userMetadataId: testUser.metadataId,
channelMetadataId: testChannel.metadataId,
uuid: testUser, channel: testChannel
user: testUser,
channel: testChannel
)

client.set(uuid: testUser) { _ in
client.set(channel: testChannel) { _ in
client.setMembers(channel: testChannel.metadataId, uuids: [membership]) { _ in
client.setUserMetadata(testUser) { _ in
client.setChannelMetadata(testChannel) { _ in
client.setMembers(channel: testChannel.metadataId, users: [membership]) { _ in
client.fetchMembers(
channel: testChannel.metadataId,
include: .init(uuidFields: true, uuidCustomFields: true)
Expand All @@ -131,7 +132,7 @@ class ChannelObjectsEndpointIntegrationTests: XCTestCase {
case let .success((memberships, _)):
XCTAssertTrue(
memberships.contains(
where: { $0.channelMetadataId == testChannel.metadataId && $0.uuidMetadataId == testUser.metadataId }
where: { $0.channelMetadataId == testChannel.metadataId && $0.userMetadataId == testUser.metadataId }
)
)
case let .failure(error):
Expand All @@ -158,13 +159,14 @@ class ChannelObjectsEndpointIntegrationTests: XCTestCase {
metadataId: "testManageMembersChannel", name: "Swift ITest"
)
let membership = PubNubMembershipMetadataBase(
uuidMetadataId: testUser.metadataId,
userMetadataId: testUser.metadataId,
channelMetadataId: testChannel.metadataId,
uuid: testUser, channel: testChannel
user: testUser,
channel: testChannel
)

client.set(uuid: testUser) { _ in
client.set(channel: testChannel) { _ in
client.setUserMetadata(testUser) { _ in
client.setChannelMetadata(testChannel) { _ in
client.manageMembers(
channel: testChannel.metadataId,
setting: [membership],
Expand All @@ -176,7 +178,7 @@ class ChannelObjectsEndpointIntegrationTests: XCTestCase {
case let .success((memberships, _)):
XCTAssertTrue(
memberships.contains(
where: { $0.channelMetadataId == testChannel.metadataId && $0.uuidMetadataId == testUser.metadataId }
where: { $0.channelMetadataId == testChannel.metadataId && $0.userMetadataId == testUser.metadataId }
)
)
case let .failure(error):
Expand Down

0 comments on commit ca74368

Please sign in to comment.