MCPcopy
hub / github.com/tinode/chat / TestMessageDeleteList

Function TestMessageDeleteList

server/db/postgres/tests/postgres_test.go:1193–1258  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1191}
1192
1193func TestMessageDeleteList(t *testing.T) {
1194 toDel := types.DelMessage{
1195 ObjHeader: types.ObjHeader{
1196 Id: testData.UGen.GetStr(),
1197 CreatedAt: testData.Now,
1198 UpdatedAt: testData.Now,
1199 },
1200 Topic: testData.Topics[1].Id,
1201 DeletedFor: testData.Users[2].Id,
1202 DelId: 1,
1203 SeqIdRanges: []types.Range{{Low: 9}, {Low: 3, Hi: 7}},
1204 }
1205 err := adp.MessageDeleteList(toDel.Topic, &toDel)
1206 if err != nil {
1207 t.Fatal(err)
1208 }
1209
1210 // Check messages in dellog
1211 var count int
1212 err = db.QueryRow(ctx, "SELECT COUNT(*) FROM dellog WHERE topic=$1 AND deletedfor=$2",
1213 toDel.Topic, decodeUid(toDel.DeletedFor)).Scan(&count)
1214 if err != nil {
1215 t.Fatal(err)
1216 }
1217 if count == 0 {
1218 t.Error("No dellog entries created")
1219 }
1220
1221 // Hard delete test
1222 toDel = types.DelMessage{
1223 ObjHeader: types.ObjHeader{
1224 Id: testData.UGen.GetStr(),
1225 CreatedAt: testData.Now,
1226 UpdatedAt: testData.Now,
1227 },
1228 Topic: testData.Topics[0].Id,
1229 DelId: 3,
1230 SeqIdRanges: []types.Range{{Low: 1, Hi: 3}},
1231 }
1232 err = adp.MessageDeleteList(toDel.Topic, &toDel)
1233 if err != nil {
1234 t.Fatal(err)
1235 }
1236
1237 // Check if messages content was cleared
1238 err = db.QueryRow(ctx, "SELECT COUNT(*) FROM messages WHERE topic=$1 AND content IS NOT NULL",
1239 toDel.Topic).Scan(&count)
1240 if err != nil {
1241 t.Fatal(err)
1242 }
1243 if count > 1 {
1244 t.Errorf("Messages not properly deleted %d, %s", count, toDel.Topic)
1245 }
1246
1247 err = adp.MessageDeleteList(testData.Topics[0].Id, nil)
1248 if err != nil {
1249 t.Fatal(err)
1250 }

Callers

nothing calls this directly

Calls 5

GetStrMethod · 0.80
ErrorMethod · 0.80
decodeUidFunction · 0.70
MessageDeleteListMethod · 0.65
ScanMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…