|
| 1 | +=begin |
| 2 | +
|
| 3 | +Things that should update the matrix (ignoring tags): |
| 4 | +* pact created |
| 5 | +* pact content updated |
| 6 | +* pact deleted |
| 7 | +* verification created |
| 8 | +* verification deleted (not yet implemented) |
| 9 | +
|
| 10 | +It's easier to update the matrix at the resource level, so we actually update the matrix when: |
| 11 | +* pacticipant deleted |
| 12 | +* version deleted |
| 13 | +* pact deleted |
| 14 | +
|
| 15 | +Things that should update the head matrix |
| 16 | +* All of the above |
| 17 | +* tag created |
| 18 | +* tag deleted |
| 19 | +
|
| 20 | +=end |
| 21 | + |
| 22 | +describe "Deleting a resource that affects the matrix" do |
| 23 | + |
| 24 | + let(:td) { TestDataBuilder.new } |
| 25 | + let(:response_body_json) { JSON.parse(subject.body) } |
| 26 | + |
| 27 | + subject { delete path; last_response } |
| 28 | + |
| 29 | + before do |
| 30 | + td.create_pact_with_hierarchy("Foo", "1", "Bar") |
| 31 | + .create_consumer_version_tag("prod") |
| 32 | + .create_verification(provider_version: "2") |
| 33 | + end |
| 34 | + |
| 35 | + context "deleting a pact" do |
| 36 | + let(:path) { "/pacts/provider/Bar/consumer/Foo/version/1" } |
| 37 | + |
| 38 | + it "deletes the relevant lines from the matrix" do |
| 39 | + expect{ subject }.to change{ PactBroker::Matrix::Row.count }.by(-1) |
| 40 | + end |
| 41 | + end |
| 42 | + |
| 43 | + context "deleting a pacticipant" do |
| 44 | + let(:path) { "/pacticipants/Bar" } |
| 45 | + |
| 46 | + it "deletes the relevant lines from the matrix" do |
| 47 | + expect{ subject }.to change{ PactBroker::Matrix::Row.count }.by(-1) |
| 48 | + end |
| 49 | + end |
| 50 | + |
| 51 | + context "deleting a version" do |
| 52 | + let(:path) { "/pacticipants/Foo/versions/1" } |
| 53 | + |
| 54 | + it "deletes the relevant lines from the matrix" do |
| 55 | + expect{ subject }.to change{ PactBroker::Matrix::Row.count }.by(-1) |
| 56 | + end |
| 57 | + end |
| 58 | + |
| 59 | + context "deleting a tag" do |
| 60 | + let(:path) { "/pacticipants/Foo/versions/1/tags/prod" } |
| 61 | + |
| 62 | + it "deletes the relevant lines from the matrix" do |
| 63 | + expect{ subject }.to change{ PactBroker::Matrix::HeadRow.count }.by(-1) |
| 64 | + end |
| 65 | + end |
| 66 | +end |
| 67 | + |
| 68 | +describe "Creating a resource that affects the matrix" do |
| 69 | + |
| 70 | + let(:td) { TestDataBuilder.new } |
| 71 | + let(:response_body_json) { JSON.parse(subject.body) } |
| 72 | + |
| 73 | + subject { put(path, nil, {'CONTENT_TYPE' => 'application/json'}); last_response } |
| 74 | + |
| 75 | + context "creating a tag" do |
| 76 | + before do |
| 77 | + td.create_pact_with_hierarchy("Foo", "1", "Bar") |
| 78 | + end |
| 79 | + |
| 80 | + let(:path) { "/pacticipants/Foo/versions/1/tags/prod" } |
| 81 | + |
| 82 | + it "adds the relevant lines to the head matrix" do |
| 83 | + expect{ subject }.to change{ PactBroker::Matrix::HeadRow.count }.by(1) |
| 84 | + end |
| 85 | + |
| 86 | + it "does not add any lines to the matrix" do |
| 87 | + expect{ subject }.to change{ PactBroker::Matrix::Row.count }.by(0) |
| 88 | + end |
| 89 | + end |
| 90 | + |
| 91 | + context "creating a pact" do |
| 92 | + let(:pact_content) { load_fixture('foo-bar.json') } |
| 93 | + let(:path) { "/pacts/provider/Bar/consumer/Foo/versions/1.2.3" } |
| 94 | + |
| 95 | + subject { put path, pact_content, {'CONTENT_TYPE' => 'application/json'}; last_response } |
| 96 | + |
| 97 | + it "adds the relevant lines to the matrix" do |
| 98 | + expect{ subject }.to change{ PactBroker::Matrix::Row.count }.by(1) |
| 99 | + end |
| 100 | + |
| 101 | + it "adds the relevant lines to the head matrix" do |
| 102 | + expect{ subject }.to change{ PactBroker::Matrix::HeadRow.count }.by(1) |
| 103 | + end |
| 104 | + end |
| 105 | + |
| 106 | + context "creating a verification" do |
| 107 | + let(:td) { TestDataBuilder.new } |
| 108 | + let(:path) { "/pacts/provider/Bar/consumer/Foo/pact-version/#{pact.pact_version_sha}/verification-results" } |
| 109 | + let(:verification_content) { load_fixture('verification.json') } |
| 110 | + let(:parsed_response_body) { JSON.parse(subject.body) } |
| 111 | + let(:pact) { td.pact } |
| 112 | + |
| 113 | + subject { post path, verification_content, {'CONTENT_TYPE' => 'application/json' }; last_response } |
| 114 | + |
| 115 | + before do |
| 116 | + td.create_pact_with_hierarchy("Foo", "1", "Bar") |
| 117 | + end |
| 118 | + |
| 119 | + it "updates the relevant lines in the matrix" do |
| 120 | + expect{ subject }.to change{ PactBroker::Matrix::Row.first.provider_version_number }.from(nil).to("4.5.6") |
| 121 | + end |
| 122 | + |
| 123 | + it "updates the relevant lines in the head matrix" do |
| 124 | + expect{ subject }.to change{ PactBroker::Matrix::HeadRow.first.provider_version_number }.from(nil).to("4.5.6") |
| 125 | + end |
| 126 | + end |
| 127 | +end |
0 commit comments