Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Chore] Improve the test for the core business domain #26

Open
longnd opened this issue Jan 9, 2023 · 1 comment
Open

[Chore] Improve the test for the core business domain #26

longnd opened this issue Jan 9, 2023 · 1 comment
Assignees

Comments

@longnd
Copy link

longnd commented Jan 9, 2023

Issue

While the application is well tested, the core business domain in the CreateKeywordsAndResultsService has not been fully tested.

def create_keywords_and_results
@keywords.each_with_index do |key, index|
raise YouAreABot, 'Detected By Google' if check_captcha_exists?
keyword = CreateKeywordService.call(key, @search.id)
google_search(keyword.name) unless index.zero?
CreateResultService.call(result_params(keyword.id))
rescue YouAreABot

The main part of the service:

  • stores the keywords in DB
  • Search on Google
  • store the search report for the keyword

but the test is fairly simple

it 'create keyword and result' do
allow_any_instance_of(described_class).to receive(:google_search).and_return(true)
allow_any_instance_of(described_class).to receive(:act_like_human).and_return(true)
expect(CreateKeywordService)
.to receive(:call)
.and_return(keyword)
.exactly(search.keywords_from_file.count).times
expect(CreateResultService)
.to receive(:call)
.and_return(true)
.exactly(search.keywords_from_file.count).times
described_class.call(search.id, url: url)
end
# rubocop:enable Layout/AnyInstance, RSpec/MultipleExpectations, RSpec/MessageSpies, Rspec/ExampleLength
end

it does not cover the 2nd step that doing the actual search and extracting the result.

by using a gem like https://github.com/vcr/vcr to record the HTTP request, that step can be actually tested, right?

Expected

The core business domain - search the keyword on google and extract the result - is fully tested.

@htoo-eain-lwin
Copy link
Owner

Hello @longnd ,

Thanks for pointing out. When I am done fixing issue #24 , it can be easily tested due to separate logic. I will create a PR for this issue also.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants