|
| 1 | +require "spec_helper" |
| 2 | +RSpec.describe "SpecialistFormatsTest" do |
| 3 | + before do |
| 4 | + bunny_mock = BunnyMock.new |
| 5 | + @channel = bunny_mock.start.channel |
| 6 | + |
| 7 | + consumer = GovukMessageQueueConsumer::Consumer.new( |
| 8 | + queue_name: "bigwig.test", |
| 9 | + processor: GovukIndex::PublishingEventProcessor.new, |
| 10 | + rabbitmq_connection: bunny_mock, |
| 11 | + ) |
| 12 | + |
| 13 | + @queue = @channel.queue("bigwig.test") |
| 14 | + consumer.run |
| 15 | + end |
| 16 | + |
| 17 | + it "specialist publisher finders are correctly indexed" do |
| 18 | + random_example = generate_random_example( |
| 19 | + schema: "finder", |
| 20 | + payload: { document_type: "finder" }, |
| 21 | + ) |
| 22 | + |
| 23 | + allow(GovukIndex::MigratedFormats).to receive(:indexable_formats).and_return("finder" => :all) |
| 24 | + |
| 25 | + @queue.publish(random_example.to_json, content_type: "application/json") |
| 26 | + |
| 27 | + expect_document_is_in_rummager({ "link" => random_example["base_path"] }, index: "govuk_test", type: "edition") |
| 28 | + end |
| 29 | + |
| 30 | + it "specialist documents are correctly indexed" do |
| 31 | + document_types = %w[ |
| 32 | + aaib_report |
| 33 | + asylum_support_decision |
| 34 | + business_finance_support_scheme |
| 35 | + cma_case |
| 36 | + countryside_stewardship_grant |
| 37 | + drug_safety_update |
| 38 | + employment_appeal_tribunal_decision |
| 39 | + employment_tribunal_decision |
| 40 | + flood_and_coastal_erosion_risk_management_research_report |
| 41 | + international_development_fund |
| 42 | + licence_transaction |
| 43 | + maib_report |
| 44 | + medical_safety_alert |
| 45 | + protected_food_drink_name |
| 46 | + raib_report |
| 47 | + research_for_development_output |
| 48 | + residential_property_tribunal_decision |
| 49 | + service_standard_report |
| 50 | + statutory_instrument |
| 51 | + tax_tribunal_decision |
| 52 | + utaac_decision |
| 53 | + ] |
| 54 | + |
| 55 | + # ideally we would run a test for all document types, but this takes 3 seconds so I have limited |
| 56 | + # it to a random subset |
| 57 | + document_types.sample(3).each do |specialist_document_type| |
| 58 | + random_example = generate_random_example( |
| 59 | + schema: "specialist_document", |
| 60 | + payload: { document_type: specialist_document_type }, |
| 61 | + ) |
| 62 | + allow(GovukIndex::MigratedFormats).to receive(:indexable_formats).and_return(specialist_document_type => :all) |
| 63 | + |
| 64 | + @queue.publish(random_example.to_json, content_type: "application/json") |
| 65 | + |
| 66 | + expect_document_is_in_rummager({ "link" => random_example["base_path"] }, index: "govuk_test", type: specialist_document_type) |
| 67 | + end |
| 68 | + end |
| 69 | + |
| 70 | + it "esi documents are correctly indexed" do |
| 71 | + publisher_document_type = "esi_fund" |
| 72 | + search_document_type = "european_structural_investment_fund" |
| 73 | + |
| 74 | + random_example = generate_random_example( |
| 75 | + schema: "specialist_document", |
| 76 | + payload: { document_type: publisher_document_type }, |
| 77 | + ) |
| 78 | + allow(GovukIndex::MigratedFormats).to receive(:indexable_formats).and_return(search_document_type => :all) |
| 79 | + |
| 80 | + @queue.publish(random_example.to_json, content_type: "application/json") |
| 81 | + |
| 82 | + expect_document_is_in_rummager( |
| 83 | + { "link" => random_example["base_path"], "format" => search_document_type }, |
| 84 | + index: "govuk_test", |
| 85 | + type: search_document_type, |
| 86 | + ) |
| 87 | + end |
| 88 | + |
| 89 | + it "finders email signup are never indexed" do |
| 90 | + random_example = generate_random_example( |
| 91 | + schema: "finder_email_signup", |
| 92 | + payload: { document_type: "finder_email_signup" }, |
| 93 | + ) |
| 94 | + |
| 95 | + @queue.publish(random_example.to_json, content_type: "application/json") |
| 96 | + |
| 97 | + expect { |
| 98 | + fetch_document_from_rummager(id: random_example["base_path"], index: "govuk_test") |
| 99 | + }.to raise_error(Elasticsearch::Transport::Transport::Errors::NotFound) |
| 100 | + end |
| 101 | +end |
0 commit comments