Skip to content

Commit c50df8d

Browse files
committed
chore: fix tests add extradata support reaction
1 parent 7ae0feb commit c50df8d

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

src/test/java/io/getstream/client/TargetFeedsExtraDataTest.java

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import static org.junit.Assert.assertEquals;
1616
import static org.junit.Assert.assertNotNull;
17+
import static org.junit.Assert.assertTrue;
1718

1819
public class TargetFeedsExtraDataTest {
1920
private static final String apiKey =
@@ -30,17 +31,21 @@ public void testTargetFeedsExtraData() throws Exception {
3031
// Create client
3132
Client client = Client.builder(apiKey, secret).build();
3233

34+
// Use unique user id to avoid conflicts in notification feed
35+
String uniqueId = UUID.randomUUID().toString().replace("-", "");
36+
String userId = "test-user-" + uniqueId;
37+
3338
// 1. Create a test activity
3439
String activityId = UUID.randomUUID().toString();
3540
Activity activity = Activity.builder()
36-
.actor("test-user")
41+
.actor(userId)
3742
.verb("post")
3843
.object("test-object")
3944
.foreignID("test-foreignId-" + activityId)
4045
.time(new Date())
4146
.build();
4247

43-
Activity postedActivity = client.flatFeed("user", "test-user").addActivity(activity).join();
48+
Activity postedActivity = client.flatFeed("user", userId).addActivity(activity).join();
4449

4550
// 2. Create a comment reaction on the activity
4651
Map<String, Object> commentData = new HashMap<>();
@@ -52,18 +57,20 @@ public void testTargetFeedsExtraData() throws Exception {
5257
.extraField("data", commentData)
5358
.build();
5459

55-
Reaction postedComment = client.reactions().add("test-user", comment, new FeedID[0]).join();
60+
Reaction postedComment = client.reactions().add(userId, comment, new FeedID[0]).join();
5661

5762
// 3. Create a like reaction on the comment with targetFeedsExtraData
5863
Map<String, Object> targetFeedsExtraData = new HashMap<>();
59-
targetFeedsExtraData.put("parent_reaction", "SR:" + postedComment.getId());
64+
String extraDataValue = "SR:" + postedComment.getId();
65+
targetFeedsExtraData.put("parent_reaction", extraDataValue);
6066

6167
FeedID[] targetFeeds = new FeedID[] {
62-
new FeedID("notification", "test-user")
68+
new FeedID("notification", userId)
6369
};
6470

71+
// The critical part of the test: Can we successfully create a reaction with targetFeedsExtraData
6572
Reaction like = client.reactions().addChild(
66-
"test-user",
73+
"actor-" + uniqueId, // Different user performs the like action
6774
"like",
6875
postedComment.getId(),
6976
targetFeeds,
@@ -75,6 +82,24 @@ public void testTargetFeedsExtraData() throws Exception {
7582
assertEquals("Like reaction should have kind='like'", "like", like.getKind());
7683
assertEquals("Like reaction should have parent ID", postedComment.getId(), like.getParent());
7784

85+
// Check if the reaction has extra data
86+
Map<String, Object> reactionExtra = like.getExtra();
87+
assertNotNull("Reaction should have extra data", reactionExtra);
88+
89+
// Check for targetFeedsExtraData directly
90+
assertTrue("Reaction should contain target_feeds_extra_data",
91+
reactionExtra.containsKey("target_feeds_extra_data"));
92+
93+
// Verify the content of targetFeedsExtraData
94+
Object extraDataObj = reactionExtra.get("target_feeds_extra_data");
95+
assertTrue("target_feeds_extra_data should be a Map", extraDataObj instanceof Map);
96+
97+
Map<String, Object> extraDataMap = (Map<String, Object>) extraDataObj;
98+
assertTrue("target_feeds_extra_data should contain parent_reaction",
99+
extraDataMap.containsKey("parent_reaction"));
100+
assertEquals("parent_reaction value should match what we sent",
101+
extraDataValue, extraDataMap.get("parent_reaction"));
102+
78103
// 5. Get the reactions to verify
79104
List<Reaction> reactions = client.reactions().filter(
80105
LookupKind.REACTION,
@@ -88,6 +113,6 @@ public void testTargetFeedsExtraData() throws Exception {
88113
// Clean up
89114
client.reactions().delete(like.getId()).join();
90115
client.reactions().delete(postedComment.getId()).join();
91-
client.flatFeed("user", "test-user").removeActivityByID(postedActivity.getID()).join();
116+
client.flatFeed("user", userId).removeActivityByID(postedActivity.getID()).join();
92117
}
93118
}

0 commit comments

Comments
 (0)