Skip to content

Commit fbd6188

Browse files
authored
Merge pull request #122 from jagerman/reactors-test
Add "you" reactor threshold test case
2 parents 59222ce + ba61fd2 commit fbd6188

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

tests/test_reactions.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ def test_reactions(client, room, room2, user, user2, mod, admin, global_mod, glo
7777
r = sogs_put(client, "/room/test-room/reaction/4/🦒🦍🐍🐊🦢🦁🦎", {}, user)
7878
assert r.json == {'added': True, "seqno": new_seqno + 1}
7979

80+
# user2 is the fourth reactor (of 5) and so should get ourself last in the truncated reactor
81+
# list:
82+
for u in (user, mod, global_mod, user2, admin):
83+
r = sogs_put(client, "/room/test-room/reaction/4/🂤", {}, u)
84+
85+
# user2 is fifth (of 5) and so should not be in the truncated reactor list (but should still get
86+
# "you"):
87+
for u in (user, mod, global_mod, global_admin, user2):
88+
r = sogs_put(client, "/room/test-room/reaction/4/🂵", {}, u)
89+
8090
exp_reactions = {
8191
'abcdefghijkl': {'index': 4, 'count': 1, 'reactors': [user.session_id]},
8292
'f': {'index': 2, 'count': 1, 'reactors': [user.session_id]},
@@ -90,6 +100,18 @@ def test_reactions(client, room, room2, user, user2, mod, admin, global_mod, glo
90100
},
91101
'🖕': {'index': 0, 'count': 2, 'reactors': [user.session_id, user2.session_id], 'you': True},
92102
'🦒🦍🐍🐊🦢🦁🦎': {'index': 6, 'count': 1, 'reactors': [user.session_id]},
103+
'🂤': {
104+
'index': 7,
105+
'count': 5,
106+
'reactors': [u.session_id for u in (user, mod, global_mod, user2)],
107+
'you': True,
108+
},
109+
'🂵': {
110+
'index': 8,
111+
'count': 5,
112+
'reactors': [u.session_id for u in (user, mod, global_mod, global_admin)],
113+
'you': True,
114+
},
93115
}
94116

95117
r = sogs_get(client, f"/room/test-room/messages/since/{seqno}?t=r", user2).json
@@ -101,7 +123,7 @@ def test_reactions(client, room, room2, user, user2, mod, admin, global_mod, glo
101123
'id': 4,
102124
'data': 'ZWRpdGVkIGZha2UgZGF0YSA0',
103125
'signature': 'ZmFrZSBzaWcgNGI' + 'A' * 71 + '==',
104-
'seqno': seqno + 7,
126+
'seqno': seqno + 17,
105127
'session_id': mod.session_id,
106128
'reactions': exp_reactions,
107129
}
@@ -110,9 +132,9 @@ def test_reactions(client, room, room2, user, user2, mod, admin, global_mod, glo
110132
# If we fetch just after the edit, we should only get the reactions:
111133

112134
r = sogs_get(client, f"/room/test-room/messages/since/{seqno+1}?t=r", user2)
113-
assert r.json == [{'id': 4, 'seqno': seqno + 7, 'reactions': exp_reactions}]
135+
assert r.json == [{'id': 4, 'seqno': seqno + 17, 'reactions': exp_reactions}]
114136

115-
seqno += 7
137+
seqno += 17
116138

117139
# Fetch the *full* list of reactors
118140
r = sogs_get(client, "/room/test-room/reactors/4/🍍", user).json
@@ -136,6 +158,11 @@ def test_reactions(client, room, room2, user, user2, mod, admin, global_mod, glo
136158
del exp_reactions['🍍']['reactors'][0]
137159
exp_reactions['🍍']['count'] -= 1
138160

161+
# We're reducing the reactor limit below, so chop off the last reactor from these in the
162+
# expected result:
163+
for card in '🂤🂵':
164+
del exp_reactions[card]['reactors'][-1]
165+
139166
# Also tests that the `reactors` query param is working right
140167
r = sogs_get(client, f"/room/test-room/messages/since/{seqno}?t=r&reactors=3", user2)
141168
assert r.json == [{'id': 4, 'seqno': seqno + 1, 'reactions': exp_reactions}]
@@ -158,7 +185,8 @@ def test_reactions(client, room, room2, user, user2, mod, admin, global_mod, glo
158185
assert exp_reactions["🍍"]["count"] == 5
159186
assert r.json == {"removed": 5, "seqno": seqno + 5}
160187
del exp_reactions["🍍"]
161-
exp_reactions["🦒🦍🐍🐊🦢🦁🦎"]["index"] -= 1
188+
for reaction in ("🦒🦍🐍🐊🦢🦁🦎", '🂤', '🂵'):
189+
exp_reactions[reaction]["index"] -= 1
162190

163191
r = sogs_get(client, f"/room/test-room/messages/since/{seqno}?t=r&reactors=0", user2)
164192
assert r.json == [{'id': 4, 'seqno': seqno + 5, 'reactions': exp_reactions}]

0 commit comments

Comments
 (0)