@@ -97,42 +97,21 @@ func createTestSummary(hasChanges bool) workertypes.EventSummary {
9797 categories .Added = 1
9898 }
9999
100- return workertypes.EventSummary {
101- SchemaVersion : "v1" ,
102- SnapshotOrigin : workertypes .OriginLive ,
103- Text : "Test Summary" ,
104- Categories : categories ,
105- Truncated : false ,
106- QueryErrors : nil ,
107- ResolvedQueryErrors : nil ,
108- Highlights : nil ,
109- }
100+ summary := workertypes .NewEmptyEventSummary ()
101+ summary .SnapshotOrigin = workertypes .OriginLive
102+ summary .Text = "Test Summary"
103+ summary .Categories = categories
104+
105+ return summary
110106}
111107
112108func createTestSummaryWithErrors (errCode workertypes.SummaryQueryErrorCode ) workertypes.EventSummary {
113- categories := workertypes.SummaryCategories {
114- QueryChanged : 0 ,
115- Added : 0 ,
116- Deleted : 0 ,
117- Removed : 0 ,
118- Moved : 0 ,
119- Split : 0 ,
120- Updated : 0 ,
121- UpdatedImpl : 0 ,
122- UpdatedRename : 0 ,
123- UpdatedBaseline : 0 ,
124- }
109+ summary := workertypes .NewEmptyEventSummary ()
110+ summary .SnapshotOrigin = workertypes .OriginLive
111+ summary .Text = "Error occurred"
112+ summary .SetQueryErrors ([]workertypes.SummaryQueryError {{Code : errCode }})
125113
126- return workertypes.EventSummary {
127- SchemaVersion : workertypes .VersionEventSummaryV1 ,
128- SnapshotOrigin : workertypes .OriginLive ,
129- Text : "Error occurred" ,
130- Categories : categories ,
131- Truncated : false ,
132- QueryErrors : []workertypes.SummaryQueryError {{Code : errCode }},
133- ResolvedQueryErrors : nil ,
134- Highlights : nil ,
135- }
114+ return summary
136115}
137116
138117// mockParserFactory creates a SummaryParser that injects the given summary directly.
@@ -205,22 +184,20 @@ func TestProcessEvent_Success(t *testing.T) {
205184 summary := createTestSummary (true )
206185 summary .Categories .UpdatedBaseline = 1
207186 summary .Categories .Updated = 1
208- summary .Highlights = []workertypes.SummaryHighlight {
209- {
210- Type : workertypes .SummaryHighlightTypeChanged ,
211- FeatureID : "test-feature-id" ,
212- FeatureName : "Test Feature" ,
213- Docs : nil ,
214- NameChange : nil ,
215- BaselineChange : & workertypes.Change [workertypes.BaselineValue ]{
216- From : newBaselineValue (workertypes .BaselineStatusLimited ),
217- To : newBaselineValue (workertypes .BaselineStatusNewly ),
218- },
219- BrowserChanges : nil ,
220- Moved : nil ,
221- Split : nil ,
187+ summary .AddHighlight (workertypes.SummaryHighlight {
188+ Type : workertypes .SummaryHighlightTypeChanged ,
189+ FeatureID : "test-feature-id" ,
190+ FeatureName : "Test Feature" ,
191+ Docs : nil ,
192+ NameChange : nil ,
193+ BaselineChange : & workertypes.Change [workertypes.BaselineValue ]{
194+ From : newBaselineValue (workertypes .BaselineStatusLimited ),
195+ To : newBaselineValue (workertypes .BaselineStatusNewly ),
222196 },
223- }
197+ BrowserChanges : nil ,
198+ Moved : nil ,
199+ Split : nil ,
200+ })
224201 parser := mockParserFactory (summary , nil )
225202
226203 d := NewDispatcher (finder , publisher )
@@ -315,22 +292,20 @@ func TestProcessEvent_Webhook_Success(t *testing.T) {
315292 summary := createTestSummary (true )
316293 summary .Categories .UpdatedBaseline = 1
317294 summary .Categories .Updated = 1
318- summary .Highlights = []workertypes.SummaryHighlight {
319- {
320- Type : workertypes .SummaryHighlightTypeChanged ,
321- FeatureID : "test-feature-id" ,
322- FeatureName : "Test Feature" ,
323- Docs : nil ,
324- NameChange : nil ,
325- BaselineChange : & workertypes.Change [workertypes.BaselineValue ]{
326- From : newBaselineValue (workertypes .BaselineStatusLimited ),
327- To : newBaselineValue (workertypes .BaselineStatusNewly ),
328- },
329- BrowserChanges : nil ,
330- Moved : nil ,
331- Split : nil ,
295+ summary .AddHighlight (workertypes.SummaryHighlight {
296+ Type : workertypes .SummaryHighlightTypeChanged ,
297+ FeatureID : "test-feature-id" ,
298+ FeatureName : "Test Feature" ,
299+ Docs : nil ,
300+ NameChange : nil ,
301+ BaselineChange : & workertypes.Change [workertypes.BaselineValue ]{
302+ From : newBaselineValue (workertypes .BaselineStatusLimited ),
303+ To : newBaselineValue (workertypes .BaselineStatusNewly ),
332304 },
333- }
305+ BrowserChanges : nil ,
306+ Moved : nil ,
307+ Split : nil ,
308+ })
334309 parser := mockParserFactory (summary , nil )
335310
336311 d := NewDispatcher (finder , publisher )
@@ -601,7 +576,7 @@ func newBrowserValue(status workertypes.BrowserStatus) workertypes.BrowserValue
601576
602577func withBaselineHighlight (
603578 s workertypes.EventSummary , from , to workertypes.BaselineStatus ) workertypes.EventSummary {
604- s .Highlights = append ( s . Highlights , workertypes.SummaryHighlight {
579+ s .AddHighlight ( workertypes.SummaryHighlight {
605580 Type : workertypes .SummaryHighlightTypeChanged ,
606581 FeatureID : "test-feature-id" ,
607582 FeatureName : "Test Feature" ,
@@ -623,7 +598,7 @@ func withBaselineHighlight(
623598
624599func withBrowserChangeHighlight (
625600 s workertypes.EventSummary , from , to workertypes.BrowserStatus ) workertypes.EventSummary {
626- s .Highlights = append ( s . Highlights , workertypes.SummaryHighlight {
601+ s .AddHighlight ( workertypes.SummaryHighlight {
627602 Type : workertypes .SummaryHighlightTypeChanged ,
628603 FeatureID : "test-feature-id" ,
629604 FeatureName : "Test Feature" ,
@@ -764,7 +739,10 @@ func TestShouldNotifyV1(t *testing.T) {
764739
765740 for _ , tc := range testCases {
766741 t .Run (tc .name , func (t * testing.T ) {
767- got := shouldNotifyV1 (tc .triggers , tc .summary )
742+ got , err := shouldNotifyV1 (tc .triggers , & tc .summary )
743+ if err != nil {
744+ t .Fatalf ("shouldNotifyV1 unexpected error: %v" , err )
745+ }
768746 if got != tc .want {
769747 t .Errorf ("shouldNotifyV1() = %v, want %v" , got , tc .want )
770748 }
@@ -773,16 +751,12 @@ func TestShouldNotifyV1(t *testing.T) {
773751}
774752
775753func createRecoveredSummary () workertypes.EventSummary {
776- return workertypes.EventSummary {
777- SchemaVersion : workertypes .VersionEventSummaryV1 ,
778- SnapshotOrigin : workertypes .OriginLive ,
779- Text : "Search query recovered and tracking 2 features normally." ,
780- Truncated : false ,
781- Categories : workertypes .NewEmptySummaryCategories (),
782- QueryErrors : nil ,
783- ResolvedQueryErrors : []workertypes.SummaryQueryError {{Code : workertypes .SummaryQueryErrorCodeQueryGrammar }},
784- Highlights : nil ,
785- }
754+ summary := workertypes .NewEmptyEventSummary ()
755+ summary .SnapshotOrigin = workertypes .OriginLive
756+ summary .Text = "Search query recovered and tracking 2 features normally."
757+ summary .SetResolvedQueryErrors ([]workertypes.SummaryQueryError {{Code : workertypes .SummaryQueryErrorCodeQueryGrammar }})
758+
759+ return summary
786760}
787761
788762func TestShouldNotifyV1_ResolvedQueryErrors (t * testing.T ) {
@@ -816,7 +790,10 @@ func TestShouldNotifyV1_ResolvedQueryErrors(t *testing.T) {
816790
817791 for _ , tc := range testCases {
818792 t .Run (tc .name , func (t * testing.T ) {
819- got := shouldNotifyV1 (tc .triggers , tc .summary )
793+ got , err := shouldNotifyV1 (tc .triggers , & tc .summary )
794+ if err != nil {
795+ t .Fatalf ("shouldNotifyV1 unexpected error: %v" , err )
796+ }
820797 if got != tc .want {
821798 t .Errorf ("shouldNotifyV1() = %v, want %v" , got , tc .want )
822799 }
@@ -878,3 +855,14 @@ func TestProcessEvent_ResolvedQueryErrors_AllChannels(t *testing.T) {
878855 t .Errorf ("expected subscription ID sub-webhook-recovery, got %s" , publisher .webhookJobs [0 ].SubscriptionID )
879856 }
880857}
858+
859+ func TestShouldNotifyV1_NilSummary (t * testing.T ) {
860+ // Verify that if the summary is nil, shouldNotifyV1 returns false and no error.
861+ got , err := shouldNotifyV1 ([]workertypes.JobTrigger {workertypes .FeaturePromotedToNewly }, nil )
862+ if err != nil {
863+ t .Fatalf ("shouldNotifyV1 unexpected error: %v" , err )
864+ }
865+ if got {
866+ t .Errorf ("shouldNotifyV1(triggers, nil) = %v, want false" , got )
867+ }
868+ }
0 commit comments