-
Notifications
You must be signed in to change notification settings - Fork 468
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 #101 from Shopify/add-order-risk
Add missing OrderRisk resource
- Loading branch information
Showing
4 changed files
with
96 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module ShopifyAPI | ||
class OrderRisk < Base | ||
init_prefix :order | ||
|
||
self.collection_name = "risks" | ||
self.element_name = "risk" | ||
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,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" | ||
} | ||
} |
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,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" | ||
} | ||
] | ||
} |
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,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 |