nulogy_message_bus_producer 3.4.0 → 3.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -2
- data/lib/nulogy_message_bus_producer.rb +6 -4
- data/lib/nulogy_message_bus_producer/config.rb +1 -1
- data/lib/nulogy_message_bus_producer/self_serve_subscription.rb +18 -0
- data/lib/nulogy_message_bus_producer/subscriptions/configured_subscription.rb +14 -0
- data/lib/nulogy_message_bus_producer/subscriptions/finder.rb +2 -2
- data/lib/nulogy_message_bus_producer/subscriptions/postgres_transport.rb +2 -2
- data/lib/nulogy_message_bus_producer/subscriptions/query_validator.rb +1 -1
- data/lib/nulogy_message_bus_producer/subscriptions/valid_for_schema_validator.rb +14 -0
- data/lib/nulogy_message_bus_producer/version.rb +1 -1
- data/spec/dummy/log/test.log +1974 -0
- data/spec/integration/lib/nulogy_message_bus_producer/subscription_spec.rb +3 -75
- data/spec/integration_spec_helper.rb +0 -6
- data/spec/nulogy_message_bus_producer/subscriptions/subscription_spec.rb +9 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/support/shared_examples/subscription_validations.rb +77 -0
- data/spec/support/sql_helpers.rb +1 -1
- data/spec/support/subscription_helpers.rb +2 -2
- metadata +9 -3
- data/lib/nulogy_message_bus_producer/subscription.rb +0 -30
@@ -1,79 +1,7 @@
|
|
1
1
|
require "integration_spec_helper"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
model = build_subscription(id: "")
|
7
|
-
|
8
|
-
model.validate
|
9
|
-
|
10
|
-
expect(model.errors[:id]).to contain_exactly("can't be blank")
|
11
|
-
end
|
12
|
-
|
13
|
-
it "is invalid without a subscription_group_id" do
|
14
|
-
model = build_subscription(subscription_group_id: "")
|
15
|
-
|
16
|
-
model.validate
|
17
|
-
|
18
|
-
expect(model.errors[:subscription_group_id]).to contain_exactly("can't be blank")
|
19
|
-
end
|
20
|
-
|
21
|
-
it "is invalid with a blank query" do
|
22
|
-
model = build_subscription(query: "")
|
23
|
-
|
24
|
-
model.validate
|
25
|
-
|
26
|
-
expect(model.errors[:query]).to contain_exactly("can't be blank")
|
27
|
-
end
|
28
|
-
|
29
|
-
it "is invalid with blank schema_key" do
|
30
|
-
model = build_subscription(schema_key: "")
|
31
|
-
|
32
|
-
model.validate
|
33
|
-
|
34
|
-
expect(model.errors[:schema_key]).to contain_exactly("can't be blank")
|
35
|
-
end
|
36
|
-
|
37
|
-
it "is invalid with an invalid schema_key" do
|
38
|
-
model = build_subscription(schema_key: "invalid")
|
39
|
-
|
40
|
-
model.validate
|
41
|
-
|
42
|
-
expect(model.errors[:query]).to contain_exactly(/Could not find a schema for schema_key 'invalid'/)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "is invalid with an invalid query" do
|
46
|
-
model = build_subscription(
|
47
|
-
query: subscription_query(query: "foo { a_field_that_does_not_exist }")
|
48
|
-
)
|
49
|
-
|
50
|
-
model.validate
|
51
|
-
|
52
|
-
expect(model).not_to be_valid
|
53
|
-
expect(model.errors[:query]).to contain_exactly(
|
54
|
-
match(/Field 'a_field_that_does_not_exist' doesn't exist on type 'testObject'/)
|
55
|
-
)
|
56
|
-
end
|
57
|
-
|
58
|
-
it "valid with a valid query" do
|
59
|
-
model = build_subscription(
|
60
|
-
query: subscription_query(query: "foo { id }")
|
61
|
-
)
|
62
|
-
|
63
|
-
model.validate
|
64
|
-
|
65
|
-
expect(model.errors).not_to include(:query)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def build_subscription(overrides = {})
|
70
|
-
attrs = {
|
71
|
-
id: SecureRandom.uuid,
|
72
|
-
subscription_group_id: SecureRandom.uuid,
|
73
|
-
schema_key: "test",
|
74
|
-
query: subscription_query,
|
75
|
-
}.merge(overrides)
|
76
|
-
|
77
|
-
NulogyMessageBusProducer::Subscription.new(attrs)
|
3
|
+
module NulogyMessageBusProducer
|
4
|
+
RSpec.describe SelfServeSubscription do
|
5
|
+
include_examples "subscription validations"
|
78
6
|
end
|
79
7
|
end
|
@@ -1,6 +1,3 @@
|
|
1
|
-
# Make all rspec configuration changes to this file.
|
2
|
-
# Leave automatically generated configuration files untouched to facilitate gem upgrades.
|
3
|
-
|
4
1
|
ENV["RAILS_ENV"] ||= "test"
|
5
2
|
|
6
3
|
require File.expand_path("dummy/config/environment.rb", __dir__)
|
@@ -10,8 +7,6 @@ require "rspec/json_expectations"
|
|
10
7
|
require "active_record"
|
11
8
|
require "spec_helper"
|
12
9
|
|
13
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }
|
14
|
-
|
15
10
|
RSpec.configure do |config|
|
16
11
|
# Uncomment this line to see full backtraces for spec failures
|
17
12
|
# config.backtrace_exclusion_patterns = []
|
@@ -37,5 +32,4 @@ RSpec.configure do |config|
|
|
37
32
|
|
38
33
|
config.include(SpecUtils)
|
39
34
|
config.include(SqlHelpers)
|
40
|
-
config.include(SubscriptionHelpers)
|
41
35
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require "rails/all"
|
2
2
|
require "nulogy_message_bus_producer"
|
3
3
|
|
4
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }
|
5
|
+
|
4
6
|
RSpec.configure do |config|
|
5
7
|
config.expect_with(:rspec) do |expectations|
|
6
8
|
# This is generally recommended, and will default to `true` in RSpec 4.
|
@@ -52,4 +54,6 @@ RSpec.configure do |config|
|
|
52
54
|
example.run
|
53
55
|
end
|
54
56
|
end
|
57
|
+
|
58
|
+
config.include(SubscriptionHelpers)
|
55
59
|
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
RSpec.shared_examples "subscription validations" do
|
2
|
+
context "when validating" do
|
3
|
+
it "is invalid without an id" do
|
4
|
+
model = build_subscription(id: "")
|
5
|
+
|
6
|
+
model.validate
|
7
|
+
|
8
|
+
expect(model.errors[:id]).to contain_exactly("can't be blank")
|
9
|
+
end
|
10
|
+
|
11
|
+
it "is invalid without a subscription_group_id" do
|
12
|
+
model = build_subscription(subscription_group_id: "")
|
13
|
+
|
14
|
+
model.validate
|
15
|
+
|
16
|
+
expect(model.errors[:subscription_group_id]).to contain_exactly("can't be blank")
|
17
|
+
end
|
18
|
+
|
19
|
+
it "is invalid with a blank query" do
|
20
|
+
model = build_subscription(query: "")
|
21
|
+
|
22
|
+
model.validate
|
23
|
+
|
24
|
+
expect(model.errors[:query]).to contain_exactly("can't be blank")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "is invalid with blank schema_key" do
|
28
|
+
model = build_subscription(schema_key: "")
|
29
|
+
|
30
|
+
model.validate
|
31
|
+
|
32
|
+
expect(model.errors[:schema_key]).to contain_exactly("can't be blank")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "is invalid with an invalid schema_key" do
|
36
|
+
model = build_subscription(schema_key: "invalid")
|
37
|
+
|
38
|
+
model.validate
|
39
|
+
|
40
|
+
expect(model.errors[:query]).to contain_exactly(/Could not find a schema for schema_key 'invalid'/)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "is invalid with an invalid query" do
|
44
|
+
model = build_subscription(
|
45
|
+
query: subscription_query(query: "foo { a_field_that_does_not_exist }")
|
46
|
+
)
|
47
|
+
|
48
|
+
model.validate
|
49
|
+
|
50
|
+
expect(model).not_to be_valid
|
51
|
+
expect(model.errors[:query]).to contain_exactly(
|
52
|
+
match(/Field 'a_field_that_does_not_exist' doesn't exist on type 'testObject'/)
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "valid with a valid query" do
|
57
|
+
model = build_subscription(
|
58
|
+
query: subscription_query(query: "foo { id }")
|
59
|
+
)
|
60
|
+
|
61
|
+
model.validate
|
62
|
+
|
63
|
+
expect(model.errors).not_to include(:query)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def build_subscription(overrides = {})
|
68
|
+
attrs = {
|
69
|
+
id: SecureRandom.uuid,
|
70
|
+
subscription_group_id: SecureRandom.uuid,
|
71
|
+
schema_key: "test",
|
72
|
+
query: subscription_query
|
73
|
+
}.merge(overrides)
|
74
|
+
|
75
|
+
described_class.new(attrs)
|
76
|
+
end
|
77
|
+
end
|
data/spec/support/sql_helpers.rb
CHANGED
@@ -14,7 +14,7 @@ module SqlHelpers
|
|
14
14
|
|
15
15
|
# Just incase these models weren't loaded, do them explicitly
|
16
16
|
ActiveRecord::Base.connection.execute("TRUNCATE #{NulogyMessageBusProducer::SubscriptionEvent.table_name}")
|
17
|
-
ActiveRecord::Base.connection.execute("TRUNCATE #{NulogyMessageBusProducer::
|
17
|
+
ActiveRecord::Base.connection.execute("TRUNCATE #{NulogyMessageBusProducer::SelfServeSubscription.table_name}")
|
18
18
|
end
|
19
19
|
|
20
20
|
def replication_slots
|
@@ -9,9 +9,9 @@ module SubscriptionHelpers
|
|
9
9
|
expect {
|
10
10
|
gql_response = execute_graphql(gql, schema)
|
11
11
|
expect(gql_response).to eq(data: {})
|
12
|
-
}.to change(NulogyMessageBusProducer::
|
12
|
+
}.to change(NulogyMessageBusProducer::SelfServeSubscription, :count).by(1)
|
13
13
|
|
14
|
-
NulogyMessageBusProducer::
|
14
|
+
NulogyMessageBusProducer::SelfServeSubscription.find(subscription_id)
|
15
15
|
end
|
16
16
|
|
17
17
|
def configured_subscription(
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nulogy_message_bus_producer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.4.
|
4
|
+
version: 3.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nulogy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|
@@ -224,13 +224,15 @@ files:
|
|
224
224
|
- lib/nulogy_message_bus_producer/configuration/query_parser.rb
|
225
225
|
- lib/nulogy_message_bus_producer/engine.rb
|
226
226
|
- lib/nulogy_message_bus_producer/repopulate_replication_slots.rb
|
227
|
-
- lib/nulogy_message_bus_producer/
|
227
|
+
- lib/nulogy_message_bus_producer/self_serve_subscription.rb
|
228
228
|
- lib/nulogy_message_bus_producer/subscription_event.rb
|
229
|
+
- lib/nulogy_message_bus_producer/subscriptions/configured_subscription.rb
|
229
230
|
- lib/nulogy_message_bus_producer/subscriptions/finder.rb
|
230
231
|
- lib/nulogy_message_bus_producer/subscriptions/no_variables.rb
|
231
232
|
- lib/nulogy_message_bus_producer/subscriptions/postgres_transport.rb
|
232
233
|
- lib/nulogy_message_bus_producer/subscriptions/query_validator.rb
|
233
234
|
- lib/nulogy_message_bus_producer/subscriptions/risky_subscription_blocker.rb
|
235
|
+
- lib/nulogy_message_bus_producer/subscriptions/valid_for_schema_validator.rb
|
234
236
|
- lib/nulogy_message_bus_producer/version.rb
|
235
237
|
- lib/tasks/engine/message_bus_producer.rake
|
236
238
|
- spec/dummy/Rakefile
|
@@ -298,9 +300,11 @@ files:
|
|
298
300
|
- spec/integration/lib/nulogy_message_bus_producer/subscriptions/risky_subscription_blocker_spec.rb
|
299
301
|
- spec/integration_spec_helper.rb
|
300
302
|
- spec/nulogy_message_bus_producer/configuration/query_parser_spec.rb
|
303
|
+
- spec/nulogy_message_bus_producer/subscriptions/subscription_spec.rb
|
301
304
|
- spec/spec_helper.rb
|
302
305
|
- spec/support/kafka.rb
|
303
306
|
- spec/support/kafka_connect.rb
|
307
|
+
- spec/support/shared_examples/subscription_validations.rb
|
304
308
|
- spec/support/spec_utils.rb
|
305
309
|
- spec/support/sql_helpers.rb
|
306
310
|
- spec/support/subscription_helpers.rb
|
@@ -398,5 +402,7 @@ test_files:
|
|
398
402
|
- spec/support/kafka.rb
|
399
403
|
- spec/support/spec_utils.rb
|
400
404
|
- spec/support/sql_helpers.rb
|
405
|
+
- spec/support/shared_examples/subscription_validations.rb
|
401
406
|
- spec/support/test_graphql_schema.rb
|
402
407
|
- spec/nulogy_message_bus_producer/configuration/query_parser_spec.rb
|
408
|
+
- spec/nulogy_message_bus_producer/subscriptions/subscription_spec.rb
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module NulogyMessageBusProducer
|
2
|
-
# This model saves all subscriptions to external systems.
|
3
|
-
# An external system can subscribe to events and specify the shape of data it would like to receive for the event.
|
4
|
-
class Subscription < ApplicationRecord
|
5
|
-
self.table_name = :message_bus_subscriptions
|
6
|
-
|
7
|
-
# Run our validator with familar syntax in this model
|
8
|
-
class ValidForSchemaValidator < ActiveModel::EachValidator
|
9
|
-
def validate_each(record, attribute, _value)
|
10
|
-
return if record.schema_key.blank? || record.query.blank?
|
11
|
-
|
12
|
-
validator = NulogyMessageBusProducer::Subscriptions::QueryValidator.new
|
13
|
-
|
14
|
-
validator.validate(record)
|
15
|
-
validator.errors.each { |e| record.errors.add(attribute, e) }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
validates :id, presence: true
|
20
|
-
validates :subscription_group_id, presence: true
|
21
|
-
validates :schema_key, :event_type, presence: true
|
22
|
-
validates :query, presence: true, valid_for_schema: true
|
23
|
-
|
24
|
-
def self.create_or_update(attrs)
|
25
|
-
find_or_initialize_by(id: attrs[:id]).tap do |model|
|
26
|
-
model.update!(attrs)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|