Skip to content

Commit

Permalink
Added tests for update of customChannelMetadata. (#333)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcin-cebo authored Feb 18, 2025
1 parent 83cf30b commit 1b7fe15
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
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

0 comments on commit 1b7fe15

Please sign in to comment.