Skip to content

Commit

Permalink
add validations for config
Browse files Browse the repository at this point in the history
  • Loading branch information
prog-supdex committed Sep 27, 2023
1 parent 1dee021 commit da5ccd1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
18 changes: 16 additions & 2 deletions lib/graphql/anycable/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@ class Config < Anyway::Config
attr_config delivery_method: "inline", queue: "default", job_class: "GraphQL::Jobs::TriggerJob"

def job_class=(value)
if value.nil? || value == ""
raise_validation_error "job_class can not be empty"
if empty_value?(value)
raise_validation_error "job_class can not be blank"
end

super
end

def queue=(value)
if empty_value?(value)
raise_validation_error "queue can not be blank"
end

super
Expand All @@ -34,6 +42,12 @@ def delivery_method=(value)

super
end

private

def empty_value?(value)
value.nil? || value == ""
end
end
end
end
27 changes: 27 additions & 0 deletions spec/graphql/anycable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,5 +300,32 @@
expect(config.queue).to eq("test")
expect(config.job_class).to eq("CustomJob")
end

context "when entered invalid delivery_method" do
it "raises an error" do
expect { described_class.delivery_method(nil) }.to raise_error(
Anyway::Config::ValidationError,
/Unknown delivery method - . Allowed methods: inline, active_job/,
)
end
end

context "when entered invalid queue" do
it "raises an error" do
expect { described_class.delivery_method("inline", queue: nil) }.to raise_error(
Anyway::Config::ValidationError,
/queue can not be blank/,
)
end
end

context "when entered invalid queue" do
it "raises an error" do
expect { described_class.delivery_method("inline", job_class: "") }.to raise_error(
Anyway::Config::ValidationError,
/job_class can not be blank/,
)
end
end
end
end

0 comments on commit da5ccd1

Please sign in to comment.