Skip to content

Commit 65ea0c8

Browse files
authored
[CHA-0] Fix failing tests on CI (#178)
* fix: use the default blocklist for the test * fix: old users caused some tests to fail, add cleanUsers to delete old users
1 parent 2577ab6 commit 65ea0c8

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

src/test/java/io/getstream/chat/java/BasicTest.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ static void setup() throws StreamException, SecurityException, IllegalArgumentEx
3434
cleanChannelTypes();
3535
cleanBlocklists();
3636
cleanCommands();
37+
cleanUsers();
3738
upsertUsers();
3839
createTestChannel();
3940
createTestMessage();
@@ -76,6 +77,43 @@ private static void cleanChannels() throws StreamException {
7677
}
7778
}
7879

80+
private static void cleanUsers() throws StreamException {
81+
while (true) {
82+
List<String> users =
83+
User.list().request().getUsers().stream()
84+
.map(user -> user.getId())
85+
.collect(Collectors.toList());
86+
87+
if (users.size() == 0) {
88+
break;
89+
}
90+
91+
var deleteManyResponse =
92+
User.deleteMany(users).deleteUserStrategy(DeleteStrategy.HARD).request();
93+
String taskId = deleteManyResponse.getTaskId();
94+
Assertions.assertNotNull(taskId);
95+
96+
System.out.printf("Waiting for user deletion task %s to complete...\n", taskId);
97+
98+
while (true) {
99+
TaskStatusGetResponse response = TaskStatus.get(taskId).request();
100+
String status = response.getStatus();
101+
102+
if (status.equals("completed") || status.equals("ok")) {
103+
break;
104+
}
105+
if (status.equals("failed") || status.equals("error")) {
106+
throw new StreamException(
107+
String.format("Failed to delete user(task_id: %s): %s", response.getId(), status),
108+
(Throwable) null);
109+
}
110+
111+
// wait for the channels to delete
112+
Assertions.assertDoesNotThrow(() -> Thread.sleep(500));
113+
}
114+
}
115+
}
116+
79117
private static void cleanChannelTypes() throws StreamException {
80118
ChannelType.list()
81119
.request()

src/test/java/io/getstream/chat/java/ModerationTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
import org.junit.jupiter.api.Test;
1010

1111
public class ModerationTest extends BasicTest {
12+
1213
@DisplayName("Can upsert, get and delete moderation config")
1314
@Test
1415
void whenUpsertingGetttingDeletingModerationConfig_thenNoException() {
16+
final String blocklistName = "profanity_en_2020_v1";
1517
BlockListRule rule =
16-
BlockListRule.builder().name("test").action(Moderation.Action.REMOVE).build();
18+
BlockListRule.builder().name(blocklistName).action(Moderation.Action.REMOVE).build();
1719

1820
String key = "chat:messaging:1234";
1921
Assertions.assertDoesNotThrow(
@@ -27,7 +29,7 @@ void whenUpsertingGetttingDeletingModerationConfig_thenNoException() {
2729
Assertions.assertDoesNotThrow(() -> Moderation.getConfig(key).request());
2830

2931
Assertions.assertEquals(
30-
response.getConfig().getBlockListConfig().getRules().get(0).getName(), "test");
32+
blocklistName, response.getConfig().getBlockListConfig().getRules().get(0).getName());
3133

3234
Assertions.assertDoesNotThrow(() -> Moderation.deleteConfig(key).request());
3335

0 commit comments

Comments
 (0)