diff --git a/lib/pact_broker/db/delete_overwritten_data.rb b/lib/pact_broker/db/delete_overwritten_data.rb index 627056a81..f431ff2b7 100644 --- a/lib/pact_broker/db/delete_overwritten_data.rb +++ b/lib/pact_broker/db/delete_overwritten_data.rb @@ -32,13 +32,19 @@ def call kept_counts[:pact_versions] = db[:pact_versions].count kept_counts[:triggered_webhooks] = db[:triggered_webhooks].count + # TODO swap the hierarchy around so it matches the clean task + if dry_run? to_keep = deleted_counts.keys.each_with_object({}) do | table_name, new_counts | new_counts[table_name] = kept_counts[table_name] - deleted_counts[table_name] end - { toDelete: deleted_counts, toKeep: to_keep } + deleted_counts.each_with_object({}) do | (key, value), new_hash | + new_hash[key] = { toDelete: value, toKeep: to_keep[key] } + end else - { deleted: deleted_counts, kept: kept_counts } + deleted_counts.each_with_object({}) do | (key, value), new_hash | + new_hash[key] = { deleted: value, kept: kept_counts[key] } + end end end diff --git a/spec/lib/pact_broker/db/delete_overwritten_data_spec.rb b/spec/lib/pact_broker/db/delete_overwritten_data_spec.rb index 1df463715..00c359ca2 100644 --- a/spec/lib/pact_broker/db/delete_overwritten_data_spec.rb +++ b/spec/lib/pact_broker/db/delete_overwritten_data_spec.rb @@ -25,8 +25,7 @@ module DB end it "returns a report" do - expect(subject[:deleted][:pact_publications]).to eq 1 - expect(subject[:kept][:pact_publications]).to eq 1 + expect(subject[:pact_publications]).to eq(deleted: 1, kept: 1) end context "when dry_run is true" do @@ -35,6 +34,10 @@ module DB it "does not delete anything" do expect { subject }.to_not change{ db[:pact_publications].count } end + + it "returns a report" do + expect(subject[:pact_publications]).to eq(toDelete: 1, toKeep: 1) + end end end @@ -56,8 +59,8 @@ module DB end it "returns a report" do - expect(subject[:deleted][:verification_results]).to eq 1 - expect(subject[:kept][:verification_results]).to eq 1 + expect(subject[:verification_results][:deleted]).to eq 1 + expect(subject[:verification_results][:kept]).to eq 1 end end @@ -75,8 +78,7 @@ module DB end it "returns a report" do - expect(subject[:deleted][:pact_versions]).to eq 1 - expect(subject[:kept][:pact_versions]).to eq 2 + expect(subject[:pact_versions]).to eq(deleted: 1, kept: 2) end context "when dry_run is true" do @@ -139,12 +141,20 @@ module DB expect { subject }.to change { PactBroker::Webhooks::TriggeredWebhook.count }.by(-2) end + it "returns a report" do + expect(subject[:triggered_webhooks]).to eq(deleted: 2, kept: 2) + end + context "when dry_run is true" do let(:dry_run) { true } it "does not delete anything" do expect { subject }.to_not change{ PactBroker::Webhooks::TriggeredWebhook.count } end + + it "returns a report" do + expect(subject[:triggered_webhooks]).to eq(toDelete: 2, toKeep: 2) + end end context "when all the records are younger than the max age" do