|
|
@@ -119,6 +119,33 @@ func TestDelDepletedRemovesOnlyDepleted(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func TestClientDeleteKeepTrafficPreservesRowForAttachedClient(t *testing.T) {
|
|
|
+ setupBulkDB(t)
|
|
|
+ svc := &ClientService{}
|
|
|
+ inboundSvc := &InboundService{}
|
|
|
+
|
|
|
+ email := "keepme@x"
|
|
|
+ c := model.Client{Email: email, ID: "11111111-1111-1111-1111-111111111111", SubID: email, Enable: true}
|
|
|
+ ib := mkInbound(t, 52030, model.VLESS, clientsSettings(t, []model.Client{c}))
|
|
|
+ if err := svc.SyncInbound(nil, ib.Id, []model.Client{c}); err != nil {
|
|
|
+ t.Fatalf("seed linkage: %v", err)
|
|
|
+ }
|
|
|
+ mkTraffic(t, ib.Id, email, 111, 222, 0, 0, true)
|
|
|
+
|
|
|
+ rec := lookupClientRecord(t, email)
|
|
|
+ if _, err := svc.Delete(inboundSvc, rec.Id, true); err != nil {
|
|
|
+ t.Fatalf("Delete(keepTraffic): %v", err)
|
|
|
+ }
|
|
|
+
|
|
|
+ var cnt int64
|
|
|
+ if err := database.GetDB().Model(&xray.ClientTraffic{}).Where("email = ?", email).Count(&cnt).Error; err != nil {
|
|
|
+ t.Fatalf("count traffic: %v", err)
|
|
|
+ }
|
|
|
+ if cnt != 1 {
|
|
|
+ t.Fatalf("keepTraffic delete of an inbound-attached client must preserve its client_traffics row, found %d", cnt)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func TestGetClientTrafficByEmailReadsClientsTable(t *testing.T) {
|
|
|
setupBulkDB(t)
|
|
|
svc := &ClientService{}
|