Skip to content

Commit 5a27792

Browse files
Dakshclaude
andcommitted
refactor: simplify TeamUsageStatsTest for non-multi-tenant app
The regular test app doesn't have multi-tenant enabled, so teams will always be empty. Removed dead code inside if-blocks that would never execute and added explicit assertions that teams is empty. Full data verification is done in TeamUsageStatsIntegrationTest with dedicated multi-tenant credentials. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent d554bf0 commit 5a27792

File tree

1 file changed

+14
-97
lines changed

1 file changed

+14
-97
lines changed
Lines changed: 14 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
package io.getstream.chat.java;
22

3-
import io.getstream.chat.java.models.TeamUsageStats;
43
import io.getstream.chat.java.models.TeamUsageStats.QueryTeamUsageStatsResponse;
4+
import io.getstream.chat.java.models.TeamUsageStats;
55
import java.time.LocalDate;
66
import java.time.format.DateTimeFormatter;
7-
import java.util.List;
87
import org.junit.jupiter.api.Assertions;
98
import org.junit.jupiter.api.DisplayName;
109
import org.junit.jupiter.api.Test;
1110

11+
/**
12+
* Basic tests for Team Usage Stats API using regular (non-multi-tenant) app credentials.
13+
* Since the regular app doesn't have multi-tenant enabled, teams will always be empty.
14+
* Full data verification is done in TeamUsageStatsIntegrationTest with multi-tenant credentials.
15+
*/
1216
public class TeamUsageStatsTest {
1317

1418
@DisplayName("Can query team usage stats with default options")
@@ -19,13 +23,13 @@ void whenQueryingTeamUsageStatsWithDefaultOptions_thenNoException() {
1923

2024
Assertions.assertNotNull(response);
2125
Assertions.assertNotNull(response.getTeams());
22-
// Teams list might be empty if there's no usage data
26+
// Regular app doesn't have multi-tenant, so teams is empty
27+
Assertions.assertTrue(response.getTeams().isEmpty());
2328
}
2429

2530
@DisplayName("Can query team usage stats with month parameter")
2631
@Test
2732
void whenQueryingTeamUsageStatsWithMonth_thenNoException() {
28-
// Use current month
2933
String currentMonth = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM"));
3034

3135
QueryTeamUsageStatsResponse response =
@@ -34,12 +38,12 @@ void whenQueryingTeamUsageStatsWithMonth_thenNoException() {
3438

3539
Assertions.assertNotNull(response);
3640
Assertions.assertNotNull(response.getTeams());
41+
Assertions.assertTrue(response.getTeams().isEmpty());
3742
}
3843

3944
@DisplayName("Can query team usage stats with date range")
4045
@Test
4146
void whenQueryingTeamUsageStatsWithDateRange_thenNoException() {
42-
// Use last 7 days
4347
LocalDate endDate = LocalDate.now();
4448
LocalDate startDate = endDate.minusDays(7);
4549
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
@@ -54,107 +58,20 @@ void whenQueryingTeamUsageStatsWithDateRange_thenNoException() {
5458

5559
Assertions.assertNotNull(response);
5660
Assertions.assertNotNull(response.getTeams());
57-
58-
// If there are teams with data, verify the daily breakdown is present
59-
if (!response.getTeams().isEmpty()) {
60-
TeamUsageStats team = response.getTeams().get(0);
61-
Assertions.assertNotNull(team.getTeam());
62-
Assertions.assertNotNull(team.getUsersDaily());
63-
Assertions.assertNotNull(team.getMessagesDaily());
64-
}
61+
Assertions.assertTrue(response.getTeams().isEmpty());
6562
}
6663

6764
@DisplayName("Can query team usage stats with pagination")
6865
@Test
6966
void whenQueryingTeamUsageStatsWithPagination_thenNoException() {
70-
// First page with limit
71-
QueryTeamUsageStatsResponse firstPage =
72-
Assertions.assertDoesNotThrow(
73-
() -> TeamUsageStats.queryTeamUsageStats().limit(10).request());
74-
75-
Assertions.assertNotNull(firstPage);
76-
Assertions.assertNotNull(firstPage.getTeams());
77-
78-
// If there's a next cursor, fetch the next page
79-
if (firstPage.getNext() != null && !firstPage.getNext().isEmpty()) {
80-
QueryTeamUsageStatsResponse secondPage =
81-
Assertions.assertDoesNotThrow(
82-
() ->
83-
TeamUsageStats.queryTeamUsageStats()
84-
.limit(10)
85-
.next(firstPage.getNext())
86-
.request());
87-
88-
Assertions.assertNotNull(secondPage);
89-
Assertions.assertNotNull(secondPage.getTeams());
90-
}
91-
}
92-
93-
@DisplayName("Can query team usage stats for last year and verify response structure")
94-
@Test
95-
void whenQueryingTeamUsageStats_thenResponseStructureIsCorrect() {
96-
// Query last year to maximize chance of getting data
97-
LocalDate endDate = LocalDate.now();
98-
LocalDate startDate = endDate.minusYears(1);
99-
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
100-
10167
QueryTeamUsageStatsResponse response =
10268
Assertions.assertDoesNotThrow(
103-
() ->
104-
TeamUsageStats.queryTeamUsageStats()
105-
.startDate(startDate.format(formatter))
106-
.endDate(endDate.format(formatter))
107-
.request());
69+
() -> TeamUsageStats.queryTeamUsageStats().limit(10).request());
10870

10971
Assertions.assertNotNull(response);
11072
Assertions.assertNotNull(response.getTeams());
111-
112-
// If there are teams with data, verify response structure
113-
// Note: The regular test account may not have multi-tenant data, so we only
114-
// verify structure when data is present. Full data verification is done in
115-
// TeamUsageStatsIntegrationTest with dedicated multi-tenant credentials.
116-
List<TeamUsageStats> teams = response.getTeams();
117-
if (!teams.isEmpty()) {
118-
TeamUsageStats team = teams.get(0);
119-
120-
// Verify all 16 metrics are present
121-
Assertions.assertNotNull(team.getTeam(), "Team identifier should not be null");
122-
123-
// Daily activity metrics
124-
Assertions.assertNotNull(team.getUsersDaily(), "users_daily should not be null");
125-
Assertions.assertNotNull(team.getMessagesDaily(), "messages_daily should not be null");
126-
Assertions.assertNotNull(
127-
team.getTranslationsDaily(), "translations_daily should not be null");
128-
Assertions.assertNotNull(
129-
team.getImageModerationDaily(), "image_moderations_daily should not be null");
130-
131-
// Peak metrics
132-
Assertions.assertNotNull(team.getConcurrentUsers(), "concurrent_users should not be null");
133-
Assertions.assertNotNull(
134-
team.getConcurrentConnections(), "concurrent_connections should not be null");
135-
136-
// Rolling/cumulative metrics
137-
Assertions.assertNotNull(team.getUsersTotal(), "users_total should not be null");
138-
Assertions.assertNotNull(
139-
team.getUsersLast24Hours(), "users_last_24_hours should not be null");
140-
Assertions.assertNotNull(team.getUsersLast30Days(), "users_last_30_days should not be null");
141-
Assertions.assertNotNull(
142-
team.getUsersMonthToDate(), "users_month_to_date should not be null");
143-
Assertions.assertNotNull(
144-
team.getUsersEngagedLast30Days(), "users_engaged_last_30_days should not be null");
145-
Assertions.assertNotNull(
146-
team.getUsersEngagedMonthToDate(), "users_engaged_month_to_date should not be null");
147-
Assertions.assertNotNull(team.getMessagesTotal(), "messages_total should not be null");
148-
Assertions.assertNotNull(
149-
team.getMessagesLast24Hours(), "messages_last_24_hours should not be null");
150-
Assertions.assertNotNull(
151-
team.getMessagesLast30Days(), "messages_last_30_days should not be null");
152-
Assertions.assertNotNull(
153-
team.getMessagesMonthToDate(), "messages_month_to_date should not be null");
154-
155-
// Verify MetricStats structure
156-
Assertions.assertNotNull(
157-
team.getUsersDaily().getTotal(), "MetricStats total should not be null");
158-
}
73+
Assertions.assertTrue(response.getTeams().isEmpty());
74+
// No next cursor when teams is empty
75+
Assertions.assertTrue(response.getNext() == null || response.getNext().isEmpty());
15976
}
16077
}

0 commit comments

Comments
 (0)