nulogy_message_bus_producer 1.0.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/nulogy_message_bus_producer.rb +17 -12
- data/lib/nulogy_message_bus_producer/config.rb +66 -0
- data/lib/nulogy_message_bus_producer/postgres_public_subscriptions.rb +30 -15
- data/lib/nulogy_message_bus_producer/public_subscription.rb +3 -1
- data/lib/nulogy_message_bus_producer/version.rb +1 -1
- data/spec/dummy/config/puma.rb +2 -2
- data/spec/dummy/log/development.log +1757 -32
- data/spec/dummy/log/test.log +18919 -13
- data/spec/integration/lib/graphql_api/postgres_public_subscriptions_spec.rb +106 -0
- data/spec/integration/lib/graphql_api/validators/subscriber_graphql_schema_validator_spec.rb +1 -1
- data/spec/integration_spec_helper.rb +1 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/unit/lib/graphql_api/models/public_subscription_spec.rb +12 -2
- metadata +14 -13
| @@ -13,4 +13,110 @@ RSpec.describe NulogyMessageBusProducer::PostgresPublicSubscriptions do | |
| 13 13 | 
             
                  end.to raise_error(KeyError, /The schema registry did not contain an entry/)
         | 
| 14 14 | 
             
                end
         | 
| 15 15 | 
             
              end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              context "when subscription is triggered" do
         | 
| 18 | 
            +
                before do
         | 
| 19 | 
            +
                  NulogyMessageBusProducer.config.register_schema(
         | 
| 20 | 
            +
                    schema: "NulogyMessageBusProducer::Specs::TestSchema",
         | 
| 21 | 
            +
                    key: "test"
         | 
| 22 | 
            +
                  )
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                it "generates events" do
         | 
| 26 | 
            +
                  create_subscription(event_type: "testCreated")
         | 
| 27 | 
            +
                  create_subscription(event_type: "testCreated")
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                  uuid = SecureRandom.uuid
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                  expect do
         | 
| 32 | 
            +
                    NulogyMessageBusProducer::Specs::TestSchema.subscriptions.trigger(
         | 
| 33 | 
            +
                      "testCreated",
         | 
| 34 | 
            +
                      {},
         | 
| 35 | 
            +
                      { uuid: uuid, tenant_id: SecureRandom.uuid }
         | 
| 36 | 
            +
                    )
         | 
| 37 | 
            +
                  end.to change(NulogyMessageBusProducer::PublicSubscriptionEvent, :count).by(2)
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                  event_data = NulogyMessageBusProducer::PublicSubscriptionEvent.pluck(:event_json)
         | 
| 40 | 
            +
                  expect(event_data).to all(include("foo" => { "id" => uuid }))
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
              end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
              context "when a subscription error occurs" do
         | 
| 45 | 
            +
                context "when failing with raise" do
         | 
| 46 | 
            +
                  before do
         | 
| 47 | 
            +
                    NulogyMessageBusProducer.config.producing_events_fails_with(:raise)
         | 
| 48 | 
            +
                  end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                  it "raises an exception" do
         | 
| 51 | 
            +
                    expect { trigger_erroneous_subscription }.to raise_error(/A subscription event could not be produced/)
         | 
| 52 | 
            +
                  end
         | 
| 53 | 
            +
                end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                context "when failing with a soft fail" do
         | 
| 56 | 
            +
                  before do
         | 
| 57 | 
            +
                    NulogyMessageBusProducer.config.producing_events_fails_with(:soft_fail)
         | 
| 58 | 
            +
                  end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                  it "does not raise an error" do
         | 
| 61 | 
            +
                    trigger_erroneous_subscription
         | 
| 62 | 
            +
                  end
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                  it "calls the provided block" do
         | 
| 65 | 
            +
                    called = false
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                    NulogyMessageBusProducer.config.producing_events_fails_with(:soft_fail) do |_|
         | 
| 68 | 
            +
                      called = true
         | 
| 69 | 
            +
                    end
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                    trigger_erroneous_subscription
         | 
| 72 | 
            +
             | 
| 73 | 
            +
                    expect(called).to be(true)
         | 
| 74 | 
            +
                  end
         | 
| 75 | 
            +
                end
         | 
| 76 | 
            +
              end
         | 
| 77 | 
            +
             | 
| 78 | 
            +
              def trigger_erroneous_subscription
         | 
| 79 | 
            +
                NulogyMessageBusProducer.config.register_schema(schema: "NulogyMessageBusProducer::Specs::TestSchema", key: "test")
         | 
| 80 | 
            +
             | 
| 81 | 
            +
                event_type = "testCreated"
         | 
| 82 | 
            +
             | 
| 83 | 
            +
                subscription = create_subscription(event_type: event_type)
         | 
| 84 | 
            +
                simulate_invalid_query(subscription)
         | 
| 85 | 
            +
             | 
| 86 | 
            +
                NulogyMessageBusProducer::Specs::TestSchema.subscriptions.trigger(
         | 
| 87 | 
            +
                  event_type,
         | 
| 88 | 
            +
                  {},
         | 
| 89 | 
            +
                  { uuid: SecureRandom.uuid, tenant_id: SecureRandom.uuid }
         | 
| 90 | 
            +
                )
         | 
| 91 | 
            +
              end
         | 
| 92 | 
            +
             | 
| 93 | 
            +
              def create_subscription(**overrides) # rubocop:disable Metrics/MethodLength
         | 
| 94 | 
            +
                args = {
         | 
| 95 | 
            +
                  id: SecureRandom.uuid,
         | 
| 96 | 
            +
                  subscription_group_id: SecureRandom.uuid,
         | 
| 97 | 
            +
                  topic_name: "test_topic",
         | 
| 98 | 
            +
                  schema_key: "test",
         | 
| 99 | 
            +
                  event_type: "test_event_type",
         | 
| 100 | 
            +
                  query: <<~QUERY
         | 
| 101 | 
            +
                    query ($id: UUID!) {
         | 
| 102 | 
            +
                      foo (id: $id) {
         | 
| 103 | 
            +
                        id
         | 
| 104 | 
            +
                      }
         | 
| 105 | 
            +
                    }
         | 
| 106 | 
            +
                  QUERY
         | 
| 107 | 
            +
                }.merge(overrides)
         | 
| 108 | 
            +
             | 
| 109 | 
            +
                NulogyMessageBusProducer::PublicSubscription.create_or_update(args)
         | 
| 110 | 
            +
              end
         | 
| 111 | 
            +
             | 
| 112 | 
            +
              def simulate_invalid_query(subscription)
         | 
| 113 | 
            +
                subscription.query = <<~QUERY
         | 
| 114 | 
            +
                  query ($id: UUID!) {
         | 
| 115 | 
            +
                    foo (id: $id) {
         | 
| 116 | 
            +
                      a_field_that_does_not_exist
         | 
| 117 | 
            +
                    }
         | 
| 118 | 
            +
                  }
         | 
| 119 | 
            +
                QUERY
         | 
| 120 | 
            +
                subscription.save(validate: false)
         | 
| 121 | 
            +
              end
         | 
| 16 122 | 
             
            end
         | 
    
        data/spec/integration/lib/graphql_api/validators/subscriber_graphql_schema_validator_spec.rb
    CHANGED
    
    | @@ -4,7 +4,7 @@ RSpec.describe NulogyMessageBusProducer::SubscriberGraphqlSchemaValidator do | |
| 4 4 | 
             
              subject(:validator) { NulogyMessageBusProducer::SubscriberGraphqlSchemaValidator.new }
         | 
| 5 5 |  | 
| 6 6 | 
             
              before do
         | 
| 7 | 
            -
                NulogyMessageBusProducer.register_schema( | 
| 7 | 
            +
                NulogyMessageBusProducer.config.register_schema(schema: "NulogyMessageBusProducer::Specs::TestSchema", key: "test")
         | 
| 8 8 | 
             
              end
         | 
| 9 9 |  | 
| 10 10 | 
             
              describe "#validate" do
         | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | @@ -13,12 +13,27 @@ module NulogyMessageBusProducer | |
| 13 13 | 
             
                  field :foo, TestObject, null: false do
         | 
| 14 14 | 
             
                    argument :id, type: NulogyGraphqlApi::Types::UUID, required: false
         | 
| 15 15 | 
             
                  end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                  def foo(id:)
         | 
| 18 | 
            +
                    OpenStruct.new(id: id)
         | 
| 19 | 
            +
                  end
         | 
| 20 | 
            +
                end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                class TestCreated < NulogyMessageBusProducer::BasePublicSubscription
         | 
| 23 | 
            +
                  field :description, String, null: false
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                class TestSubscription < GraphQL::Schema::Object
         | 
| 27 | 
            +
                  extend GraphQL::Subscriptions::SubscriptionRoot
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                  field :test_created, subscription: TestCreated
         | 
| 16 30 | 
             
                end
         | 
| 17 31 |  | 
| 18 32 | 
             
                class TestSchema < GraphQL::Schema
         | 
| 19 33 | 
             
                  use NulogyMessageBusProducer::PostgresPublicSubscriptions
         | 
| 20 34 |  | 
| 21 35 | 
             
                  query TestQuery
         | 
| 36 | 
            +
                  subscription TestSubscription
         | 
| 22 37 | 
             
                end
         | 
| 23 38 | 
             
              end
         | 
| 24 39 | 
             
            end
         | 
| @@ -3,7 +3,7 @@ require "unit_spec_helper" | |
| 3 3 | 
             
            RSpec.describe NulogyMessageBusProducer::PublicSubscription do
         | 
| 4 4 | 
             
              context "when validating" do
         | 
| 5 5 | 
             
                before do
         | 
| 6 | 
            -
                  NulogyMessageBusProducer.register_schema | 
| 6 | 
            +
                  NulogyMessageBusProducer.config.register_schema schema: "NulogyMessageBusProducer::Specs::TestSchema", key: "test"
         | 
| 7 7 | 
             
                end
         | 
| 8 8 |  | 
| 9 9 | 
             
                it "is invalid with a blank query" do
         | 
| @@ -18,6 +18,14 @@ RSpec.describe NulogyMessageBusProducer::PublicSubscription do | |
| 18 18 | 
             
                  expect(model.errors[:query]).to contain_exactly("can't be blank")
         | 
| 19 19 | 
             
                end
         | 
| 20 20 |  | 
| 21 | 
            +
                it "is invalid with blank schema_key" do
         | 
| 22 | 
            +
                  model = NulogyMessageBusProducer::PublicSubscription.new(schema_key: "")
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  model.validate
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                  expect(model.errors[:schema_key]).to be_present
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
             | 
| 21 29 | 
             
                it "is invalid with an invalid query" do
         | 
| 22 30 | 
             
                  model = NulogyMessageBusProducer::PublicSubscription.new(
         | 
| 23 31 | 
             
                    schema_key: "test",
         | 
| @@ -33,7 +41,9 @@ RSpec.describe NulogyMessageBusProducer::PublicSubscription do | |
| 33 41 | 
             
                  model.validate
         | 
| 34 42 |  | 
| 35 43 | 
             
                  expect(model).to_not be_valid
         | 
| 36 | 
            -
                  expect(model.errors[:query]).to contain_exactly( | 
| 44 | 
            +
                  expect(model.errors[:query]).to contain_exactly(
         | 
| 45 | 
            +
                    "Field 'a_field_that_does_not_exist' doesn't exist on type 'testObject' (id: <new_record>)"
         | 
| 46 | 
            +
                  )
         | 
| 37 47 | 
             
                end
         | 
| 38 48 |  | 
| 39 49 | 
             
                it "valid with a valid query" do
         | 
    
        metadata
    CHANGED
    
    | @@ -1,43 +1,43 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: nulogy_message_bus_producer
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version:  | 
| 4 | 
            +
              version: 2.0.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Nulogy
         | 
| 8 | 
            -
            autorequire:
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2020-07- | 
| 11 | 
            +
            date: 2020-07-14 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rails
         | 
| 15 15 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 16 | 
             
                requirements:
         | 
| 17 | 
            -
                - - " | 
| 17 | 
            +
                - - ">="
         | 
| 18 18 | 
             
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            -
                    version: 5 | 
| 19 | 
            +
                    version: '5'
         | 
| 20 20 | 
             
              type: :runtime
         | 
| 21 21 | 
             
              prerelease: false
         | 
| 22 22 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 23 | 
             
                requirements:
         | 
| 24 | 
            -
                - - " | 
| 24 | 
            +
                - - ">="
         | 
| 25 25 | 
             
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            -
                    version: 5 | 
| 26 | 
            +
                    version: '5'
         | 
| 27 27 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 28 28 | 
             
              name: graphql
         | 
| 29 29 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 30 | 
             
                requirements:
         | 
| 31 | 
            -
                - -  | 
| 31 | 
            +
                - - ">="
         | 
| 32 32 | 
             
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            -
                    version: 1.9 | 
| 33 | 
            +
                    version: '1.9'
         | 
| 34 34 | 
             
              type: :runtime
         | 
| 35 35 | 
             
              prerelease: false
         | 
| 36 36 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 37 | 
             
                requirements:
         | 
| 38 | 
            -
                - -  | 
| 38 | 
            +
                - - ">="
         | 
| 39 39 | 
             
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            -
                    version: 1.9 | 
| 40 | 
            +
                    version: '1.9'
         | 
| 41 41 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 42 42 | 
             
              name: strong_migrations
         | 
| 43 43 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -191,6 +191,7 @@ files: | |
| 191 191 | 
             
            - lib/nulogy_message_bus_producer.rb
         | 
| 192 192 | 
             
            - lib/nulogy_message_bus_producer/application_record.rb
         | 
| 193 193 | 
             
            - lib/nulogy_message_bus_producer/base_public_subscription.rb
         | 
| 194 | 
            +
            - lib/nulogy_message_bus_producer/config.rb
         | 
| 194 195 | 
             
            - lib/nulogy_message_bus_producer/engine.rb
         | 
| 195 196 | 
             
            - lib/nulogy_message_bus_producer/postgres_public_subscriptions.rb
         | 
| 196 197 | 
             
            - lib/nulogy_message_bus_producer/public_subscription.rb
         | 
| @@ -260,7 +261,7 @@ files: | |
| 260 261 | 
             
            homepage: https://github.com/nulogy/message-bus/tree/master/gems/nulogy_message_bus_producer
         | 
| 261 262 | 
             
            licenses: []
         | 
| 262 263 | 
             
            metadata: {}
         | 
| 263 | 
            -
            post_install_message:
         | 
| 264 | 
            +
            post_install_message: 
         | 
| 264 265 | 
             
            rdoc_options: []
         | 
| 265 266 | 
             
            require_paths:
         | 
| 266 267 | 
             
            - lib
         | 
| @@ -276,7 +277,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 276 277 | 
             
                  version: '0'
         | 
| 277 278 | 
             
            requirements: []
         | 
| 278 279 | 
             
            rubygems_version: 3.0.3
         | 
| 279 | 
            -
            signing_key:
         | 
| 280 | 
            +
            signing_key: 
         | 
| 280 281 | 
             
            specification_version: 4
         | 
| 281 282 | 
             
            summary: Nulogy's code for producing to the Message Bus
         | 
| 282 283 | 
             
            test_files:
         |