Skip to content

Commit

Permalink
feat: support DELETE for verification results
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Feb 1, 2020
1 parent e0dae2c commit 70392e5
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/pact_broker/api/resources/verification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def content_types_provided
# Remember to update latest_verification_id_for_pact_version_and_provider_version
# if/when DELETE is implemented
def allowed_methods
["GET", "OPTIONS"]
["GET", "OPTIONS", "DELETE"]
end

def resource_exists?
Expand All @@ -40,6 +40,11 @@ def to_extended_json
extended_decorator_for(verification).to_json(user_options: { base_url: base_url })
end

def delete_resource
verification_service.delete(verification)
true
end

private

def verification
Expand Down
4 changes: 4 additions & 0 deletions lib/pact_broker/verifications/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def create verification, provider_version_number, pact
verification
end

def delete(verification_id)
PactBroker::Domain::Verification.where(id: verification_id).delete
end

def update_latest_verification_id verification
params = {
pact_version_id: verification.pact_version_id,
Expand Down
5 changes: 5 additions & 0 deletions lib/pact_broker/verifications/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ def create next_verification_number, params, pact, webhook_options
verification
end

def delete(verification)
webhook_service.delete_all_webhook_related_objects_by_verification_ids(verification.id)
verification_repository.delete(verification.id)
end

def errors params
contract = PactBroker::Api::Contracts::VerificationContract.new(PactBroker::Domain::Verification.new)
contract.validate(params)
Expand Down
4 changes: 4 additions & 0 deletions lib/pact_broker/webhooks/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ def self.delete_all_webhook_related_objects_by_pact_publication_ids pact_publica
webhook_repository.delete_triggered_webhooks_by_pact_publication_ids pact_publication_ids
end

def self.delete_all_webhook_related_objects_by_verification_ids verification_ids
webhook_repository.delete_triggered_webhooks_by_verification_ids verification_ids
end

def self.find_all
webhook_repository.find_all
end
Expand Down
29 changes: 29 additions & 0 deletions spec/features/delete_verification_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'support/test_data_builder'
require 'pact_broker/api/pact_broker_urls'


describe "Delete a verification" do

let!(:verification) do
TestDataBuilder.new
.create_pact_with_verification("Foo", "1", "Bar", "2")
.create_provider_webhook(event_names: ['provider_verification_published'])
.create_triggered_webhook
.create_webhook_execution
.and_return(:verification)
end

let(:path) { PactBroker::Api::PactBrokerUrls.verification_url(verification, "") }
let(:response_body) { JSON.parse(last_response.body, symbolize_names: true)}

subject { delete(path) }

it "deletes the verification" do
expect { subject }.to change { PactBroker::Domain::Verification.count }.by(-1)
end

it "returns a 204 response" do
subject
expect(last_response.status).to eq 204
end
end

0 comments on commit 70392e5

Please sign in to comment.