MCPcopy Index your code
hub / github.com/tinode/chat / TestReplyDelMsgHardDelete

Function TestReplyDelMsgHardDelete

server/topic_test.go:3178–3242  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3176}
3177
3178func TestReplyDelMsgHardDelete(t *testing.T) {
3179 // Test hard delete scenario - hard deletes affect all users equally
3180 // and don't update individual unread counters the same way as soft deletes
3181
3182 topicName := "p2pTest"
3183 helper := TopicTestHelper{}
3184 helper.setUp(t, 2, types.TopicCatP2P, topicName, true)
3185 defer helper.tearDown()
3186
3187 user1 := helper.uids[0] // User with delete permission
3188 user2 := helper.uids[1] // Other user
3189
3190 // Set up initial state: user2 has read up to message 5, topic has messages up to 10
3191 helper.topic.lastID = 10
3192
3193 pud1 := helper.topic.perUser[user1]
3194 pud1.readID = 10
3195 pud1.modeGiven = types.ModeCFull // Full permissions including delete
3196 pud1.modeWant = types.ModeCFull
3197 helper.topic.perUser[user1] = pud1
3198
3199 pud2 := helper.topic.perUser[user2]
3200 pud2.readID = 5
3201 pud2.modeGiven = types.ModeCFull
3202 pud2.modeWant = types.ModeCFull
3203 helper.topic.perUser[user2] = pud2
3204
3205 // Simulate user1 doing a hard delete of messages 7 and 8
3206 msg := &ClientComMessage{
3207 Del: &MsgClientDel{
3208 Id: "del123",
3209 What: "msg",
3210 DelSeq: []MsgRange{
3211 {LowId: 7, HiId: 9}, // Deletes messages 7 and 8 [7, 9)
3212 },
3213 Hard: true, // Hard delete
3214 },
3215 AsUser: user1.UserId(),
3216 sess: helper.sessions[0],
3217 init: true,
3218 }
3219
3220 // Mock the message deletion for hard delete (forUser = types.ZeroUid)
3221 helper.mm.EXPECT().DeleteList(topicName, 1, types.ZeroUid, gomock.Any(), []types.Range{{Low: 7, Hi: 9}}).Return(nil)
3222
3223 // Call the function under test
3224 err := helper.topic.replyDelMsg(helper.sessions[0], user1, false, msg)
3225
3226 // Verify
3227 if err != nil {
3228 t.Fatalf("replyDelMsg failed: %v", err)
3229 }
3230
3231 // Verify session got success response
3232 helper.finish()
3233 registerSessionVerifyOutputs(t, helper.results[0], []int{http.StatusOK})
3234
3235 // For hard deletes, all users' delID should be updated

Callers

nothing calls this directly

Calls 8

setUpMethod · 0.95
tearDownMethod · 0.95
finishMethod · 0.95
UserIdMethod · 0.80
replyDelMsgMethod · 0.80
DeleteListMethod · 0.65
EXPECTMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…