diff --git a/src/test/java/io/getstream/ChatChannelIntegrationTest.java b/src/test/java/io/getstream/ChatChannelIntegrationTest.java index 37c15c1..ca73dae 100644 --- a/src/test/java/io/getstream/ChatChannelIntegrationTest.java +++ b/src/test/java/io/getstream/ChatChannelIntegrationTest.java @@ -170,7 +170,8 @@ void testPartialUpdateChannel() throws Exception { assertNotNull(setResp.getData(), "PartialUpdate (set) response should not be null"); assertNotNull(setResp.getData().getChannel(), "Channel in response should not be null"); - var custom = setResp.getData().getChannel().getCustom(); + + var custom = readChannel(channelId).getCustom(); assertNotNull(custom, "Custom data should not be null after set"); assertEquals("red", custom.get("color"), "Custom field 'color' should be 'red'"); @@ -184,12 +185,25 @@ void testPartialUpdateChannel() throws Exception { assertNotNull(unsetResp.getData(), "PartialUpdate (unset) response should not be null"); assertNotNull(unsetResp.getData().getChannel(), "Channel in response should not be null"); - var customAfterUnset = unsetResp.getData().getChannel().getCustom(); + + var customAfterUnset = readChannel(channelId).getCustom(); assertTrue( customAfterUnset == null || !customAfterUnset.containsKey("color"), "Custom field 'color' should be removed after unset"); } + /** + * Reads the channel back from the API. The channel returned by a partial update can lag the write + * it just applied, so state assertions read the channel instead of trusting that response. + */ + private ChannelResponse readChannel(String channelId) throws Exception { + return chat.getOrCreateChannel( + "messaging", channelId, GetOrCreateChannelRequest.builder().build()) + .execute() + .getData() + .getChannel(); + } + @Test @Order(9) void testAddRemoveMembers() throws Exception { @@ -793,7 +807,7 @@ void testFreezeUnfreezeChannel() throws Exception { assertNotNull(freezeResp.getData(), "Freeze response should not be null"); assertNotNull( freezeResp.getData().getChannel(), "Channel in freeze response should not be null"); - Boolean frozenAfterFreeze = freezeResp.getData().getChannel().getFrozen(); + Boolean frozenAfterFreeze = readChannel(channelId).getFrozen(); assertNotNull(frozenAfterFreeze, "Frozen field should not be null after freeze"); assertTrue(frozenAfterFreeze, "Channel should be frozen after setting frozen=true"); @@ -808,7 +822,7 @@ void testFreezeUnfreezeChannel() throws Exception { assertNotNull(unfreezeResp.getData(), "Unfreeze response should not be null"); assertNotNull( unfreezeResp.getData().getChannel(), "Channel in unfreeze response should not be null"); - Boolean frozenAfterUnfreeze = unfreezeResp.getData().getChannel().getFrozen(); + Boolean frozenAfterUnfreeze = readChannel(channelId).getFrozen(); assertNotNull(frozenAfterUnfreeze, "Frozen field should not be null after unfreeze"); assertFalse(frozenAfterUnfreeze, "Channel should be unfrozen after setting frozen=false"); }