checkout_ru 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,124 @@
1
+ require 'test_helper'
2
+
3
+ class CheckoutRuTest < MiniTest::Test
4
+ def build_order
5
+ CheckoutRu::Order.new(
6
+ :goods => [
7
+ CheckoutRu::Item.new(
8
+ :name => 'blue tshirt',
9
+ :code => 'blt',
10
+ :variant_code => 'blue',
11
+ :quantity => 2,
12
+ :assessed_cost => 1000,
13
+ :pay_cost => 750,
14
+ :weight => 0.5
15
+ )
16
+ ],
17
+
18
+ :delivery => CheckoutRu::Delivery.new(
19
+ :delivery_id => 2,
20
+ :place_fias_id => '0c5b2444-70a0-4932-980c-b4dc0d3f02b5',
21
+ :address_pvz => 'Энтузиастов ш., д. 54',
22
+ :type => 'postamat',
23
+ :cost => 224.41,
24
+ :min_term => 2,
25
+ :max_term => 11
26
+ ),
27
+
28
+ :user => CheckoutRu::User.new(
29
+ :fullname => 'Вася Пупкин',
30
+ :email => 'vasyapupkin@example.com',
31
+ :phone => '555'
32
+ ),
33
+
34
+ :comment => 'test order',
35
+ :shop_order_id => '777',
36
+ :payment_method => 'cash'
37
+ )
38
+ end
39
+
40
+ def test_get_ticket_returns_valid_ticket
41
+ VCR.use_cassette('get_ticket') do
42
+ assert_equal 'valid-ticket',
43
+ CheckoutRu.get_ticket(:api_key => 'valid-api-key')
44
+ end
45
+ end
46
+
47
+ def test_get_ticket_with_invalid_api_key_raises_invalid_key_error
48
+ VCR.use_cassette('get_ticket_invalid_api_key') do
49
+ assert_raises CheckoutRu::Error do
50
+ CheckoutRu.get_ticket(:api_key => 'invalid-api-key')
51
+ end
52
+ end
53
+ end
54
+
55
+ def test_create_order
56
+ order = build_order
57
+
58
+ VCR.use_cassette('create_order') do
59
+ response = CheckoutRu.create_order(order, :api_key => 'valid-api-key')
60
+
61
+ assert_equal 75, response.order.id
62
+ assert_equal 2, response.delivery.id
63
+ assert_equal 'PickPoint', response.delivery.service_name
64
+ end
65
+ end
66
+
67
+ def test_update_order
68
+ order = build_order
69
+ order.user.fullname = 'Петя Пупкин'
70
+
71
+ VCR.use_cassette('update_order') do
72
+ response = CheckoutRu.update_order(75, order, :api_key => 'valid-api-key')
73
+
74
+ assert_equal 75, response.order.id
75
+ assert_equal 2, response.delivery.id
76
+ assert_equal 'PickPoint', response.delivery.service_name
77
+ end
78
+ end
79
+
80
+ def test_status
81
+ VCR.use_cassette('status') do
82
+ response = CheckoutRu.status \
83
+ 75, :cancelled_before_shipment, :api_key => 'valid-api-key'
84
+ assert_equal '', response
85
+ end
86
+ end
87
+
88
+ def test_status_history
89
+ VCR.use_cassette('status_history') do
90
+ response = CheckoutRu.status_history(777, :api_key => 'valid-api-key')
91
+
92
+ assert_equal '75', response.order.id
93
+ assert_equal Date.parse('2014-02-01'), response.order.date
94
+ assert_equal 1724.41, response.order.total_cost
95
+ assert_equal nil, response.order.approximate_delivery_date
96
+ assert_equal 'Петя Пупкин', response.user.fullname
97
+ assert_equal 'г. Москва', response.user.address.place
98
+ assert_equal 'PickPoint', response.delivery_name
99
+ assert_equal [], response.delivery_history
100
+ end
101
+ end
102
+
103
+ def test_populated_status_history
104
+ VCR.use_cassette('populated_status_history') do
105
+ response = CheckoutRu.status_history(64, :api_key => 'valid-api-key')
106
+
107
+ assert_equal '64', response.order.id
108
+ assert_equal Date.parse('2013-10-14'), response.order.date
109
+ assert_equal 1136.33, response.order.total_cost
110
+ assert_equal nil, response.order.approximate_delivery_date
111
+
112
+ assert_equal 'ввв', response.user.fullname
113
+ assert_equal 'г. Волгоград (Волгоградская область)',
114
+ response.user.address.place
115
+
116
+ assert_equal 'DPD', response.delivery_name
117
+
118
+ assert_equal 9, response.delivery_history.size
119
+ assert_equal 'Посылка находится на терминале DPD, который осуществлял ' +
120
+ 'её приём у отправителя', response.delivery_history[0].status
121
+ assert_equal '10.09.2013 17:19:13', response.delivery_history[0].date
122
+ end
123
+ end
124
+ end