Skip to content

Commit

Permalink
Merge pull request #101 from Shopify/add-order-risk
Browse files Browse the repository at this point in the history
Add missing OrderRisk resource
  • Loading branch information
maartenvg committed Jan 20, 2014
2 parents d1b0254 + f253f22 commit 4aa2f42
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/shopify_api/resources/order_risk.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module ShopifyAPI
class OrderRisk < Base
init_prefix :order

self.collection_name = "risks"
self.element_name = "risk"
end
end
14 changes: 14 additions & 0 deletions test/fixtures/order_risk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"risk": {
"cause_cancel": true,
"checkout_id": null,
"display": true,
"id": 284138680,
"message": "This order was placed from a proxy IP",
"order_id": 450789469,
"recommendation": "cancel",
"score": "1.0",
"source": "External",
"merchant_message": "This order was placed from a proxy IP"
}
}
28 changes: 28 additions & 0 deletions test/fixtures/order_risks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"risks": [
{
"cause_cancel": true,
"checkout_id": null,
"display": true,
"id": 284138680,
"message": "This order was placed from a proxy IP",
"order_id": 450789469,
"recommendation": "cancel",
"score": "1.0",
"source": "External",
"merchant_message": "This order was placed from a proxy IP"
},
{
"cause_cancel": true,
"checkout_id": null,
"display": true,
"id": 432527878,
"message": "This order came from an anonymous proxy",
"order_id": 450789469,
"recommendation": "cancel",
"score": "1.0",
"source": "External",
"merchant_message": "This order came from an anonymous proxy"
}
]
}
46 changes: 46 additions & 0 deletions test/order_risk_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require 'test_helper'

class OrderRiskTest < Test::Unit::TestCase
def test_create_order_risk
fake "orders/450789469/risks", :method => :post, :body => load_fixture('order_risk')
v = ShopifyAPI::OrderRisk.new(:order_id => 450789469)
v.message = "This order was placed from a proxy IP"
v.recommendation = "cancel"
v.score = "1.0"
v.source = "External"
v.merchant_message = "This order was placed from a proxy IP"
v.display = true
v.cause_cancel = true
v.save

assert_equal 284138680, v.id
end

def test_get_order_risks
fake "orders/450789469/risks", :method => :get, :body => load_fixture('order_risks')
v = ShopifyAPI::OrderRisk.find(:all, :params => {:order_id => 450789469})
assert_equal 2, v.size
end

def test_get_order_risk
fake "orders/450789469/risks/284138680", :method => :get, :body => load_fixture('order_risk')
v = ShopifyAPI::OrderRisk.find(284138680, :params => {:order_id => 450789469})
assert_equal 284138680, v.id
end

def test_delete_order_risk
fake "orders/450789469/risks/284138680", :method => :get, :body => load_fixture('order_risk')
fake "orders/450789469/risks/284138680", :method => :delete, :body => "destroyed"
v = ShopifyAPI::OrderRisk.find(284138680, :params => {:order_id => 450789469})
assert v.destroy
end

def test_delete_order_risk
fake "orders/450789469/risks/284138680", :method => :get, :body => load_fixture('order_risk')
fake "orders/450789469/risks/284138680", :method => :put, :body => load_fixture('order_risk')

v = ShopifyAPI::OrderRisk.find(284138680, :params => {:order_id => 450789469})
v.position = 3
v.save
end
end

0 comments on commit 4aa2f42

Please sign in to comment.