|
| 1 | +describe 'creating triggered webhooks from webhook executions (migrate 36-41)', migration: true do |
| 2 | + before do |
| 3 | + PactBroker::Database.migrate(41) |
| 4 | + end |
| 5 | + |
| 6 | + let(:before_now) { DateTime.new(2016, 1, 1) } |
| 7 | + let(:now) { DateTime.new(2018, 2, 2) } |
| 8 | + let!(:consumer) { create(:pacticipants, {name: 'Consumer', created_at: now, updated_at: now}) } |
| 9 | + let!(:provider) { create(:pacticipants, {name: 'Provider', created_at: now, updated_at: now}) } |
| 10 | + let!(:consumer_version) { create(:versions, {number: '1.2.3', order: 1, pacticipant_id: consumer[:id], created_at: now, updated_at: now}) } |
| 11 | + let!(:pact_version) { create(:pact_versions, {content: {some: 'json'}.to_json, sha: '1234', consumer_id: consumer[:id], provider_id: provider[:id], created_at: now}) } |
| 12 | + let!(:pact_publication) do |
| 13 | + create(:pact_publications, { |
| 14 | + consumer_version_id: consumer_version[:id], |
| 15 | + provider_id: provider[:id], |
| 16 | + revision_number: 1, |
| 17 | + pact_version_id: pact_version[:id], |
| 18 | + created_at: (now - 1) |
| 19 | + }) |
| 20 | + end |
| 21 | + let!(:webhook) do |
| 22 | + create(:webhooks, { |
| 23 | + uuid: '1234', |
| 24 | + method: 'GET', |
| 25 | + url: 'http://www.example.org', |
| 26 | + consumer_id: consumer[:id], |
| 27 | + provider_id: provider[:id], |
| 28 | + is_json_request_body: false, |
| 29 | + created_at: now |
| 30 | + }) |
| 31 | + end |
| 32 | + let!(:triggered_webhook) do |
| 33 | + create(:triggered_webhooks, { |
| 34 | + trigger_uuid: '12345', |
| 35 | + trigger_type: 'publication', |
| 36 | + pact_publication_id: pact_publication[:id], |
| 37 | + webhook_id: webhook[:id], |
| 38 | + webhook_uuid: webhook[:uuid], |
| 39 | + consumer_id: consumer[:id], |
| 40 | + provider_id: provider[:id], |
| 41 | + status: 'success', |
| 42 | + created_at: now, |
| 43 | + updated_at: now |
| 44 | + }) |
| 45 | + end |
| 46 | + let!(:webhook_execution) do |
| 47 | + create(:webhook_executions, { |
| 48 | + triggered_webhook_id: triggered_webhook[:id], |
| 49 | + success: true, |
| 50 | + logs: 'logs', |
| 51 | + created_at: now |
| 52 | + }) |
| 53 | + end |
| 54 | + |
| 55 | + let!(:orphan_triggered_webhook) do |
| 56 | + create(:triggered_webhooks, { |
| 57 | + trigger_uuid: '12345', |
| 58 | + trigger_type: 'publication', |
| 59 | + pact_publication_id: pact_publication[:id], |
| 60 | + webhook_id: nil, |
| 61 | + webhook_uuid: webhook[:uuid], |
| 62 | + consumer_id: consumer[:id], |
| 63 | + provider_id: provider[:id], |
| 64 | + status: 'success', |
| 65 | + created_at: now, |
| 66 | + updated_at: now |
| 67 | + }) |
| 68 | + end |
| 69 | + |
| 70 | + let!(:orphan_webhook_execution) do |
| 71 | + create(:webhook_executions, { |
| 72 | + triggered_webhook_id: orphan_triggered_webhook[:id], |
| 73 | + success: true, |
| 74 | + logs: 'logs', |
| 75 | + created_at: now |
| 76 | + }) |
| 77 | + end |
| 78 | + |
| 79 | + let!(:deprecated_orphan_webhook_execution) do |
| 80 | + create(:webhook_executions, { |
| 81 | + triggered_webhook_id: nil, |
| 82 | + webhook_id: nil, |
| 83 | + success: true, |
| 84 | + logs: 'logs', |
| 85 | + created_at: now |
| 86 | + }) |
| 87 | + end |
| 88 | + |
| 89 | + subject { PactBroker::Database.migrate(42) } |
| 90 | + |
| 91 | + it "deletes the orphan triggered webhooks" do |
| 92 | + expect { subject }.to change { database[:triggered_webhooks].count }.by(-1) |
| 93 | + end |
| 94 | + |
| 95 | + it "deletes the orphan webhook executions" do |
| 96 | + expect { subject }.to change { database[:webhook_executions].count }.by(-2) |
| 97 | + end |
| 98 | +end |
0 commit comments