package service import ( "testing" "github.com/google/uuid" "go.uber.org/zap" ) // TestProxySessionClears ends the sessions of one campaign and of one person // and keeps the others func TestProxySessionClears(t *testing.T) { m := NewProxySessionManager(Common{Logger: zap.NewNop().Sugar()}) c1, c2, r1, r2 := uuid.New(), uuid.New(), uuid.New(), uuid.New() m.StoreSession("a", &ProxySession{ID: "a", CampaignID: &c1, RecipientID: &r1}) m.StoreSession("b", &ProxySession{ID: "b", CampaignID: &c2, RecipientID: &r1}) m.StoreSession("c", &ProxySession{ID: "c", CampaignID: &c2, RecipientID: &r2}) if n := m.ClearSessionsForCampaign(c1); n != 1 { t.Fatalf("campaign clear %d, want 1", n) } if n := m.ClearSessionsForRecipient(r1); n != 1 { t.Fatalf("recipient clear %d, want 1", n) } if _, ok := m.GetSession("c"); !ok { t.Fatal("an unrelated session ended") } ids := m.SessionCampaignIDs() if _, ok := ids[c2]; !ok || len(ids) != 1 { t.Fatalf("session campaigns %v", ids) } if n := m.ClearSessionsForCampaigns(ids); n != 1 { t.Fatalf("campaigns clear %d, want 1", n) } }