Skip to content
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
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ jobs:
with:
fetch-depth: 0

- name: Commit message lint
uses: wagoid/commitlint-github-action@v4

- name: Test
env:
STREAM_KEY: ${{ secrets.STREAM_KEY }}
Expand Down
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM amazoncorretto:11

WORKDIR /code

# Copy the Gradle wrapper files
COPY gradlew .
COPY gradle gradle/
COPY build.gradle .
COPY settings.gradle .

# Make gradlew executable
RUN chmod +x gradlew

CMD ["sh", "-c", "./gradlew :spotlessApply"]
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ test_with_docker:
docker run -t -i -w /code -v $(PWD):/code --env-file .env amazoncorretto:17 sh -c "sh ./gradlew test"

format_with_docker:
docker run -t -i -w /code -v $(PWD):/code amazoncorretto:17 sh -c "sh ./gradlew :spotlessApply"
docker build -t stream-chat-java-formatter . && \
docker run -v $(PWD):/code stream-chat-java-formatter
11 changes: 11 additions & 0 deletions src/main/java/io/getstream/chat/java/models/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public class User {
@JsonProperty("teams")
private List<String> teams;

@JsonProperty("teams_role")
private Map<String, String> teamsRole;

@NotNull
@JsonProperty("online")
private Boolean online;
Expand Down Expand Up @@ -219,6 +222,10 @@ public static class OwnUser {
@JsonProperty("role")
private String role;

@Nullable
@JsonProperty("teams_role")
private Map<String, String> teamsRole;

@Nullable
@JsonProperty("roles")
private List<String> roles;
Expand Down Expand Up @@ -361,6 +368,10 @@ public static class UserRequestObject {
@JsonProperty("teams")
private List<String> teams;

@Nullable
@JsonProperty("teams_role")
private Map<String, String> teamsRole;

@Singular @Nullable @JsonIgnore private Map<String, Object> additionalFields;

@JsonAnyGetter
Expand Down
69 changes: 69 additions & 0 deletions src/test/java/io/getstream/chat/java/UserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,33 @@ void whenParsingNotDefinedLanguage_thenUnknown() {
Assertions.assertEquals(lang, Language.UNKNOWN);
}

@DisplayName("Can create a user with team and teams_role")
@Test
void whenCreatingUserWithTeam_thenNoException() {
var id = RandomStringUtils.randomAlphabetic(10);
var team = "blue";
var role = "admin";

// Create user with team and teams_role
UserUpsertResponse response =
Assertions.assertDoesNotThrow(
() ->
User.upsert()
.user(
UserRequestObject.builder()
.id(id)
.teams(Collections.singletonList(team))
.teamsRole(Collections.singletonMap(team, role))
.build())
.request());

// Verify the user was created with correct team and role
User createdUser = response.getUsers().get(id);
Assertions.assertNotNull(createdUser);
Assertions.assertEquals(team, createdUser.getTeams().get(0));
Assertions.assertEquals(role, createdUser.getTeamsRole().get(team));
}

@DisplayName("Can partial update a user")
@Test
void whenPartiallyUpdatingUser_thenNoException() {
Expand Down Expand Up @@ -109,6 +136,48 @@ void whenPartiallyUpdatingUser_thenNoException() {
Assertions.assertEquals(addedValue, updatedUser.getAdditionalFields().get(addedKey));
}

@DisplayName("Can partial update a user with team and teams_role")
@Test
void whenPartiallyUpdatingUserWithTeam_thenNoException() {
// First create a basic user
UserUpsertRequest usersUpsertRequest = User.upsert();
User user =
Assertions.assertDoesNotThrow(
() ->
usersUpsertRequest
.user(
UserRequestObject.builder()
.id(RandomStringUtils.randomAlphabetic(10))
.name("Test User")
.build())
.request())
.getUsers()
.values()
.iterator()
.next();

// Partially update the user with team and teams_role
UserPartialUpdateRequestObject userPartialUpdateRequestObject =
UserPartialUpdateRequestObject.builder()
.id(user.getId())
.setValue("teams", Collections.singletonList("blue"))
.setValue("teams_role", Collections.singletonMap("blue", "admin"))
.build();

User updatedUser =
Assertions.assertDoesNotThrow(
() ->
User.partialUpdate()
.users(Arrays.asList(userPartialUpdateRequestObject))
.request())
.getUsers()
.get(user.getId());

// Verify the changes
Assertions.assertEquals("blue", updatedUser.getTeams().get(0));
Assertions.assertEquals("admin", updatedUser.getTeamsRole().get("blue"));
}

@DisplayName("Can ban user")
@Test
void whenBanUser_thenIsBanned() {
Expand Down