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
30 changes: 30 additions & 0 deletions src/test/java/io/getstream/chat/java/ChannelTypeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,36 @@
import org.junit.jupiter.api.*;

public class ChannelTypeTest extends BasicTest {

private static final java.util.Set<String> SYSTEM_CHANNEL_TYPES =
java.util.Set.of("messaging", "livestream", "gaming", "commerce", "team");

/**
* Delete zombie custom channel types left over from prior CI runs that failed mid-test before
* their inline {@code ChannelType.delete(...)} could fire. The shared test app caps custom
* channel types at 50; without this sweep new branches hit the quota as soon as enough zombie
* types accumulate. Only deletes types not in {@link #SYSTEM_CHANNEL_TYPES}.
*/
@BeforeAll
static void cleanupLeftoverChannelTypes() {
try {
var resp = ChannelType.list().request();
if (resp == null || resp.getChannelTypes() == null) return;
resp.getChannelTypes().keySet().stream()
.filter(name -> !SYSTEM_CHANNEL_TYPES.contains(name))
.forEach(
name -> {
try {
ChannelType.delete(name).request();
} catch (StreamException ignored) {
// Best-effort: skip types that are in use or already deleted.
}
});
} catch (StreamException ignored) {
// Best-effort: if list fails the tests below will surface the real error.
}
}

@Test
@DisplayName("Get channel type with populated commands")
void whenPopulatingCommands_thenFetchChannelTypeWithoutAnyIssues() {
Expand Down
31 changes: 31 additions & 0 deletions src/test/java/io/getstream/chat/java/CommandTest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,45 @@
package io.getstream.chat.java;

import io.getstream.chat.java.exceptions.StreamException;
import io.getstream.chat.java.models.Command;
import java.util.List;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

public class CommandTest extends BasicTest {

private static final java.util.Set<String> SYSTEM_COMMANDS =
java.util.Set.of("giphy", "imgur", "ban", "unban", "mute", "unmute", "flag", "unflag");

/**
* Delete zombie custom commands left over from prior CI runs that failed mid-test before the
* inline {@code Command.delete(...)} could fire. The shared test app caps custom commands at 50.
* Only deletes commands not in {@link #SYSTEM_COMMANDS}.
*/
@BeforeAll
static void cleanupLeftoverCommands() {
try {
var resp = Command.list().request();
if (resp == null || resp.getCommands() == null) return;
resp.getCommands().stream()
.map(Command::getName)
.filter(name -> name != null && !SYSTEM_COMMANDS.contains(name))
.forEach(
name -> {
try {
Command.delete(name).request();
} catch (StreamException ignored) {
// Best-effort: skip commands that are in use or already deleted.
}
});
} catch (StreamException ignored) {
// Best-effort.
}
}

@DisplayName("Can create command")
@Test
void whenCreatingCommand_thenCorrectDescription() {
Expand Down
7 changes: 6 additions & 1 deletion src/test/java/io/getstream/chat/java/TaskStatusTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ void whenTaskHasBeenExecuted_thenGetItById() {

var cids = List.of(ch1.getCId(), ch2.getCId());
var taskId = Channel.deleteMany(cids).request().getTaskId();
// Shared CI test app: asynq queue can be backed up under load — the
// default 5s waitFor is routinely too short. 5 minutes leaves real
// headroom without masking a stuck task.
waitFor(
() -> {
var taskStatusResponse =
Assertions.assertDoesNotThrow(() -> TaskStatus.get(taskId).request());
return "completed".equals(taskStatusResponse.getStatus());
});
},
1000L,
300000L);
});
}
}
38 changes: 38 additions & 0 deletions src/test/java/io/getstream/chat/java/UserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,50 @@
import java.util.logging.Logger;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.ThrowingSupplier;

public class UserTest extends BasicTest {

/**
* Clear zombie bans left over from prior CI runs that died before their cleanup could fire.
* {@code User.queryBanned().request()} returns a paginated slice; once enough bans accumulate on
* the shared test app, the just-created ban under test ends up past the first page and the {@code
* assertTrue(bans.stream().anyMatch(...))} assertion fails. Best-effort sweep.
*/
@BeforeAll
static void cleanupLeftoverBans() {
// queryBanned() returns a paginated slice, so a single pass only clears
// the first page. Loop until either the response is empty or we stop
// making progress; cap iterations to avoid running forever against a
// poisoned app.
Set<String> seen = new HashSet<>();
for (int round = 0; round < 20; round++) {
List<Ban> bans;
try {
bans = User.queryBanned().request().getBans();
} catch (StreamException ignored) {
return; // Best-effort.
}
if (bans == null || bans.isEmpty()) return;
int unbannedThisRound = 0;
for (var ban : bans) {
if (ban.getUser() == null || ban.getUser().getId() == null) continue;
String id = ban.getUser().getId();
if (!seen.add(id)) continue;
try {
User.unban(id).request();
unbannedThisRound++;
} catch (StreamException ignored) {
// In-use or already-deleted; skip.
}
}
if (unbannedThisRound == 0) return; // No progress; bail.
}
}

@DisplayName("Can list users with no Exception")
@Test
void whenListingUsers_thenNoException() {
Expand Down
Loading