Skip to content
This repository has been archived by the owner on May 4, 2022. It is now read-only.

Commit

Permalink
Add helper module and methods for test readability
Browse files Browse the repository at this point in the history
  • Loading branch information
allolex committed Apr 15, 2014
1 parent 52ab70d commit 07d8c6a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 20 deletions.
16 changes: 10 additions & 6 deletions spec/lib/nacre/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
before do
stub_request(
:post,
'https://ws-eu1.brightpearl.com/%s/authorise' % [ENV['NACRE_USER_ID']]
auth_url
).to_return(
status: 200,
body: auth_response_success_body,
headers: {}
status: 200,
body: auth_response_success_body,
headers: {}
)
end

Expand Down Expand Up @@ -56,8 +56,12 @@

context 'with bad credentials' do
before do
stub_request(:post, 'https://ws-eu1.brightpearl.com/%s/authorise' % [ENV['NACRE_USER_ID']]).
to_return(:status => 400, :body => auth_response_failure_body, :headers => {})
stub_request(:post, auth_url).
to_return(
status: 400,
body: auth_response_failure_body,
headers: {}
)
end

let(:args) do
Expand Down
7 changes: 1 addition & 6 deletions spec/lib/nacre/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,7 @@
before do
stub_request(
:get,
'https://ws-eu1.brightpearl.com/%s/%s/order-service/order-search?orderId=%s' %
[
Nacre.configuration.api_version,
Nacre.configuration.user_id,
id_text
]
"#{order_search_url}?orderId=%s" % [id_text]
).to_return(
status: 200,
body: fixture_file_content('order_search_result.json'),
Expand Down
10 changes: 2 additions & 8 deletions spec/lib/nacre/product_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,7 @@
before do
stub_request(
:get,
'https://ws-eu1.brightpearl.com/%s/%s/product-service/product-search?productId=%s' %
[
Nacre.configuration.api_version,
Nacre.configuration.user_id,
id_text
]
"#{product_search_url}?productId=%s" % [id_text]
).to_return(
status: 200,
body: fixture_file_content('product_search_result.json') ,
Expand Down Expand Up @@ -147,8 +142,7 @@

describe '.get' do
let(:resource_endpoint) {
"https://ws-eu1.brightpearl.com/%s/%s/#{resource}-service/#{resource}" %
api_details
product_service_url
}

let(:range) { 1018 }
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ def fixture_file(file_name)

include AuthenticationHelper
include NacreConfigHelper
include UrlHelper
37 changes: 37 additions & 0 deletions spec/support/url_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'spec_helper'

module UrlHelper
def base_url
'https://ws-eu1.brightpearl.com/%s/%s' %
[Nacre.configuration.api_version, Nacre.configuration.user_id]
end

def auth_url
'https://ws-eu1.brightpearl.com/%s/authorise' %
[Nacre.configuration.user_id]
end

def resource_service_url(resource)
"#{base_url}/#{resource}-service/#{resource}"
end

def order_service_url
resource_service_url('order')
end

def product_service_url
resource_service_url('product')
end

def resource_search_url(resource)
"#{base_url}/#{resource}-service/#{resource}-search"
end

def order_search_url
resource_search_url('order')
end

def product_search_url
resource_search_url('product')
end
end

0 comments on commit 07d8c6a

Please sign in to comment.