-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCommonTest.java
More file actions
169 lines (148 loc) · 5.86 KB
/
CommonTest.java
File metadata and controls
169 lines (148 loc) · 5.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package io.getstream;
import io.getstream.exceptions.StreamException;
import io.getstream.models.*;
import io.getstream.services.framework.StreamHTTPClient;
import io.getstream.services.framework.StreamSDKClient;
import java.util.Properties;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
public class CommonTest extends BasicTest {
private String SnsStatus;
private String SqsStatus;
@DisplayName("Can generate a user token")
@Test
void whenGeneratingUserToken_thenNoException() {
String userId = RandomStringUtils.randomAlphabetic(10);
String token = client.tokenBuilder().createToken(userId, 24 * 60 * 60);
Assertions.assertNotEquals(0, token.length());
}
@DisplayName("App Get does not throw Exception")
@Test
void whenCallingGetApp_thenNoException() {
Assertions.assertDoesNotThrow(() -> client.getApp(null).execute());
}
@DisplayName("App Settings update does not throw Exception")
@Test
@Disabled
void whenUpdatingAppSettings_thenNoException() {
var data =
UpdateAppRequest.builder()
.disableAuthChecks(true)
.disablePermissionsChecks(true)
.asyncModerationConfig(
AsyncModerationConfiguration.builder()
.callback(
AsyncModerationCallbackConfig.builder()
.mode("CALLBACK_MODE_REST")
.serverUrl("http://localhost.com")
.build())
.timeoutMs(3000)
.build())
.build();
Assertions.assertDoesNotThrow(() -> client.updateApp(data).execute());
Assertions.assertDoesNotThrow(
() ->
client
.updateApp(
UpdateAppRequest.builder()
.disableAuthChecks(false)
.disablePermissionsChecks(false)
.build())
.execute());
}
@DisplayName("App Get fails with bad key")
@Test
@Disabled
void givenBadKey_whenGettingApp_thenException() {
var properties = new Properties();
properties.put(StreamHTTPClient.API_KEY_PROP_NAME, "XXX");
var client = new StreamSDKClient(properties);
StreamException exception =
Assertions.assertThrows(StreamException.class, () -> client.getApp(null).execute());
Assertions.assertEquals(401, exception.getResponseData().getStatusCode());
}
@DisplayName("App Get fails with bad secret (after enabling auth)")
@Test
@Disabled
void givenBadSecret_whenEnableAuthAndGettingApp_thenException() {
Assertions.assertDoesNotThrow(
() ->
client
.updateApp(UpdateAppRequest.builder().disableAuthChecks(false).build())
.execute());
var properties = new Properties();
properties.put(
StreamHTTPClient.API_SECRET_PROP_NAME, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
var client = new StreamSDKClient(properties);
StreamException exception =
Assertions.assertThrows(StreamException.class, () -> client.getApp(null).execute());
Assertions.assertEquals(401, exception.getResponseData().getStatusCode());
}
@DisplayName("Can check sqs")
@Test
void whenCheckingBadSqs_thenError() {
CheckSQSResponse response =
Assertions.assertDoesNotThrow(
() ->
client
.checkSQS(
CheckSQSRequest.builder()
.sqsKey("key")
.sqsSecret("secret")
.sqsUrl("https://foo.com/bar")
.build())
.execute()
.getData());
Assertions.assertEquals("error", response.getStatus());
}
@DisplayName("Can check sns")
@Test
void whenCheckingBadSns_thenError() {
CheckSNSResponse response =
Assertions.assertDoesNotThrow(
() ->
client
.checkSNS(
CheckSNSRequest.builder()
.snsKey("key")
.snsSecret("secret")
.snsTopicArn("arn:aws:sns:us-east-1:123456789012:sns-topic")
.build())
.execute()
.getData());
Assertions.assertEquals("error", response.getStatus());
}
@Test
void testUserTimestamps() throws Exception {
// Use a fixed user ID
String userId = "test-user-timestamps";
UserRequest userRequest =
UserRequest.builder()
.id(userId)
.name("Test User for Timestamps" + System.currentTimeMillis())
.build();
UpdateUsersRequest updateUsersRequest =
UpdateUsersRequest.builder().users(java.util.Map.of(userId, userRequest)).build();
// Upsert the user
var response = client.updateUsers(updateUsersRequest).execute();
FullUserResponse user = response.getData().getUsers().get(userId);
// Verify the user was created
Assertions.assertNotNull(user, "User should not be null");
Assertions.assertEquals(userId, user.getId(), "User ID should match");
// Verify updatedAt timestamp is not null
Assertions.assertNotNull(user.getUpdatedAt(), "updatedAt timestamp should not be null");
// Verify updatedAt is reasonable (not in the future, not too old)
long now = System.currentTimeMillis();
long fiveMinutesAgo = now - (5 * 60 * 1000);
long oneMinuteInFuture = now + (60 * 1000);
Assertions.assertTrue(
user.getUpdatedAt().getTime() >= fiveMinutesAgo,
"updatedAt should not be more than 5 minutes in the past");
Assertions.assertTrue(
user.getUpdatedAt().getTime() <= oneMinuteInFuture,
"updatedAt should not be in the future");
}
}