shopify_api 4.9.0 → 5.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/CODEOWNERS +1 -0
- data/.github/probots.yml +2 -0
- data/.gitignore +3 -0
- data/.rubocop.yml +8 -0
- data/.travis.yml +0 -4
- data/CHANGELOG +63 -0
- data/README.md +36 -14
- data/lib/active_resource/detailed_log_subscriber.rb +25 -2
- data/lib/shopify_api/connection.rb +5 -3
- data/lib/shopify_api/limits.rb +1 -2
- data/lib/shopify_api/resources/abandoned_checkout.rb +7 -0
- data/lib/shopify_api/resources/access_scope.rb +5 -0
- data/lib/shopify_api/resources/api_permission.rb +9 -0
- data/lib/shopify_api/resources/asset.rb +8 -8
- data/lib/shopify_api/resources/billing_address.rb +1 -1
- data/lib/shopify_api/resources/checkout.rb +27 -1
- data/lib/shopify_api/resources/collection_publication.rb +10 -0
- data/lib/shopify_api/resources/currency.rb +6 -0
- data/lib/shopify_api/resources/custom_collection.rb +3 -3
- data/lib/shopify_api/resources/{customer_invite_message.rb → customer_invite.rb} +0 -0
- data/lib/shopify_api/resources/graphql.rb +22 -0
- data/lib/shopify_api/resources/image.rb +2 -2
- data/lib/shopify_api/resources/inventory_item.rb +6 -0
- data/lib/shopify_api/resources/inventory_level.rb +55 -0
- data/lib/shopify_api/resources/line_item.rb +9 -1
- data/lib/shopify_api/resources/location.rb +4 -0
- data/lib/shopify_api/resources/o_auth.rb +8 -0
- data/lib/shopify_api/resources/order.rb +16 -4
- data/lib/shopify_api/resources/payment.rb +7 -0
- data/lib/shopify_api/resources/ping.rb +3 -0
- data/lib/shopify_api/resources/ping/conversation.rb +42 -0
- data/lib/shopify_api/resources/ping/delivery_confirmation_details.rb +10 -0
- data/lib/shopify_api/resources/ping/message.rb +8 -0
- data/lib/shopify_api/resources/product.rb +4 -4
- data/lib/shopify_api/resources/product_publication.rb +10 -0
- data/lib/shopify_api/resources/publication.rb +5 -0
- data/lib/shopify_api/resources/shipping_line.rb +1 -1
- data/lib/shopify_api/resources/shipping_rate.rb +7 -0
- data/lib/shopify_api/resources/shop.rb +4 -4
- data/lib/shopify_api/resources/smart_collection.rb +6 -2
- data/lib/shopify_api/resources/tender_transaction.rb +6 -0
- data/lib/shopify_api/session.rb +1 -1
- data/lib/shopify_api/version.rb +1 -1
- data/service.yml +8 -0
- data/shopify_api.gemspec +4 -1
- data/test/abandoned_checkouts_test.rb +29 -0
- data/test/api_permission_test.rb +9 -0
- data/test/checkouts_test.rb +72 -4
- data/test/collection_publication_test.rb +40 -0
- data/test/currency_test.rb +21 -0
- data/test/detailed_log_subscriber_test.rb +19 -1
- data/test/fixtures/abandoned_checkout.json +184 -0
- data/test/fixtures/abandoned_checkouts.json +186 -0
- data/test/fixtures/checkout.json +160 -0
- data/test/fixtures/checkouts.json +25 -49
- data/test/fixtures/collection_publication.json +11 -0
- data/test/fixtures/collection_publications.json +13 -0
- data/test/fixtures/currencies.json +25 -0
- data/test/fixtures/inventory_level.json +7 -0
- data/test/fixtures/inventory_levels.json +24 -0
- data/test/fixtures/order_with_properties.json +373 -0
- data/test/fixtures/payment.json +7 -0
- data/test/fixtures/payments.json +9 -0
- data/test/fixtures/ping/conversation.json +1 -0
- data/test/fixtures/ping/failed_delivery_confirmation.json +1 -0
- data/test/fixtures/ping/message.json +1 -0
- data/test/fixtures/ping/successful_delivery_confirmation.json +1 -0
- data/test/fixtures/product_publication.json +11 -0
- data/test/fixtures/product_publications.json +13 -0
- data/test/fixtures/publications.json +9 -0
- data/test/fixtures/shipping_rates.json +12 -0
- data/test/fixtures/smart_collection_products.json +155 -0
- data/test/fixtures/tender_transactions.json +52 -0
- data/test/inventory_level_test.rb +59 -0
- data/test/location_test.rb +14 -0
- data/test/order_test.rb +29 -1
- data/test/payment_test.rb +19 -0
- data/test/ping/conversation_test.rb +71 -0
- data/test/ping/message_test.rb +23 -0
- data/test/product_publication_test.rb +40 -0
- data/test/publication_test.rb +12 -0
- data/test/session_test.rb +11 -11
- data/test/shipping_rate_test.rb +17 -0
- data/test/smart_collection_test.rb +25 -0
- data/test/tender_transaction_test.rb +18 -0
- data/test/test_helper.rb +8 -5
- data/test/variant_test.rb +4 -1
- metadata +102 -10
- data/lib/shopify_api/resources/discount.rb +0 -11
- data/test/discount_test.rb +0 -52
- data/test/fixtures/discount.json +0 -17
- data/test/fixtures/discount_disabled.json +0 -17
- data/test/fixtures/discounts.json +0 -34
@@ -0,0 +1 @@
|
|
1
|
+
{"conversation":{"id":"d315d4f7-53bd-49ec-8808-23f6db3c641a","name":"my topic","participants":{"counts":{"total":1},"data":[{"id":"test","name":"foo","avatar":null,"group":"customer"}]},"shopify_account":{"domain":"backpackinghacks.myshopify.com"}}}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"delivery_confirmation_details":{"delivery_timestamp":"2018-08-29T22:16:05.589479Z","delivered":"false","details":"Integration failed to deliver message."}}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"message":{"id":"d0c7a2e6-8084-4e79-8483-e4a1352b81f7","sender_id":"test","sender":{"id":"test","name":"foo","avatar":null,"group":"customer"},"content":{"text":"Hello from shopify_api"},"sent_at":"2018-08-29T22:16:05.589479Z"}}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"delivery_confirmation_details":{"delivery_timestamp":"2018-08-29T22:16:05.589479Z","delivered":"true"}}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
{
|
2
|
+
"product_publication": {
|
3
|
+
"id": 647162527768,
|
4
|
+
"publication_id": 55650051,
|
5
|
+
"published_at": "2018-01-29T14:06:08-05:00",
|
6
|
+
"published": true,
|
7
|
+
"created_at": "2018-01-29T14:06:08-05:00",
|
8
|
+
"updated_at": "2018-09-26T15:39:05-04:00",
|
9
|
+
"product_id": 8267093571
|
10
|
+
}
|
11
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
{
|
2
|
+
"product_publications": [
|
3
|
+
{
|
4
|
+
"id": 647162527768,
|
5
|
+
"publication_id": 55650051,
|
6
|
+
"published_at": "2018-01-29T14:06:08-05:00",
|
7
|
+
"published": true,
|
8
|
+
"created_at": "2018-01-29T14:06:08-05:00",
|
9
|
+
"updated_at": "2018-09-26T15:39:05-04:00",
|
10
|
+
"product_id": 8267093571
|
11
|
+
}
|
12
|
+
]
|
13
|
+
}
|
@@ -0,0 +1,155 @@
|
|
1
|
+
{
|
2
|
+
"products": [
|
3
|
+
{
|
4
|
+
"product_type": "Cult Products",
|
5
|
+
"handle": "ipod-nano",
|
6
|
+
"created_at": "2011-10-20T14:05:13-04:00",
|
7
|
+
"body_html": "<p>It's the small iPod with one very big idea: Video. Now the world's most popular music player, available in 4GB and 8GB models, lets you enjoy TV shows, movies, video podcasts, and more. The larger, brighter display means amazing picture quality. In six eye-catching colors, iPod nano is stunning all around. And with models starting at just $149, little speaks volumes.</p>",
|
8
|
+
"title": "IPod Nano - 8GB",
|
9
|
+
"template_suffix": null,
|
10
|
+
"updated_at": "2011-10-20T14:05:13-04:00",
|
11
|
+
"id": 632910392,
|
12
|
+
"tags": "Emotive, Flash Memory, MP3, Music",
|
13
|
+
"images": [
|
14
|
+
{
|
15
|
+
"position": 1,
|
16
|
+
"created_at": "2011-10-20T14:05:13-04:00",
|
17
|
+
"product_id": 632910392,
|
18
|
+
"updated_at": "2011-10-20T14:05:13-04:00",
|
19
|
+
"src": "http://static.shopify.com/s/files/1/6909/3384/products/ipod-nano.png?0",
|
20
|
+
"id": 850703190
|
21
|
+
}
|
22
|
+
],
|
23
|
+
"variants": [
|
24
|
+
{
|
25
|
+
"position": 1,
|
26
|
+
"price": "199.00",
|
27
|
+
"product_id": 632910392,
|
28
|
+
"created_at": "2011-10-20T14:05:13-04:00",
|
29
|
+
"requires_shipping": true,
|
30
|
+
"title": "Pink",
|
31
|
+
"inventory_quantity": 10,
|
32
|
+
"compare_at_price": null,
|
33
|
+
"inventory_policy": "continue",
|
34
|
+
"updated_at": "2011-10-20T14:05:13-04:00",
|
35
|
+
"inventory_management": "shopify",
|
36
|
+
"id": 808950810,
|
37
|
+
"taxable": true,
|
38
|
+
"grams": 200,
|
39
|
+
"sku": "IPOD2008PINK",
|
40
|
+
"option1": "Pink",
|
41
|
+
"fulfillment_service": "manual",
|
42
|
+
"option2": null,
|
43
|
+
"option3": null
|
44
|
+
},
|
45
|
+
{
|
46
|
+
"position": 2,
|
47
|
+
"price": "199.00",
|
48
|
+
"product_id": 632910392,
|
49
|
+
"created_at": "2011-10-20T14:05:13-04:00",
|
50
|
+
"requires_shipping": true,
|
51
|
+
"title": "Red",
|
52
|
+
"inventory_quantity": 20,
|
53
|
+
"compare_at_price": null,
|
54
|
+
"inventory_policy": "continue",
|
55
|
+
"updated_at": "2011-10-20T14:05:13-04:00",
|
56
|
+
"inventory_management": "shopify",
|
57
|
+
"id": 49148385,
|
58
|
+
"taxable": true,
|
59
|
+
"grams": 200,
|
60
|
+
"sku": "IPOD2008RED",
|
61
|
+
"option1": "Red",
|
62
|
+
"fulfillment_service": "manual",
|
63
|
+
"option2": null,
|
64
|
+
"option3": null
|
65
|
+
},
|
66
|
+
{
|
67
|
+
"position": 3,
|
68
|
+
"price": "199.00",
|
69
|
+
"product_id": 632910392,
|
70
|
+
"created_at": "2011-10-20T14:05:13-04:00",
|
71
|
+
"requires_shipping": true,
|
72
|
+
"title": "Green",
|
73
|
+
"inventory_quantity": 30,
|
74
|
+
"compare_at_price": null,
|
75
|
+
"inventory_policy": "continue",
|
76
|
+
"updated_at": "2011-10-20T14:05:13-04:00",
|
77
|
+
"inventory_management": "shopify",
|
78
|
+
"id": 39072856,
|
79
|
+
"taxable": true,
|
80
|
+
"grams": 200,
|
81
|
+
"sku": "IPOD2008GREEN",
|
82
|
+
"option1": "Green",
|
83
|
+
"fulfillment_service": "manual",
|
84
|
+
"option2": null,
|
85
|
+
"option3": null
|
86
|
+
},
|
87
|
+
{
|
88
|
+
"position": 4,
|
89
|
+
"price": "199.00",
|
90
|
+
"product_id": 632910392,
|
91
|
+
"created_at": "2011-10-20T14:05:13-04:00",
|
92
|
+
"requires_shipping": true,
|
93
|
+
"title": "Black",
|
94
|
+
"inventory_quantity": 40,
|
95
|
+
"compare_at_price": null,
|
96
|
+
"inventory_policy": "continue",
|
97
|
+
"updated_at": "2011-10-20T14:05:13-04:00",
|
98
|
+
"inventory_management": "shopify",
|
99
|
+
"id": 457924702,
|
100
|
+
"taxable": true,
|
101
|
+
"grams": 200,
|
102
|
+
"sku": "IPOD2008BLACK",
|
103
|
+
"option1": "Black",
|
104
|
+
"fulfillment_service": "manual",
|
105
|
+
"option2": null,
|
106
|
+
"option3": null
|
107
|
+
}
|
108
|
+
],
|
109
|
+
"vendor": "Apple",
|
110
|
+
"published_at": "2007-12-31T19:00:00-05:00",
|
111
|
+
"manually_sorted": true,
|
112
|
+
"options": [
|
113
|
+
{
|
114
|
+
"name": "Title"
|
115
|
+
}
|
116
|
+
]
|
117
|
+
},
|
118
|
+
{
|
119
|
+
"product_type": "Cult Products",
|
120
|
+
"handle": "ipod-touch",
|
121
|
+
"created_at": "2018-09-26T14:05:13-04:00",
|
122
|
+
"body_html": "<p>The iPod Touch has the iPhone's multi-touch interface, with a physical home button off the touch screen. The home screen has a list of buttons for the available applications.</p>",
|
123
|
+
"title": "IPod Touch 8GB",
|
124
|
+
"template_suffix": null,
|
125
|
+
"updated_at": "2018-09-26T14:05:13-04:00",
|
126
|
+
"id": 921728736,
|
127
|
+
"tags": null,
|
128
|
+
"variants": [
|
129
|
+
{
|
130
|
+
"id": 447654529,
|
131
|
+
"title": "Black",
|
132
|
+
"price": "199.00",
|
133
|
+
"sku": "IPOD2009BLACK",
|
134
|
+
"position": 1,
|
135
|
+
"inventory_policy": "continue",
|
136
|
+
"compare_at_price": null,
|
137
|
+
"fulfillment_service": "manual",
|
138
|
+
"inventory_management": "shopify",
|
139
|
+
"option1": "Black",
|
140
|
+
"option2": null,
|
141
|
+
"option3": null,
|
142
|
+
"created_at": "2018-09-26T14:05:13-04:00",
|
143
|
+
"updated_at": "2018-09-26T14:05:13-04:00",
|
144
|
+
"taxable": true,
|
145
|
+
"grams": 567,
|
146
|
+
"inventory_quantity": 13,
|
147
|
+
"requires_shipping": true
|
148
|
+
}
|
149
|
+
],
|
150
|
+
"vendor": "Apple",
|
151
|
+
"published_at": "2018-09-26T14:05:13-04:00",
|
152
|
+
"manually_sorted": true
|
153
|
+
}
|
154
|
+
]
|
155
|
+
}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
{
|
2
|
+
"tender_transactions": [
|
3
|
+
{
|
4
|
+
"id": 1,
|
5
|
+
"order_id": 450789469,
|
6
|
+
"amount": "138.46",
|
7
|
+
"currency": "CAD",
|
8
|
+
"user_id": null,
|
9
|
+
"test": true,
|
10
|
+
"processed_at": "2018-08-09T15:43:39-04:00",
|
11
|
+
"updated_at": "2018-08-09T15:43:41-04:00",
|
12
|
+
"remote_reference": "1118366",
|
13
|
+
"payment_method": "credit_card",
|
14
|
+
"payment_details": {
|
15
|
+
"credit_card_number": "•••• •••• •••• 1",
|
16
|
+
"credit_card_company": "Bogus"
|
17
|
+
}
|
18
|
+
},
|
19
|
+
{
|
20
|
+
"id": 2,
|
21
|
+
"order_id": 450789469,
|
22
|
+
"amount": "128.16",
|
23
|
+
"currency": "CAD",
|
24
|
+
"user_id": null,
|
25
|
+
"test": true,
|
26
|
+
"processed_at": "2018-08-11T15:43:39-04:00",
|
27
|
+
"updated_at": "2018-08-09T15:43:41-04:00",
|
28
|
+
"remote_reference": "1118367",
|
29
|
+
"payment_method": "credit_card",
|
30
|
+
"payment_details": {
|
31
|
+
"credit_card_number": "•••• •••• •••• 2",
|
32
|
+
"credit_card_company": "Bogus"
|
33
|
+
}
|
34
|
+
},
|
35
|
+
{
|
36
|
+
"id": 3,
|
37
|
+
"order_id": 450789469,
|
38
|
+
"amount": "28.16",
|
39
|
+
"currency": "CAD",
|
40
|
+
"user_id": null,
|
41
|
+
"test": true,
|
42
|
+
"processed_at": "2018-08-12T15:43:39-04:00",
|
43
|
+
"updated_at": "2018-08-09T15:43:41-04:00",
|
44
|
+
"remote_reference": "1118368",
|
45
|
+
"payment_method": "credit_card",
|
46
|
+
"payment_details": {
|
47
|
+
"credit_card_number": "•••• •••• •••• 3",
|
48
|
+
"credit_card_company": "Bogus"
|
49
|
+
}
|
50
|
+
}
|
51
|
+
]
|
52
|
+
}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class InventoryLevelTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
super
|
6
|
+
@inventory_level_response = ActiveSupport::JSON.decode load_fixture('inventory_level')
|
7
|
+
@inventory_level = ShopifyAPI::InventoryLevel.new(@inventory_level_response['inventory_level'])
|
8
|
+
end
|
9
|
+
|
10
|
+
test ".find with inventory_item_ids and location_ids returns expected inventory levels" do
|
11
|
+
params = { inventory_item_ids: [808950810, 39072856], location_ids: [905684977, 487838322] }
|
12
|
+
fake "inventory_levels.json?#{params.to_param}", extension: false, method: :get,
|
13
|
+
status: 200, body: load_fixture('inventory_levels')
|
14
|
+
inventory_levels = ShopifyAPI::InventoryLevel.find(:all, params: params)
|
15
|
+
|
16
|
+
assert inventory_levels.all? { |item|
|
17
|
+
params[:location_ids].include?(item.location_id) &&
|
18
|
+
params[:inventory_item_ids].include?(item.inventory_item_id)
|
19
|
+
}, message: 'Response contained inventory_items or locations not requested.'
|
20
|
+
end
|
21
|
+
|
22
|
+
test '#adjust with adjustment value returns inventory_level with available increased by adjustment value' do
|
23
|
+
adjustment = 5
|
24
|
+
updated_available = @inventory_level.available + adjustment
|
25
|
+
@inventory_level_response[:available] = updated_available
|
26
|
+
|
27
|
+
fake 'inventory_levels/adjust', method: :post, body: ActiveSupport::JSON.encode(@inventory_level_response)
|
28
|
+
@inventory_level.adjust(adjustment)
|
29
|
+
assert_equal updated_available, @inventory_level.available
|
30
|
+
end
|
31
|
+
|
32
|
+
test '#connect saves an inventory_level associated with inventory_item and location_id' do
|
33
|
+
params = { inventory_item_id: 808950810, location_id: 99999999 }
|
34
|
+
response = params.clone
|
35
|
+
response[:available] = 0
|
36
|
+
|
37
|
+
fake 'inventory_levels/connect', method: :post, body: ActiveSupport::JSON.encode(response)
|
38
|
+
inventory_level = ShopifyAPI::InventoryLevel.new(params)
|
39
|
+
inventory_level.connect
|
40
|
+
assert_equal 0, inventory_level.available, message: 'expected newly connected location to have 0 inventory'
|
41
|
+
end
|
42
|
+
|
43
|
+
test '#destroy removes inventory_level and returns nil' do
|
44
|
+
params = { inventory_item_id: @inventory_level.inventory_item_id, location_id: @inventory_level.location_id }
|
45
|
+
fake "inventory_levels.json?#{params.to_param}", extension: false, method: :delete, status: 204, body: nil
|
46
|
+
assert_nil @inventory_level.destroy
|
47
|
+
end
|
48
|
+
|
49
|
+
test '#set with available value returns inventory_level with available as the available value' do
|
50
|
+
available = 13
|
51
|
+
response = @inventory_level_response.clone
|
52
|
+
response['inventory_level']['available'] = available
|
53
|
+
|
54
|
+
fake 'inventory_levels/set', method: :post, body: ActiveSupport::JSON.encode(response)
|
55
|
+
@inventory_level.set(available)
|
56
|
+
|
57
|
+
assert_equal available, @inventory_level.available
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class LocationTest < Test::Unit::TestCase
|
4
|
+
test '#inventory_levels returns all inventory_levels associated with this location' do
|
5
|
+
location = ShopifyAPI::Location.new(id: 487838322)
|
6
|
+
expected_body = JSON.parse(load_fixture('inventory_levels'))
|
7
|
+
expected_body['inventory_levels'].delete_if {|level| level['location_id'] != location.id }
|
8
|
+
fake "locations/#{location.id}/inventory_levels", method: :get, status: 200, body: JSON(expected_body).to_s
|
9
|
+
inventory_levels = location.inventory_levels
|
10
|
+
|
11
|
+
assert inventory_levels.all? { |item| item.location_id == location.id },
|
12
|
+
message: 'Response contained locations other than the current location.'
|
13
|
+
end
|
14
|
+
end
|
data/test/order_test.rb
CHANGED
@@ -8,12 +8,25 @@ class OrderTest < Test::Unit::TestCase
|
|
8
8
|
assert_equal 39072856, order.line_items.first.variant_id
|
9
9
|
end
|
10
10
|
|
11
|
+
test "create should create an order with custom properties" do
|
12
|
+
props = [{ :"By default may label with \"Roasted for " => { :"Your First Name" => { :"\". If you want something specific on the label, enter it here:" => "" }}}]
|
13
|
+
fake 'orders', :method => :post, :status => 201, :body => load_fixture('order_with_properties')
|
14
|
+
order = ShopifyAPI::Order.create(line_items: [{quantity:1, variant_id:39072856, properties:props}], financial_status:"authorized")
|
15
|
+
assert_equal 39072856, order.line_items.first.variant_id
|
16
|
+
end
|
17
|
+
|
11
18
|
test "get should get an order" do
|
12
19
|
fake 'orders/450789469', :method => :get, :status => 200, :body => load_fixture('order')
|
13
20
|
order = ShopifyAPI::Order.find(450789469)
|
14
21
|
assert_equal 450789469, order.id
|
15
22
|
end
|
16
23
|
|
24
|
+
test "get should get an order with custom properties" do
|
25
|
+
fake 'orders/450789469', :method => :get, :status => 200, :body => load_fixture('order_with_properties')
|
26
|
+
order = ShopifyAPI::Order.find(450789469)
|
27
|
+
assert_equal 450789469, order.id
|
28
|
+
end
|
29
|
+
|
17
30
|
test "get all should get all orders" do
|
18
31
|
fake 'orders', :method => :get, :status => 200, :body => load_fixture('orders')
|
19
32
|
order = ShopifyAPI::Order.all
|
@@ -43,5 +56,20 @@ class OrderTest < Test::Unit::TestCase
|
|
43
56
|
order.cancel(email: false, restock: true)
|
44
57
|
assert_request_body({'email' => false, 'restock' => true}.to_json)
|
45
58
|
end
|
46
|
-
end
|
47
59
|
|
60
|
+
test "capture an order with currency param" do
|
61
|
+
fake 'orders/450789469', body: load_fixture('order')
|
62
|
+
order = ShopifyAPI::Order.find(450789469)
|
63
|
+
|
64
|
+
fake 'orders/450789469/transactions', method: :post, status: 201, body: load_fixture('transaction')
|
65
|
+
order.capture(100.00, currency: 'CAD')
|
66
|
+
|
67
|
+
assert_request_body({
|
68
|
+
transaction: {
|
69
|
+
amount: 100.00,
|
70
|
+
kind: 'capture',
|
71
|
+
currency: 'CAD',
|
72
|
+
},
|
73
|
+
}.to_json)
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class PaymentTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
super
|
7
|
+
|
8
|
+
@checkout_id = JSON.parse(load_fixture('checkout'))['checkout']['token']
|
9
|
+
@expected_payment = JSON.parse(load_fixture('payment'))['payment']
|
10
|
+
end
|
11
|
+
|
12
|
+
test ":create creates a new payment" do
|
13
|
+
fake "checkouts/#{@checkout_id}/payments", method: :post, status: 201, body: load_fixture('payment')
|
14
|
+
|
15
|
+
new_payment = ShopifyAPI::Payment.create(checkout_id: @checkout_id)
|
16
|
+
|
17
|
+
assert_equal @expected_payment['unique_token'], new_payment.attributes['unique_token']
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
|
5
|
+
class PingConversationTest < Test::Unit::TestCase
|
6
|
+
def test_create_conversation
|
7
|
+
fake "api/ping-api/v1/conversations", method: :post, body: load_fixture('ping/conversation')
|
8
|
+
|
9
|
+
conversation = ShopifyAPI::Ping::Conversation.new(
|
10
|
+
topic: 'my topic',
|
11
|
+
participants: [
|
12
|
+
{
|
13
|
+
name: 'foo',
|
14
|
+
id: 'test',
|
15
|
+
group: 'customer',
|
16
|
+
},
|
17
|
+
]
|
18
|
+
)
|
19
|
+
|
20
|
+
conversation.save
|
21
|
+
|
22
|
+
assert_equal "d315d4f7-53bd-49ec-8808-23f6db3c641a", conversation.id
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_send_message
|
26
|
+
fake "api/ping-api/v1/conversations/123/messages", method: :post, body: load_fixture('ping/message')
|
27
|
+
|
28
|
+
conversation = ShopifyAPI::Ping::Conversation.new(id: '123')
|
29
|
+
message = conversation.send_message(
|
30
|
+
dedupe_key: SecureRandom.uuid,
|
31
|
+
content: {
|
32
|
+
text: "Hello from shopify_api",
|
33
|
+
},
|
34
|
+
sender_id: 'test',
|
35
|
+
)
|
36
|
+
|
37
|
+
assert_equal "d0c7a2e6-8084-4e79-8483-e4a1352b81f7", message.id
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_successful_delivery
|
41
|
+
fake("api/ping-api/v1/conversations/123/messages/111/delivery_confirmation",
|
42
|
+
method: :post,
|
43
|
+
body: load_fixture('ping/successful_delivery_confirmation'))
|
44
|
+
|
45
|
+
conversation = ShopifyAPI::Ping::Conversation.new(id: '123')
|
46
|
+
delivery_confirmation = conversation.successful_delivery(
|
47
|
+
message_id: '111',
|
48
|
+
delivery_timestamp: "2018-08-29T22:16:05.589479Z"
|
49
|
+
)
|
50
|
+
|
51
|
+
assert_equal("true", delivery_confirmation.delivered)
|
52
|
+
assert_equal("2018-08-29T22:16:05.589479Z", delivery_confirmation.delivery_timestamp)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_failed_delivery
|
56
|
+
fake("api/ping-api/v1/conversations/123/messages/111/delivery_confirmation",
|
57
|
+
method: :post,
|
58
|
+
body: load_fixture('ping/failed_delivery_confirmation'))
|
59
|
+
|
60
|
+
conversation = ShopifyAPI::Ping::Conversation.new(id: '123')
|
61
|
+
delivery_confirmation = conversation.failed_delivery(
|
62
|
+
message_id: '111',
|
63
|
+
delivery_timestamp: Time.now.to_s,
|
64
|
+
details: "Integration failed to deliver message."
|
65
|
+
)
|
66
|
+
|
67
|
+
assert_equal("false", delivery_confirmation.delivered)
|
68
|
+
assert_equal("2018-08-29T22:16:05.589479Z", delivery_confirmation.delivery_timestamp)
|
69
|
+
assert_equal("Integration failed to deliver message.", delivery_confirmation.details)
|
70
|
+
end
|
71
|
+
end
|