|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +RSpec.describe API::V1::Ingestions::Relationships::IngestionMessagesController, type: :request do |
| 4 | + let_it_be(:project, refind: true) { FactoryBot.create(:project, creator: project_creator) } |
| 5 | + let_it_be(:ingestion, refind: true) { FactoryBot.create(:ingestion, project:) } |
| 6 | + let_it_be(:other_ingestion, refind: true) { FactoryBot.create(:ingestion) } |
| 7 | + |
| 8 | + let_it_be(:ingestion_messages, refind: true) do |
| 9 | + [ |
| 10 | + FactoryBot.create(:ingestion_message, :start_message, ingestion:, created_at: 2.hours.ago), |
| 11 | + FactoryBot.create(:ingestion_message, :info, ingestion:, created_at: 90.minutes.ago), |
| 12 | + FactoryBot.create(:ingestion_message, :warn, ingestion:, created_at: 70.minutes.ago), |
| 13 | + FactoryBot.create(:ingestion_message, :unknown, ingestion:, created_at: 50.minutes.ago), |
| 14 | + FactoryBot.create(:ingestion_message, :end_message, ingestion:), |
| 15 | + ] |
| 16 | + end |
| 17 | + |
| 18 | + let(:starting_at) { nil } |
| 19 | + let(:params) { { starting_at: } } |
| 20 | + |
| 21 | + shared_examples_for "visible ingestion messages" do |
| 22 | + it "returns ingestion messages" do |
| 23 | + expect do |
| 24 | + get path, headers: |
| 25 | + end.to execute_safely |
| 26 | + |
| 27 | + expect(response).to have_http_status(:ok) |
| 28 | + expect(response.parsed_body["data"]).to have(5).items |
| 29 | + end |
| 30 | + |
| 31 | + context "when filtering by starting_at" do |
| 32 | + let(:starting_at) { 40.minutes.ago.iso8601 } |
| 33 | + |
| 34 | + it "returns ingestion messages created after the starting_at time" do |
| 35 | + expect do |
| 36 | + get path, headers: |
| 37 | + end.to execute_safely |
| 38 | + |
| 39 | + expect(response).to have_http_status(:ok) |
| 40 | + |
| 41 | + expect(response.parsed_body["data"]).to have(1).item |
| 42 | + end |
| 43 | + end |
| 44 | + end |
| 45 | + |
| 46 | + context "GET /api/v1/ingestions/:ingestion_id/relationships/ingestion_messages" do |
| 47 | + let(:path) { api_v1_ingestion_relationships_ingestion_messages_path(ingestion, params:) } |
| 48 | + let(:other_path) { api_v1_ingestion_relationships_ingestion_messages_path(other_ingestion, params:) } |
| 49 | + |
| 50 | + context "as an admin" do |
| 51 | + let(:headers) { admin_headers } |
| 52 | + |
| 53 | + it_behaves_like "visible ingestion messages" |
| 54 | + |
| 55 | + context "when trying to read messages for an unaffiliated ingestion" do |
| 56 | + let(:path) { other_path } |
| 57 | + |
| 58 | + it "allows access" do |
| 59 | + expect do |
| 60 | + get path, headers: |
| 61 | + end.to execute_safely |
| 62 | + |
| 63 | + expect(response).to have_http_status(:ok) |
| 64 | + end |
| 65 | + end |
| 66 | + end |
| 67 | + |
| 68 | + context "as the project creator" do |
| 69 | + let(:headers) { project_creator_headers } |
| 70 | + |
| 71 | + it_behaves_like "visible ingestion messages" |
| 72 | + |
| 73 | + context "when trying to read messages for an unaffiliated ingestion" do |
| 74 | + let(:path) { other_path } |
| 75 | + |
| 76 | + it "forbids access" do |
| 77 | + expect do |
| 78 | + get path, headers: |
| 79 | + end.to execute_safely |
| 80 | + |
| 81 | + expect(response).to have_http_status(:forbidden) |
| 82 | + end |
| 83 | + end |
| 84 | + end |
| 85 | + |
| 86 | + context "as a marketeer" do |
| 87 | + let(:headers) { marketeer_headers } |
| 88 | + |
| 89 | + it_behaves_like "visible ingestion messages" |
| 90 | + end |
| 91 | + |
| 92 | + context "as a reader" do |
| 93 | + let(:headers) { reader_headers } |
| 94 | + |
| 95 | + it "forbids access" do |
| 96 | + expect do |
| 97 | + get path, headers: |
| 98 | + end.to execute_safely |
| 99 | + |
| 100 | + expect(response).to have_http_status(:forbidden) |
| 101 | + end |
| 102 | + end |
| 103 | + end |
| 104 | +end |
0 commit comments