-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move `Pull` service test to specs * Drop test directory * Remove Minitest from dependencies * Don't run old tests on CI * Remove unused gems * Disable flaky test * Rubocop
- Loading branch information
1 parent
cd153b4
commit 8afbee9
Showing
16 changed files
with
162 additions
and
335 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
require "rails_helper" | ||
|
||
class TestProcessor < BaseProcessor | ||
def entities | ||
JSON.parse(content).map { build_entity(_1.fetch("link"), _1) } | ||
end | ||
end | ||
|
||
class TestNormalizer < BaseNormalizer | ||
def link | ||
content.fetch("link") | ||
end | ||
|
||
def text | ||
content.fetch("text") | ||
end | ||
|
||
def validation_errors | ||
[].tap do |errors| | ||
errors << "empty_link" if link.blank? | ||
errors << "empty_text" if text.blank? | ||
end | ||
end | ||
end | ||
|
||
RSpec.describe Pull do | ||
subject(:service) { described_class } | ||
|
||
let(:feed_url) { "https://example.com/sample_feed" } | ||
|
||
let(:feed) do | ||
create( | ||
:feed, | ||
name: "test", | ||
loader: "http", | ||
processor: "test", | ||
normalizer: "test", | ||
import_limit: 0, | ||
url: feed_url | ||
) | ||
end | ||
|
||
let(:expected) do | ||
[ | ||
NormalizedEntity.new( | ||
feed_id: feed.id, | ||
uid: "https://example.com/0", | ||
link: "https://example.com/0", | ||
published_at: nil, | ||
text: "Sample entity", | ||
attachments: [], | ||
comments: [], | ||
validation_errors: [] | ||
) | ||
] | ||
end | ||
|
||
let(:feed_entities) do | ||
[ | ||
NormalizedEntity.new( | ||
feed_id: feed.id, | ||
uid: "https://example.com/0", | ||
link: "https://example.com/0", | ||
published_at: nil, | ||
text: "Sample entity", | ||
attachments: [], | ||
comments: [], | ||
validation_errors: [] | ||
), | ||
NormalizedEntity.new( | ||
feed_id: feed.id, | ||
uid: "https://example.com/1", | ||
link: "https://example.com/1", | ||
published_at: nil, | ||
text: "Sample entity", | ||
attachments: [], | ||
comments: [], | ||
validation_errors: [] | ||
), | ||
NormalizedEntity.new( | ||
feed_id: feed.id, | ||
uid: "https://example.com/2", | ||
link: "https://example.com/2", | ||
published_at: nil, | ||
text: "", | ||
attachments: [], | ||
comments: [], | ||
validation_errors: ["empty_text"] | ||
) | ||
] | ||
end | ||
|
||
let(:feed_content) do | ||
<<~JSON | ||
[ | ||
{ | ||
"link": "https://example.com/0", | ||
"text": "Sample entity" | ||
}, | ||
{ | ||
"link": "https://example.com/1", | ||
"text": "Sample entity" | ||
}, | ||
{ | ||
"link": "https://example.com/2", | ||
"text": null | ||
} | ||
] | ||
JSON | ||
end | ||
|
||
let(:processor_error_content) do | ||
<<~JSON | ||
[ | ||
{ | ||
"link": "https://example.com/0", | ||
"text": "Sample entity" | ||
}, | ||
{ | ||
"text": "Sample entity" | ||
} | ||
] | ||
JSON | ||
end | ||
|
||
let(:normalizer_error_content) do | ||
<<~JSON | ||
[ | ||
{ | ||
"link": "https://example.com/0", | ||
"text": "Sample entity" | ||
}, | ||
{ | ||
"link": "https://example.com/1" | ||
} | ||
] | ||
JSON | ||
end | ||
|
||
it "do the call" do | ||
stub_feed_loader_request(feed_content) | ||
expect(feed_entities).to eq(service.call(feed)) | ||
end | ||
|
||
# NOTE: Processor will fail due to the lack of the required 'link' field. | ||
# Processing error should stop the workflow. | ||
it "handles processor error" do | ||
stub_feed_loader_request(processor_error_content) | ||
assert_raises(KeyError) { service.call(feed) } | ||
end | ||
|
||
# NOTE: Normalizer will fail due to the lack of the required 'text' field. | ||
# Normalizer error should not stop the workflow. | ||
it "handles normalizer error" do | ||
stub_feed_loader_request(normalizer_error_content) | ||
expect(service.call(feed)).to eq(expected) | ||
end | ||
|
||
def stub_feed_loader_request(content) | ||
stub_request(:get, feed_url).to_return(body: content) | ||
end | ||
end |
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.