-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from rickpeyton/fake-api-client
Fake api client and invalid request exception
- Loading branch information
Showing
15 changed files
with
108 additions
and
69 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
example_id | status | run_time | | ||
----------------------------------------- | ------ | --------------- | | ||
./spec/nintendo_eshop/game_spec.rb[1:1:1] | passed | 0.00568 seconds | | ||
./spec/nintendo_eshop/game_spec.rb[1:1:2] | passed | 0.0112 seconds | | ||
./spec/nintendo_eshop_spec.rb[1:1] | passed | 0.00086 seconds | | ||
example_id | status | run_time | | ||
------------------------------------------------------ | ------ | --------------- | | ||
./spec/acceptance/retrieve_a_valid_record_spec.rb[1:1] | passed | 0.11786 seconds | | ||
./spec/nintendo_eshop/game_spec.rb[1:1:1] | passed | 0.00419 seconds | | ||
./spec/nintendo_eshop/game_spec.rb[1:1:2] | passed | 0.00606 seconds | | ||
./spec/nintendo_eshop/game_spec.rb[1:1:3] | passed | 0.00398 seconds | | ||
./spec/nintendo_eshop_spec.rb[1:1] | passed | 0.00083 seconds | |
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 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,21 @@ | ||
module NintendoEshop | ||
class APIClient | ||
class << self | ||
def post(uri, json: {}) | ||
http = setup_http(uri) | ||
req = Net::HTTP::Post.new(uri) | ||
req.add_field "Accept", "application/json" | ||
req.add_field "Content-Type", "application/json" | ||
req.body = JSON.dump(json) | ||
http.request(req) | ||
end | ||
|
||
def setup_http(uri) | ||
http = Net::HTTP.new(uri.host, uri.port) | ||
http.use_ssl = true | ||
http.verify_mode = OpenSSL::SSL::VERIFY_PEER | ||
http | ||
end | ||
end | ||
end | ||
end |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module NintendoEshop | ||
VERSION = "0.1.0.alpha2".freeze | ||
VERSION = "0.1.0.alpha3".freeze | ||
end |
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,15 @@ | ||
RSpec.describe "Retrieve a valid game" do | ||
it "can retrieve a game from the Nintendo API" do | ||
WebMock.allow_net_connect! | ||
NintendoEshop.client = NintendoEshop::APIClient | ||
|
||
game = NintendoEshop::Game.retrieve("70010000001130") | ||
|
||
expect(game).to be_a NintendoEshop::Game | ||
expect(game.current_price).to eq(game.msrp).or eq(game.sale_price) | ||
expect(game.sale_price).to be_a(Integer).or be_nil | ||
|
||
NintendoEshop.client = NintendoEshop::FakeClient | ||
WebMock.disable_net_connect! | ||
end | ||
end |
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,19 @@ | ||
module NintendoEshop | ||
class FakeClient | ||
class << self | ||
def post(_uri, json: {}) | ||
response = case json.dig(:query) | ||
when "70010000001539" | ||
File.read("spec/http_responses/sonic_response.txt") | ||
when "70010000001130" | ||
File.read("spec/http_responses/mario_response.txt") | ||
when "invalid" | ||
File.read("spec/http_responses/invalid_response.txt") | ||
end | ||
OpenStruct.new( | ||
body: response | ||
) | ||
end | ||
end | ||
end | ||
end |
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 @@ | ||
{"hits":[],"nbHits":0,"page":0,"nbPages":0,"hitsPerPage":20,"processingTimeMS":1,"exhaustiveNbHits":true,"query":"invalid","params":"query=invalid&restrictSearchableAttributes=%5B%22nsuid%22%5D"} |
File renamed without changes.
File renamed without changes.
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