Skip to content

Commit

Permalink
Merge pull request #4 from clebrun/feature/test-suite
Browse files Browse the repository at this point in the history
Basic testing skeleton.
  • Loading branch information
phstc committed Sep 8, 2015
2 parents ce953e2 + 9200f8a commit 591fa0c
Show file tree
Hide file tree
Showing 9 changed files with 253 additions and 7 deletions.
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ gem 'tilt-jbuilder', require: 'sinatra/jbuilder'
gem 'activesupport', '4.0.3'
gem 'ebay_client', '~> 0.1.0'
gem 'endpoint_base', github: 'spree/endpoint_base'

group :test do
gem 'rspec'
gem 'guard-rspec'
end
55 changes: 55 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,27 @@ GEM
gyoku (>= 0.4.0)
nokogiri
builder (3.2.2)
coderay (1.1.0)
diff-lcs (1.2.5)
ebay_client (0.1.0)
activesupport (>= 3.1.0)
savon (< 2.0.0)
ffi (1.9.10)
formatador (0.2.5)
guard (2.13.0)
formatador (>= 0.2.4)
listen (>= 2.7, <= 4.0)
lumberjack (~> 1.0)
nenv (~> 0.1)
notiffany (~> 0.0)
pry (>= 0.9.12)
shellany (~> 0.0)
thor (>= 0.18.1)
guard-compat (1.2.1)
guard-rspec (4.6.4)
guard (~> 2.1)
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
gyoku (0.4.6)
builder (>= 2.1.2)
httpi (1.1.1)
Expand All @@ -32,15 +50,44 @@ GEM
activesupport (>= 3.0.0, < 5)
multi_json (~> 1.2)
json (1.8.1)
listen (3.0.3)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9)
lumberjack (1.0.9)
method_source (0.8.2)
mini_portile (0.6.0)
minitest (4.7.5)
multi_json (1.10.1)
nenv (0.2.0)
nokogiri (1.6.3.1)
mini_portile (= 0.6.0)
nori (1.1.5)
notiffany (0.0.7)
nenv (~> 0.1)
shellany (~> 0.0)
pry (0.10.1)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
rack (1.5.2)
rack-protection (1.5.3)
rack
rb-fsevent (0.9.5)
rb-inotify (0.9.5)
ffi (>= 0.5.0)
rspec (3.3.0)
rspec-core (~> 3.3.0)
rspec-expectations (~> 3.3.0)
rspec-mocks (~> 3.3.0)
rspec-core (3.3.2)
rspec-support (~> 3.3.0)
rspec-expectations (3.3.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.3.0)
rspec-mocks (3.3.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.3.0)
rspec-support (3.3.0)
savon (1.2.0)
akami (~> 1.2.0)
builder (>= 2.1.2)
Expand All @@ -49,10 +96,13 @@ GEM
nokogiri (>= 1.4.0)
nori (~> 1.1.0)
wasabi (~> 2.5.0)
shellany (0.0.1)
sinatra (1.4.5)
rack (~> 1.4)
rack-protection (~> 1.4)
tilt (~> 1.3, >= 1.3.4)
slop (3.6.0)
thor (0.19.1)
thread_safe (0.3.4)
tilt (1.4.1)
tilt-jbuilder (0.6.0)
Expand All @@ -70,6 +120,11 @@ DEPENDENCIES
activesupport (= 4.0.3)
ebay_client (~> 0.1.0)
endpoint_base!
guard-rspec
rspec
sinatra
tilt (~> 1.4.1)
tilt-jbuilder

BUNDLED WITH
1.10.6
16 changes: 16 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
clearing :on # Clear the screen before running tests again

guard :rspec, cmd: 'bundle exec rspec' do
require 'guard/rspec/dsl'
dsl = Guard::RSpec::Dsl.new(self)

# RSpec files
rspec = dsl.rspec
watch(rspec.spec_helper) { rspec.spec_dir }
watch(rspec.spec_support) { rspec.spec_dir }
watch(rspec.spec_files)

# Ruby files
ruby = dsl.ruby
dsl.watch_spec_files_for(ruby.lib_files)
end
6 changes: 3 additions & 3 deletions lib/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'json'

class Configuration
SANDBOX_URL = 'https://api.sandbox.ebay.com/wsapi'
PRODUCTION_URL = 'https://api.ebay.com/wsapi'
VERSION = 883
SANDBOX_URL ||= 'https://api.sandbox.ebay.com/wsapi'
PRODUCTION_URL ||= 'https://api.ebay.com/wsapi'
VERSION ||= 883

def initialize(config={})
@config = config
Expand Down
4 changes: 2 additions & 2 deletions lib/order.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require 'json'

class Order
WOMBAT_ORDER_INITIAL_VALUES_MAPPING = { 'id' => :order_id,
WOMBAT_ORDER_INITIAL_VALUES_MAPPING ||= { 'id' => :order_id,
'ebay_order_id' => :order_id,
'placed_on' => :created_time }
WOMBAT_ORDER_SHIPPING_VALUES_MAPPING = { 'first_name' => :name,
WOMBAT_ORDER_SHIPPING_VALUES_MAPPING ||= { 'first_name' => :name,
'address1' => :street1,
'address2' => :street2,
'city' => :city,
Expand Down
4 changes: 2 additions & 2 deletions lib/shipment.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'json'

class Shipment
WOMBAT_SHIPMENT_INITIAL_VALUES_MAPPING = { 'id' => :order_id,
WOMBAT_SHIPMENT_INITIAL_VALUES_MAPPING ||= { 'id' => :order_id,
'ebay_order_id' => :order_id }
WOMBAT_SHIPMENT_SHIPPING_VALUES_MAPPING = { 'first_name' => :name,
WOMBAT_SHIPMENT_SHIPPING_VALUES_MAPPING ||= { 'first_name' => :name,
'address1' => :street1,
'address2' => :street2,
'city' => :city,
Expand Down
7 changes: 7 additions & 0 deletions spec/lib/order_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'spec_helper'

RSpec.describe Order do
describe Order.wombat_order_hash(Factories.order) do
it { expect(subject['status']).to eq 'Complete' }
end
end
9 changes: 9 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'bundler'
require 'rubygems'

Bundler.require(:default, :test)

Dir['./lib/**/*.rb'].each(&method(:load))
Dir['./spec/support/*.rb'].each(&method(:load))

Sinatra::Base.environment = 'test'
154 changes: 154 additions & 0 deletions spec/support/factories.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
module Factories
# Collection of stuff to test against
class << self
def line_item
{ transaction_price: '5.00',
quantity_purchased: '1',
taxes: {total_tax_amount: '0.0' },
buyer: { email: '[email protected]',
user_first_name: 'Testfirst',
user_last_name: 'Testlast' },
item: { title: 'Brand New Product!',
item_id: '12345',
sku: 'thisissku' } }
end

def order
{
order_id: '110162297659-27485126001',
order_status: 'Completed',
adjustment_amount: '0.0',
amount_paid: '2.0',
amount_saved: '0.0',
created_time: '2015-05-21T22:37:01.000Z',
payment_methods: 'PayPal',
seller_email: '[email protected]',
shipping_service_selected: { shipping_service: 'USPSFirstClass',
shipping_service_cost: '1.0' },
subtotal: '1.0',
total: '2.0',
external_transaction: { external_transaction_id: '91681732GU4308121',
external_transaction_time: '2015-05-21T23:22:15.000Z',
fee_or_credit_amount: '0.36',
payment_or_refund_amount: '2.0',
external_transaction_status: 'Pending' },
buyer_user_id: 'testuser_gpsmatty',
integrated_merchant_credit_card_enabled: false,
eias_token: 'nY+sHZ2PrBmdj6wVnY+sEZ2PrA2dj6wFk4GhDZeDoAidj6x9nY+seQ==',
payment_hold_status: 'PaymentReview',
is_multi_leg_shipping: false,
seller_user_id: 'testuser_clebrun',
seller_eias_token: 'nY+sHZ2PrBmdj6wVnY+sEZ2PrA2dj6wFk4GhDZaFpwqdj6x9nY+seQ==',
cancel_status: 'NotApplicable',
extended_order_id: '110162297659-27485126001!632290000',
checkout_status: checkout_status,
shipping_details: shipping_details,
shipping_address: shipping_address,
monetary_details: monetary_details,
transaction_array: transaction_array
}
end

def checkout_status
{
e_bay_payment_status: 'PayPalPaymentInProcess',
last_modified_time: '2015-05-21T23:22:16.000Z',
payment_method: 'PayPal',
status: 'Complete',
integrated_merchant_credit_card_enabled: false
}
end

def shipping_details
{
sales_tax: { sales_tax_percent: '0.0',
sales_tax_state: 'CA',
shipping_included_in_tax: false,
sales_tax_amount: '0.0' },
shipping_service_options: [{ shipping_service: 'USPSFirstClass',
shipping_service_cost: '1.0',
shipping_service_priority: '1',
expedited_service: false,
shipping_time_min: '2',
shipping_time_max: '6' },
{ shipping_service: 'UPSNextDayAir',
shipping_service_cost: '1.0',
shipping_service_priority: '2',
expedited_service: true,
shipping_time_min: '1',
shipping_time_max: '1' }],
selling_manager_sales_record_number: '100',
tax_table: { tax_jurisdiction: { sales_tax_percent: '0.0',
shipping_included_in_tax: false } },
get_it_fast: false
}
end

def shipping_address
{
name: 'Test User',
street1: 'address',
street2: nil,
city_name: 'city',
state_or_province: 'WA',
country: 'US',
country_name: 'United States',
phone: '1 800 111 1111',
postal_code: '98102',
address_id: '7544652',
address_owner: 'eBay',
external_address_id: nil
}
end

def monetary_details
{
payments: { payment: {
payment_status: 'Pending',
payer: 'testuser_gpsmatty',
payee: 'testuser_clebrun',
payment_time: '2015-05-21T23:22:15.000Z',
payment_amount: '2.0',
reference_id: '91681732GU4308121',
fee_or_credit_amount: '0.36' } }
}
end

def transaction_array
{
transaction: { buyer: { email: '[email protected]',
user_first_name: 'Test',
user_last_name: 'User' },
shipping_details: { selling_manager_sales_record_number: '100' },
created_date: '2015-05-21T22:37:01.000Z',
item: { item_id: '110162297659',
site: 'US',
title: 'foobar',
sku: 'thisissku' },
quantity_purchased: '1',
status: { payment_hold_status: 'PaymentReview',
inquiry_status: 'NotApplicable',
return_status: 'NotApplicable' },
transaction_id: '27485126001',
transaction_price: '1.0',
final_value_fee: '0.1',
transaction_site_id: 'US',
platform: 'eBay',
taxes: { total_tax_amount: '0.0',
tax_details: [{ imposition: 'SalesTax',
tax_description: 'SalesTax',
tax_amount: '0.0',
tax_on_subtotal_amount: '0.0',
tax_on_shipping_amount: '0.0',
tax_on_handling_amount: '0.0' },
{ imposition: 'WasteRecyclingFee',
tax_description: 'ElectronicWasteRecyclingFee',
tax_amount: '0.0' }] },
actual_shipping_cost: '1.0',
actual_handling_cost: '0.0',
order_line_item_id: '110162297659-27485126001',
extended_order_id: '110162297659-27485126001!632290000' }
}
end
end
end

0 comments on commit 591fa0c

Please sign in to comment.