|
| 1 | +require 'pact_broker/db/data_migrations/set_consumer_ids_for_pact_publications' |
| 2 | + |
| 3 | +module PactBroker |
| 4 | + module DB |
| 5 | + module DataMigrations |
| 6 | + describe SetConsumerIdsForPactPublications, migration: true do |
| 7 | + describe ".call" do |
| 8 | + before do |
| 9 | + PactBroker::Database.migrate(20180615) |
| 10 | + end |
| 11 | + |
| 12 | + let(:now) { DateTime.new(2018, 2, 2) } |
| 13 | + let!(:consumer_other) { create(:pacticipants, {name: 'Other consumer', created_at: now, updated_at: now}) } |
| 14 | + let!(:consumer) { create(:pacticipants, {name: 'Consumer', created_at: now, updated_at: now}) } |
| 15 | + let!(:provider) { create(:pacticipants, {name: 'Provider', created_at: now, updated_at: now}) } |
| 16 | + let!(:consumer_version) { create(:versions, {number: '1.2.3', order: 1, pacticipant_id: consumer[:id], created_at: now, updated_at: now}) } |
| 17 | + let!(:pact_version) { create(:pact_versions, {content: {some: 'json'}.to_json, sha: '1234', consumer_id: consumer[:id], provider_id: provider[:id], created_at: now}) } |
| 18 | + let!(:pact_publication) do |
| 19 | + create(:pact_publications, { |
| 20 | + consumer_version_id: consumer_version[:id], |
| 21 | + provider_id: provider[:id], |
| 22 | + revision_number: 1, |
| 23 | + pact_version_id: pact_version[:id], |
| 24 | + created_at: (now - 1) |
| 25 | + }) |
| 26 | + end |
| 27 | + |
| 28 | + subject { SetConsumerIdsForPactPublications.call(database) } |
| 29 | + |
| 30 | + it "sets the consumer_id" do |
| 31 | + expect(database[:pact_publications].first[:consumer_id]).to be nil |
| 32 | + subject |
| 33 | + expect(database[:pact_publications].first[:consumer_id]).to_not be nil |
| 34 | + expect(database[:pact_publications].first[:consumer_id]).to eq consumer[:id] |
| 35 | + end |
| 36 | + end |
| 37 | + end |
| 38 | + end |
| 39 | + end |
| 40 | +end |
0 commit comments