Skip to content

Commit

Permalink
feat: service for connecting to the mock data endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
noahdurbin committed Aug 30, 2024
1 parent b9ab7b6 commit 8d157c8
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 4 deletions.
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ group :development, :test do
gem 'rspec-rails', '~> 6.1'
gem 'shoulda-matchers', '~> 6.4'
gem 'simplecov', '~> 0.22.0'
gem 'vcr', '~> 6.3'
gem "webmock", "~> 3.23"
end

group :development do
Expand All @@ -60,4 +62,4 @@ end

gem 'redis'
gem 'sidekiq'
gem 'sidekiq-cron'
gem 'sidekiq-cron'
15 changes: 15 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ GEM
coderay (1.1.3)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
crack (1.0.0)
bigdecimal
rexml
crass (1.0.6)
date (3.3.4)
debug (1.9.2)
Expand Down Expand Up @@ -123,6 +126,7 @@ GEM
raabro (~> 1.4)
globalid (1.2.1)
activesupport (>= 6.1)
hashdiff (1.1.1)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
io-console (0.7.2)
Expand Down Expand Up @@ -231,6 +235,8 @@ GEM
regexp_parser (2.9.2)
reline (0.5.9)
io-console (~> 0.5)
rexml (3.3.6)
strscan
rspec-core (3.13.0)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.2)
Expand Down Expand Up @@ -267,11 +273,18 @@ GEM
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
stringio (3.1.1)
strscan (3.1.0)
thor (1.3.1)
timeout (0.4.1)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
uri (0.13.0)
vcr (6.3.1)
base64
webmock (3.23.1)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
webrick (1.8.1)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
Expand Down Expand Up @@ -309,6 +322,8 @@ DEPENDENCIES
sidekiq-cron
simplecov (~> 0.22.0)
tzinfo-data
vcr (~> 6.3)
webmock (~> 3.23)

RUBY VERSION
ruby 3.2.2p53
Expand Down
8 changes: 5 additions & 3 deletions app/services/summary_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ def conn
)
end

def summarize
conn.post('api/v1/ping') do |req|
req.body = { link: 'wwww.example.com' }.to_json
def summarize(resource)
response = conn.post('api/v1/ping') do |req|
req.body = { link: resource }.to_json
end

JSON.parse(response.body, symbolize_names: true)
end
end
Binary file added dump.rdb
Binary file not shown.
7 changes: 7 additions & 0 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,10 @@
with.library :rails
end
end

VCR.configure do |config|
config.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
config.hook_into :webmock
config.configure_rspec_metadata!
config.allow_http_connections_when_no_cassette = true
end
17 changes: 17 additions & 0 deletions spec/services/summary_service_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'rails_helper'

RSpec.describe SummaryService do
it 'gets a summary for a link', :vcr do
sum_service = SummaryService.new
sum_service.summarize('www.example.com')

expect(response).to be_successful
summary = JSON.parse(response.body, symbolize_names: true)

expect(summary[:data]).to have_key(:link)
expect(summary[:data]).to have_key(:summary)

expect(summary[:data][link]).to eq 'www.example.com'
expect(summary[:data][:summary]).to eq "1. example 1\n2. example 2\n3. example 3"
end
end

0 comments on commit 8d157c8

Please sign in to comment.