Skip to content

Commit

Permalink
fix: additional fields mutable
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdeme committed Mar 18, 2022
1 parent 85c19b2 commit 478d505
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @ferhatelmas @miagilepner @driver-devel
* @ferhatelmas @driver-devel @peterdeme
19 changes: 19 additions & 0 deletions src/main/java/io/getstream/chat/java/models/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,25 @@ public void setAdditionalField(String name, Object value) {
public static ChannelRequestObject buildFrom(@Nullable Channel channel) {
return RequestObjectBuilder.build(ChannelRequestObject.class, channel);
}

private ChannelRequestObject(
@Nullable UserRequestObject createdBy,
@Nullable String team,
@Nullable Boolean autoTranslationEnabled,
@Nullable Language autoTranslationLanguage,
@Nullable Boolean frozen,
@Nullable List<ChannelMemberRequestObject> members,
@Nullable ConfigOverridesRequestObject configOverrides,
Map<String, Object> additionalFields) {
this.createdBy = createdBy;
this.team = team;
this.autoTranslationEnabled = autoTranslationEnabled;
this.autoTranslationLanguage = autoTranslationLanguage;
this.frozen = frozen;
this.members = members;
this.configOverrides = configOverrides;
this.additionalFields = new HashMap<String, Object>(additionalFields);
}
}

@Builder
Expand Down
41 changes: 41 additions & 0 deletions src/test/java/io/getstream/chat/java/ChannelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,47 @@ void whenRetrievingChannel_thenNoException() {
.request());
}

@DisplayName("Can set custom field on channel")
@Test
void whenSettingCustomField_thenNoException() {
var channelReq =
ChannelRequestObject.builder()
.createdBy(testUserRequestObject)
.members(buildChannelMembersList())
.build();
channelReq.setAdditionalField("fieldkey", "fieldvalue");
var channel =
Assertions.assertDoesNotThrow(
() ->
Channel.getOrCreate(testChannel.getType(), RandomStringUtils.randomAlphabetic(12))
.data(channelReq)
.request());
Assertions.assertEquals(
"fieldvalue", channel.getChannel().getAdditionalFields().get("fieldkey"));
}

@DisplayName("Can set custom field on channel after fields have already been set in builder")
@Test
void whenSettingCustomFieldInBuilderAndAfer_thenNoException() {
var channelReq =
ChannelRequestObject.builder()
.createdBy(testUserRequestObject)
.members(buildChannelMembersList())
.additionalField("fieldkey1", "fieldvalue1")
.build();
channelReq.setAdditionalField("fieldkey2", "fieldvalue2");
var channel =
Assertions.assertDoesNotThrow(
() ->
Channel.getOrCreate(testChannel.getType(), RandomStringUtils.randomAlphabetic(12))
.data(channelReq)
.request());
Assertions.assertEquals(
"fieldvalue1", channel.getChannel().getAdditionalFields().get("fieldkey1"));
Assertions.assertEquals(
"fieldvalue2", channel.getChannel().getAdditionalFields().get("fieldkey2"));
}

@DisplayName("Can add a moderator to a channel (update)")
@Test
void whenAddingModerator_thenHasModerator() {
Expand Down

0 comments on commit 478d505

Please sign in to comment.