Skip to content
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

Added tests for update of customChannelMetadata. #333

Merged
merged 1 commit into from
Feb 18, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,58 @@ public void getChannelHappyPath() throws PubNubException {
assertEquals(typeValue, getChannelMetadataResult.getData().getType().getValue());
}

@Test
public void canUpdateCustomChannelMetadata() throws PubNubException {
final String channel = randomChannelMetadataId;
final String channelName = "Channel1on1";
final String channelDescription = "Channel for 1on1 conversation";
final String status = "active";
final String type = "1on1";
final Map initialCustom = new HashMap();
initialCustom.put("Days", "Mon-Fri");

final PNSetChannelMetadataResult setChannelMetadataResult = pubNubUnderTest.setChannelMetadata()
.channel(channel)
.description(channelDescription)
.name(channelName)
.custom(initialCustom)
.includeCustom(true)
.status(status)
.type(type)
.sync();

final PNChannelMetadata channelMetadataAfterGet = pubNubUnderTest.getChannelMetadata()
.channel(channel)
.includeCustom(true)
.sync().getData();

Map<String, Object> updatedCustomMetadata = channelMetadataAfterGet.getCustom().getValue();
Map<String, Object> additionalMetadata = new HashMap<>();
additionalMetadata.put("Months", "Jan-May");

updatedCustomMetadata.putAll(additionalMetadata);

final PNSetChannelMetadataResult updatedChannelMetadata = pubNubUnderTest.setChannelMetadata()
.channel(channel)
.custom(updatedCustomMetadata)
.includeCustom(true)
.sync();

PNChannelMetadata updatedData = updatedChannelMetadata.getData();
assertEquals(channel, updatedData.getId());
assertEquals(channelName, updatedData.getName().getValue());
assertEquals(channelDescription, updatedData.getDescription().getValue());
assertEquals(status, updatedData.getStatus().getValue());
assertEquals(type, updatedData.getType().getValue());
Map<String, Object> expectedCustom = new HashMap<>();
expectedCustom.put("Days", "Mon-Fri");
expectedCustom.put("Months","Jan-May");
assertEquals(expectedCustom, updatedData.getCustom().getValue());

// clean up
pubNubUnderTest.removeChannelMetadata().channel(channel).sync();
}

@Test
public void getAllChannelHappyPath() throws PubNubException {
//given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.pubnub.api.models.consumer.objects.PNMembershipKey
import com.pubnub.api.models.consumer.objects.PNPage
import com.pubnub.api.models.consumer.objects.PNSortKey
import com.pubnub.api.models.consumer.objects.channel.PNChannelMetadata
import com.pubnub.api.models.consumer.objects.channel.PNChannelMetadataResult
import com.pubnub.api.models.consumer.objects.member.MemberInclude
import com.pubnub.api.models.consumer.objects.member.PNMember
import com.pubnub.api.models.consumer.objects.member.PNMemberArrayResult
Expand Down Expand Up @@ -35,6 +36,7 @@ import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter.ISO_ZONED_DATE_TIME
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
import kotlin.collections.ArrayList

class ObjectsIntegrationTest : BaseIntegrationTest() {
private val testUserId01 = "ThisIsMyId01" + randomValue()
Expand Down Expand Up @@ -71,6 +73,45 @@ class ObjectsIntegrationTest : BaseIntegrationTest() {
assertTrue(getAllAfterRemovalResult.data.none { it.id == channel })
}

@Test
fun canUpdateCustomChannelMetadata() {
val channelName = "Channel1on1"
val channelDescription = "Channel for 1on1 conversation"
val status = "active"
val type = "1on1"
val initialCustom = mapOf("Days" to "Mon-Fri")

val channelMetadataAfterSet: PNChannelMetadataResult = pubnub.setChannelMetadata(
channel = channel,
name = channelName,
description = channelDescription,
status = status,
type = type,
custom = initialCustom
).sync()

val channelMetadataAfterGet = pubnub.getChannelMetadata(channel = channel, includeCustom = true).sync().data

// Update metadata with additional custom data
val updatedCustomMetadata = (channelMetadataAfterGet.custom?.value ?: emptyMap()) + mapOf("Months" to "Jan-May")
val updatedChannelMetadata = pubnub.setChannelMetadata(
channel = channelMetadataAfterGet.id,
custom = updatedCustomMetadata,
includeCustom = true
).sync()

val updatedData = updatedChannelMetadata.data
assertEquals(channel, updatedData.id)
assertEquals(channelName, updatedData.name?.value)
assertEquals(channelDescription, updatedData.description?.value)
assertEquals(status, updatedData.status?.value)
assertEquals(type, updatedData.type?.value)
val expectedCustom = mapOf("Days" to "Mon-Fri", "Months" to "Jan-May")
assertEquals(expectedCustom, updatedData.custom?.value)

pubnub.removeChannelMetadata(channel = channel).sync()
}

@Test
fun setGetAndRemoveUUIDMetadata() {
// maintenance task: remove all UserMetadata
Expand Down
Loading