From f2028d5db2096832c364e535a3123c50c94242e8 Mon Sep 17 00:00:00 2001 From: jguz-pubnub Date: Tue, 19 Nov 2024 12:50:06 +0100 Subject: [PATCH] Fix in other targets --- PubNubSpace/Sources/Space+PubNub.swift | 6 +- PubNubUser/Sources/User+PubNub.swift | 6 +- Sources/PubNub/APIs/Objects+PubNub.swift | 4 +- .../SubscriptionIntegrationTests.swift | 71 +++++++++++++++++++ 4 files changed, 79 insertions(+), 8 deletions(-) diff --git a/PubNubSpace/Sources/Space+PubNub.swift b/PubNubSpace/Sources/Space+PubNub.swift index 13669b12..01fbedb7 100644 --- a/PubNubSpace/Sources/Space+PubNub.swift +++ b/PubNubSpace/Sources/Space+PubNub.swift @@ -197,7 +197,7 @@ public extension PubNubSpaceInterface { ) { let router = ObjectsChannelRouter( .all( - customFields: includeCustom, + include: PubNub.IncludeFields(custom: includeCustom).channelIncludeFields, totalCount: includeTotalCount, filter: filter, sort: sort.map { $0.routerParameter }, @@ -229,7 +229,7 @@ public extension PubNubSpaceInterface { completion: @escaping (Result) -> Void ) { let router = ObjectsChannelRouter( - .fetch(metadataId: spaceId, customFields: includeCustom), + .fetch(metadataId: spaceId, include: PubNub.IncludeFields(custom: includeCustom).channelIncludeFields), configuration: requestConfig.customConfiguration ?? configuration ) @@ -265,7 +265,7 @@ public extension PubNubSpaceInterface { channelDescription: description, custom: custom?.flatJSON ), - customFields: includeCustom + include: PubNub.IncludeFields(custom: includeCustom).channelIncludeFields ), configuration: requestConfig.customConfiguration ?? configuration ) diff --git a/PubNubUser/Sources/User+PubNub.swift b/PubNubUser/Sources/User+PubNub.swift index bb6da9ba..9756aa73 100644 --- a/PubNubUser/Sources/User+PubNub.swift +++ b/PubNubUser/Sources/User+PubNub.swift @@ -205,7 +205,7 @@ public extension PubNubUserInterface { ) { let router = ObjectsUUIDRouter( .all( - customFields: includeCustom, + include: PubNub.IncludeFields(custom: includeCustom).uuidIncludeFields, totalCount: includeTotalCount, filter: filter, sort: sort.map { $0.routerParameter }, @@ -239,7 +239,7 @@ public extension PubNubUserInterface { let router = ObjectsUUIDRouter( .fetch( metadataId: userId ?? (requestConfig.customConfiguration?.uuid ?? configuration.uuid), - customFields: includeCustom + include: PubNub.IncludeFields(custom: includeCustom).uuidIncludeFields ), configuration: requestConfig.customConfiguration ?? configuration ) @@ -280,7 +280,7 @@ public extension PubNubUserInterface { email: email, custom: custom?.flatJSON ), - customFields: includeCustom + include: PubNub.IncludeFields(custom: includeCustom).uuidIncludeFields ), configuration: requestConfig.customConfiguration ?? configuration ) diff --git a/Sources/PubNub/APIs/Objects+PubNub.swift b/Sources/PubNub/APIs/Objects+PubNub.swift index e8c7b22f..a7a734ce 100644 --- a/Sources/PubNub/APIs/Objects+PubNub.swift +++ b/Sources/PubNub/APIs/Objects+PubNub.swift @@ -220,7 +220,7 @@ public extension PubNub { self.totalCount = totalCount } - var uuidIncludeFields: [ObjectsUUIDRouter.Include]? { + public var uuidIncludeFields: [ObjectsUUIDRouter.Include]? { var includes = [ObjectsUUIDRouter.Include]() if customFields { includes.append(.custom) } @@ -230,7 +230,7 @@ public extension PubNub { return includes.isEmpty ? nil : includes } - var channelIncludeFields: [ObjectsChannelRouter.Include]? { + public var channelIncludeFields: [ObjectsChannelRouter.Include]? { var includes = [ObjectsChannelRouter.Include]() if customFields { includes.append(.custom) } diff --git a/Tests/PubNubTests/Integration/SubscriptionIntegrationTests.swift b/Tests/PubNubTests/Integration/SubscriptionIntegrationTests.swift index c6d74e8e..26bd18f0 100644 --- a/Tests/PubNubTests/Integration/SubscriptionIntegrationTests.swift +++ b/Tests/PubNubTests/Integration/SubscriptionIntegrationTests.swift @@ -444,4 +444,75 @@ class SubscriptionIntegrationTests: XCTestCase { wait(for: [expectation], timeout: 5.0) } + + func testMembership() { + let expectation = XCTestExpectation(description: "Description") + expectation.assertForOverFulfill = true + expectation.expectedFulfillmentCount = 1 + + let config = PubNubConfiguration( + publishKey: "pub-c-f210bade-4506-4b99-b572-888bddc01d75", + subscribeKey: "sub-c-9822b8a7-80eb-4320-a2fb-d88d1f37e284", + userId: "JG" + ) + let pubnub = PubNub( + configuration: config + ) + + pubnub.set(uuid: PubNubUUIDMetadataBase(metadataId: "JG", name: "JG")) { [unowned pubnub] in + switch $0 { + case let .success(uuid): + pubnub.set(channel: PubNubChannelMetadataBase(metadataId: "JG-CHANNEL")) { + switch $0 { + case let .success(channel): + pubnub.setMemberships( + uuid: "JG", + channels: [PubNubMembershipMetadataBase(uuidMetadataId: "JG", channelMetadataId: "JG-CHANNEL", status: "mystatus", type: "mytype")], + include: .init(statusField: true, typeField: true) + ) { + switch $0 { + case let .success((memberships, pages)): + expectation.fulfill() + case let .failure(error): + XCTFail("Unexpected condition") + } + } + case let .failure(error): + XCTFail("Unexpected condition") + } + } + case let .failure(error): + XCTFail("Unexpected condition") + } + } + + wait(for: [expectation], timeout: 100) + } + + func testMembership2() { + let expectation = XCTestExpectation(description: "Description") + expectation.assertForOverFulfill = true + expectation.expectedFulfillmentCount = 1 + + let config = PubNubConfiguration( + publishKey: "pub-c-f210bade-4506-4b99-b572-888bddc01d75", + subscribeKey: "sub-c-9822b8a7-80eb-4320-a2fb-d88d1f37e284", + userId: "JG" + ) + let pubnub = PubNub( + configuration: config + ) + + pubnub.fetchMemberships(uuid: "JG", include: .init(statusField: true, typeField: true)) { + switch $0 { + case let .success((memberships, page)): + debugPrint("!") + expectation.fulfill() + case let .failure(error): + XCTFail("Unexpected condition") + } + } + + wait(for: [expectation], timeout: 100) + } }