This repository was archived by the owner on Jul 19, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +34
-1
lines changed Expand file tree Collapse file tree 4 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,10 @@ def initialize(payload)
59
59
@improved_constants_payload = data . merge ( "constants" => improved_constants ) if improved_constants . any?
60
60
end
61
61
62
+ def changed?
63
+ alert_constants_payload . present? || improved_constants_payload . present?
64
+ end
65
+
62
66
private
63
67
64
68
def new_constants_selector
Original file line number Diff line number Diff line change @@ -23,7 +23,13 @@ def receive_test
23
23
end
24
24
25
25
def receive_snapshot
26
- send_snapshot_to_slack ( CC ::Formatters ::SnapshotFormatter ::Base . new ( payload ) )
26
+ snapshot = CC ::Formatters ::SnapshotFormatter ::Base . new ( payload )
27
+
28
+ if snapshot . changed?
29
+ send_snapshot_to_slack ( snapshot )
30
+ else
31
+ { ok : false , ignored : true , message : "No changes in snapshot" }
32
+ end
27
33
end
28
34
29
35
def receive_coverage
Original file line number Diff line number Diff line change @@ -44,4 +44,16 @@ def test_snapshot_formatter_test_with_relaxed_constraints
44
44
refute_nil f . alert_constants_payload
45
45
refute_nil f . improved_constants_payload
46
46
end
47
+
48
+ def test_changed_when_snapshot_changed
49
+ f = described_class . new ( { "new_constants" => [ ] ,
50
+ "changed_constants" => [ { "to" => { "rating" => "A" } , "from" => { "rating" => "D" } } ]
51
+ } )
52
+ assert f . changed?
53
+ end
54
+
55
+ def test_changed_when_no_changes
56
+ f = described_class . new ( { "new_constants" => [ ] , "changed_constants" => [ ] } )
57
+ refute f . changed?
58
+ end
47
59
end
Original file line number Diff line number Diff line change @@ -184,6 +184,17 @@ def test_receive_test
184
184
assert_equal "Test message sent" , response [ :message ]
185
185
end
186
186
187
+ def test_no_changes_in_snapshot
188
+ data = { "name" => "snapshot" , "repo_name" => "Rails" ,
189
+ "new_constants" => [ ] ,
190
+ "changed_constants" => [ ] ,
191
+ }
192
+ response = receive_event ( data )
193
+
194
+ assert_equal false , response [ :ok ]
195
+ assert response [ :ignored ]
196
+ end
197
+
187
198
private
188
199
189
200
def assert_slack_receives ( color , event_data , expected_body )
You can’t perform that action at this time.
0 commit comments