peddler 2.1.1 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +43 -41
- data/lib/mws.rb +2 -1
- data/lib/mws/easy_ship.rb +3 -0
- data/lib/mws/easy_ship/client.rb +93 -0
- data/lib/mws/fulfillment_outbound_shipment/client.rb +1 -1
- data/lib/mws/orders/client.rb +6 -6
- data/lib/mws/shipment_invoicing.rb +3 -0
- data/lib/mws/shipment_invoicing/client.rb +74 -0
- data/lib/peddler/client.rb +11 -10
- data/lib/peddler/content.rb +2 -2
- data/lib/peddler/errors/builder.rb +7 -2
- data/lib/peddler/errors/class_generator.rb +1 -1
- data/lib/peddler/errors/error.rb +6 -2
- data/lib/peddler/errors/parser.rb +1 -1
- data/lib/peddler/flat_file_parser.rb +5 -3
- data/lib/peddler/marketplace.rb +23 -19
- data/lib/peddler/mws.rb +2 -2
- data/lib/peddler/operation.rb +17 -11
- data/lib/peddler/parser.rb +1 -1
- data/lib/peddler/structured_list.rb +1 -1
- data/lib/peddler/vcr_matcher.rb +7 -7
- data/lib/peddler/version.rb +1 -1
- data/lib/peddler/xml_parser.rb +1 -1
- data/lib/peddler/xml_response_parser.rb +1 -1
- metadata +11 -146
- data/lib/mws/off_amazon_payments/client.rb +0 -362
- data/test/credentials.rb +0 -23
- data/test/helper.rb +0 -15
- data/test/integration/internals/test_errors.rb +0 -17
- data/test/integration/internals/test_multibyte_queries.rb +0 -17
- data/test/integration/internals/test_mws_headers.rb +0 -21
- data/test/integration/internals/test_string_encodings.rb +0 -38
- data/test/integration/test_feeds.rb +0 -37
- data/test/integration/test_fulfillment_inbound_shipment.rb +0 -35
- data/test/integration/test_fulfillment_inventory.rb +0 -20
- data/test/integration/test_fulfillment_outbound_shipment.rb +0 -13
- data/test/integration/test_merchant_fulfillment.rb +0 -69
- data/test/integration/test_off_amazon_payments.rb +0 -13
- data/test/integration/test_orders.rb +0 -30
- data/test/integration/test_products.rb +0 -97
- data/test/integration/test_recommendations.rb +0 -20
- data/test/integration/test_reports.rb +0 -51
- data/test/integration/test_sellers.rb +0 -13
- data/test/integration/test_subscriptions.rb +0 -27
- data/test/integration_helper.rb +0 -53
- data/test/mws.yml +0 -36
- data/test/mws.yml.example +0 -32
- data/test/null_client.rb +0 -25
- data/test/recorder.rb +0 -39
- data/test/unit/mws/test_feeds_client.rb +0 -103
- data/test/unit/mws/test_finances_client.rb +0 -74
- data/test/unit/mws/test_fulfillment_inbound_shipment_client.rb +0 -426
- data/test/unit/mws/test_fulfillment_inventory_client.rb +0 -48
- data/test/unit/mws/test_fulfillment_outbound_shipment_client.rb +0 -202
- data/test/unit/mws/test_merchant_fulfillment_client.rb +0 -109
- data/test/unit/mws/test_off_amazon_payments_client.rb +0 -286
- data/test/unit/mws/test_orders_client.rb +0 -111
- data/test/unit/mws/test_products_client.rb +0 -248
- data/test/unit/mws/test_recommendations_client.rb +0 -62
- data/test/unit/mws/test_reports_client.rb +0 -209
- data/test/unit/mws/test_sellers_client.rb +0 -47
- data/test/unit/mws/test_subscriptions_client.rb +0 -182
- data/test/unit/peddler/errors/test_builder.rb +0 -65
- data/test/unit/peddler/errors/test_class_generator.rb +0 -18
- data/test/unit/peddler/errors/test_error.rb +0 -33
- data/test/unit/peddler/errors/test_parser.rb +0 -44
- data/test/unit/peddler/test_client.rb +0 -203
- data/test/unit/peddler/test_flat_file_parser.rb +0 -111
- data/test/unit/peddler/test_headers.rb +0 -103
- data/test/unit/peddler/test_marketplace.rb +0 -47
- data/test/unit/peddler/test_operation.rb +0 -87
- data/test/unit/peddler/test_parser.rb +0 -36
- data/test/unit/peddler/test_structured_list.rb +0 -39
- data/test/unit/peddler/test_vcr_matcher.rb +0 -55
- data/test/unit/peddler/test_xml_parser.rb +0 -37
- data/test/unit/peddler/test_xml_response_parser.rb +0 -39
- data/test/unit/test_mws.rb +0 -11
- data/test/vcr_cassettes/CartInformation.yml +0 -433
- data/test/vcr_cassettes/CustomerInformation.yml +0 -433
- data/test/vcr_cassettes/Errors.yml +0 -444
- data/test/vcr_cassettes/Feeds.yml +0 -9957
- data/test/vcr_cassettes/FulfillmentInboundShipment.yml +0 -6166
- data/test/vcr_cassettes/FulfillmentInventory.yml +0 -850
- data/test/vcr_cassettes/FulfillmentOutboundShipment.yml +0 -433
- data/test/vcr_cassettes/MWSHeaders.yml +0 -2964
- data/test/vcr_cassettes/MerchantFulfillment.yml +0 -753
- data/test/vcr_cassettes/MultibyteQueries.yml +0 -437
- data/test/vcr_cassettes/OffAmazonPayments.yml +0 -433
- data/test/vcr_cassettes/Orders.yml +0 -4740
- data/test/vcr_cassettes/PeddlerVCRMatcher.yml +0 -41
- data/test/vcr_cassettes/Products.yml +0 -7139
- data/test/vcr_cassettes/Recommendations.yml +0 -3145
- data/test/vcr_cassettes/Reports.yml +0 -5549
- data/test/vcr_cassettes/Sellers.yml +0 -433
- data/test/vcr_cassettes/Subscriptions.yml +0 -1529
@@ -1,111 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
require 'peddler/flat_file_parser'
|
5
|
-
|
6
|
-
class TestPeddlerFlatFileParser < MiniTest::Test
|
7
|
-
def test_parsing_data
|
8
|
-
body = build_body("Feed Processing Summary:\n\tNumber of records processed\t\t11006\n\tNumber of records successful\t\t11006\n\noriginal-record-number\tsku\terror-code\terror-type\terror-message\n1822\t85da472e-ba6c-11e3-95af-002590a74356\t5000\tWarning\tThe update for Sku '85da472e-ba6c-11e3-95af-002590a74356' was skipped because it is identical to the update in feed '9518995390'.\n",
|
9
|
-
encoding: Encoding::ASCII_8BIT)
|
10
|
-
parser = Peddler::FlatFileParser.new(build_mock_response(body), 'ISO-8859-1')
|
11
|
-
assert_kind_of CSV::Table, parser.parse
|
12
|
-
end
|
13
|
-
|
14
|
-
def test_parsing_data_a_line_at_a_time
|
15
|
-
body = build_body("Feed Processing Summary:\n\tNumber of records processed\t\t11006\n\tNumber of records successful\t\t11006\n\noriginal-record-number\tsku\terror-code\terror-type\terror-message\n1822\t85da472e-ba6c-11e3-95af-002590a74356\t5000\tWarning\tThe update for Sku '85da472e-ba6c-11e3-95af-002590a74356' was skipped because it is identical to the update in feed '9518995390'.\n",
|
16
|
-
encoding: Encoding::ASCII_8BIT)
|
17
|
-
parser = Peddler::FlatFileParser.new(build_mock_response(body), 'ISO-8859-1')
|
18
|
-
counter = 0
|
19
|
-
parser.parse { counter += 1 }
|
20
|
-
assert counter.positive?
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_the_work_around_empty_rows
|
24
|
-
body = build_body("Feed Processing Summary:\n\tNumber of records processed\t\t2\n\tNumber of records successful\t\t2\n\nfoo\tbar\n1\ta\n\n2\tb\n",
|
25
|
-
encoding: Encoding::ASCII_8BIT)
|
26
|
-
parser = Peddler::FlatFileParser.new(build_mock_response(body), 'ISO-8859-1')
|
27
|
-
assert_equal 3, parser.parse.count
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_summary
|
31
|
-
body = build_body("Feed Processing Summary:\n\tNumber of records processed\t\t11006\n\tNumber of records successful\t\t11006\n\noriginal-record-number\tsku\terror-code\terror-type\terror-message\n1822\t85da472e-ba6c-11e3-95af-002590a74356\t5000\tWarning\tThe update for Sku '85da472e-ba6c-11e3-95af-002590a74356' was skipped because it is identical to the update in feed '9518995390'.\n",
|
32
|
-
encoding: Encoding::ASCII_8BIT)
|
33
|
-
parser = Peddler::FlatFileParser.new(build_mock_response(body), 'ISO-8859-1')
|
34
|
-
refute_empty parser.records_count
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_summary_of_non_english_reports
|
38
|
-
body = build_body("Riepilogo elaborazione feed:\n\tNumero record elaborati\t\t1\n\tNumero record elaborati con successo\t\t1\n\n",
|
39
|
-
encoding: 'Cp1252')
|
40
|
-
parser = Peddler::FlatFileParser.new(build_mock_response(body), 'ISO-8859-1')
|
41
|
-
refute_empty parser.records_count
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_validates
|
45
|
-
body = build_body("Feed Processing Summary:\n\tNumber of records processed\t\t11006\n\tNumber of records successful\t\t11006\n\noriginal-record-number\tsku\terror-code\terror-type\terror-message\n1822\t85da472e-ba6c-11e3-95af-002590a74356\t5000\tWarning\tThe update for Sku '85da472e-ba6c-11e3-95af-002590a74356' was skipped because it is identical to the update in feed '9518995390'.\n",
|
46
|
-
encoding: Encoding::ASCII_8BIT)
|
47
|
-
parser = Peddler::FlatFileParser.new(build_mock_response(body), 'ISO-8859-1')
|
48
|
-
assert parser.valid?
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_handling_reports_without_a_summary
|
52
|
-
response = OpenStruct.new(body: "Foo\nBar\n")
|
53
|
-
parser = Peddler::FlatFileParser.new(response, 'ISO-8859-1')
|
54
|
-
refute_empty parser.content
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_encoding_if_passed_in_header
|
58
|
-
body = build_body("Foo\nfür\n", encoding: Encoding::UTF_8)
|
59
|
-
parser = Peddler::FlatFileParser.new(build_mock_response(body,
|
60
|
-
charset: 'UTF-8'),
|
61
|
-
Encoding::CP1252)
|
62
|
-
assert_equal 'für', parser.parse[0]['Foo']
|
63
|
-
end
|
64
|
-
|
65
|
-
def test_handling_japanese_flat_files
|
66
|
-
body = build_body("Foo\nこんにちは\n", encoding: Encoding::SHIFT_JIS)
|
67
|
-
parser = Peddler::FlatFileParser.new(build_mock_response(body), Encoding::WINDOWS_31J)
|
68
|
-
assert_equal 'こんにちは', parser.parse[0]['Foo']
|
69
|
-
end
|
70
|
-
|
71
|
-
def test_handling_japanese_curly_braces
|
72
|
-
body = build_body("Foo\n〝\n", encoding: Encoding::WINDOWS_31J)
|
73
|
-
parser = Peddler::FlatFileParser.new(build_mock_response(body), Encoding::WINDOWS_31J)
|
74
|
-
assert_equal '〝', parser.parse[0]['Foo']
|
75
|
-
end
|
76
|
-
|
77
|
-
def test_handling_latin_1_flat_files
|
78
|
-
body = build_body("Foo\n™\n", encoding: 'Cp1252')
|
79
|
-
parser = Peddler::FlatFileParser.new(build_mock_response(body), Encoding::CP1252)
|
80
|
-
assert_equal '™', parser.parse['Foo'][0]
|
81
|
-
end
|
82
|
-
|
83
|
-
def test_handling_undefined_characters
|
84
|
-
body = +"Foo\n\xFF\n"
|
85
|
-
body.force_encoding(Encoding::ASCII_8BIT)
|
86
|
-
parser = Peddler::FlatFileParser.new(build_mock_response(body), Encoding::ASCII_8BIT)
|
87
|
-
assert_equal '�', parser.parse['Foo'][0]
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_handling_utf8_flat_files
|
91
|
-
body = "Foo\nfür\n"
|
92
|
-
parser = Peddler::FlatFileParser.new(build_mock_response(body, ascii: false), Encoding::CP1252)
|
93
|
-
assert_equal 'für', parser.parse['Foo'][0]
|
94
|
-
end
|
95
|
-
|
96
|
-
private
|
97
|
-
|
98
|
-
def build_body(str, encoding:)
|
99
|
-
str.dup.encode(encoding)
|
100
|
-
end
|
101
|
-
|
102
|
-
def build_mock_response(body, ascii: true, charset: nil)
|
103
|
-
body.force_encoding(Encoding::ASCII_8BIT) if ascii
|
104
|
-
headers = {
|
105
|
-
'Content-MD5' => Digest::MD5.base64digest(body)
|
106
|
-
}
|
107
|
-
headers['Content-Type'] = "text/plain;charset=#{charset}" if charset
|
108
|
-
|
109
|
-
OpenStruct.new(body: body, headers: headers)
|
110
|
-
end
|
111
|
-
end
|
@@ -1,103 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
require 'peddler/headers'
|
5
|
-
|
6
|
-
class TestPeddlerHeaders < MiniTest::Test
|
7
|
-
include ::Peddler::Headers
|
8
|
-
|
9
|
-
attr_reader :headers
|
10
|
-
|
11
|
-
def setup
|
12
|
-
@headers = {
|
13
|
-
'Content-Length' => '100',
|
14
|
-
'Content-MD5' => 'rkkx1Xv/k56/onrN0m7E/Q==',
|
15
|
-
'Content-Type' => 'text/plain;charset=UTF-8',
|
16
|
-
'x-mws-quota-max' => '200.0',
|
17
|
-
'x-mws-quota-remaining' => '200.0',
|
18
|
-
'x-mws-quota-resetsOn' => '2017-01-30T00:03:00.000Z',
|
19
|
-
'x-mws-request-id' => '123',
|
20
|
-
'x-mws-timestamp' => '2017-01-29T23:55:25.356Z',
|
21
|
-
'x-mws-response-context' => 'foo'
|
22
|
-
}
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_content_length
|
26
|
-
assert_kind_of Integer, content_length
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_content_md5
|
30
|
-
assert content_md5
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_content_media_type
|
34
|
-
assert content_media_type
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_content_type
|
38
|
-
assert content_type
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_content_subtype
|
42
|
-
assert content_subtype
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_content_charset
|
46
|
-
assert_kind_of Encoding, content_charset
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_no_content_length
|
50
|
-
@headers.delete('Content-Length')
|
51
|
-
assert_nil content_length
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_no_content_type
|
55
|
-
@headers.delete('Content-Type')
|
56
|
-
assert_nil content_media_type
|
57
|
-
assert_nil content_type
|
58
|
-
assert_nil content_subtype
|
59
|
-
assert_nil content_charset
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_no_content_charset
|
63
|
-
@headers['Content-Type'] = 'text/xml'
|
64
|
-
assert content_media_type
|
65
|
-
assert content_type
|
66
|
-
assert content_subtype
|
67
|
-
assert_nil content_charset
|
68
|
-
end
|
69
|
-
|
70
|
-
def test_mws_quota_max
|
71
|
-
assert_kind_of Integer, mws_quota_max
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_mws_quota_remaining
|
75
|
-
assert_kind_of Integer, mws_quota_remaining
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_mws_quota_resets_on
|
79
|
-
assert_kind_of Time, mws_quota_resets_on
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_request_id
|
83
|
-
assert mws_request_id
|
84
|
-
end
|
85
|
-
|
86
|
-
def test_timestamp
|
87
|
-
assert_kind_of Time, mws_timestamp
|
88
|
-
end
|
89
|
-
|
90
|
-
def test_response_context
|
91
|
-
assert mws_response_context
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_handling_no_quota
|
95
|
-
@headers = {}
|
96
|
-
assert_nil mws_quota_max
|
97
|
-
assert_nil mws_quota_remaining
|
98
|
-
assert_nil mws_quota_resets_on
|
99
|
-
assert_nil mws_request_id
|
100
|
-
assert_nil mws_timestamp
|
101
|
-
assert_nil mws_response_context
|
102
|
-
end
|
103
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
require 'peddler/marketplace'
|
5
|
-
|
6
|
-
class TestPeddlerMarketplace < MiniTest::Test
|
7
|
-
def setup
|
8
|
-
@marketplace = Peddler::Marketplace.find('ATVPDKIKX0DER')
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_country_code
|
12
|
-
assert @marketplace.country_code
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_host
|
16
|
-
assert @marketplace.host
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_encoding
|
20
|
-
assert @marketplace.encoding
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_guard_against_missing_country_code
|
24
|
-
error = assert_raises ArgumentError do
|
25
|
-
Peddler::Marketplace.find(nil)
|
26
|
-
end
|
27
|
-
assert_equal 'missing marketplace', error.message
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_guard_against_invalid_country_code
|
31
|
-
error = assert_raises ArgumentError do
|
32
|
-
Peddler::Marketplace.find('FOO')
|
33
|
-
end
|
34
|
-
assert_equal '"FOO" is not a valid marketplace', error.message
|
35
|
-
end
|
36
|
-
|
37
|
-
class TestFindByCountryCode < TestPeddlerMarketplace
|
38
|
-
def setup
|
39
|
-
@marketplace = Peddler::Marketplace.find('US')
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_translation_of_uk_to_gb
|
43
|
-
marketplace = Peddler::Marketplace.find('UK')
|
44
|
-
assert_equal 'GB', marketplace.country_code
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
@@ -1,87 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
require 'peddler/operation'
|
5
|
-
|
6
|
-
class TestPeddlerOperation < MiniTest::Test
|
7
|
-
def setup
|
8
|
-
@operation = Peddler::Operation.new('Foo')
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_that_it_converts_key_to_structured_list
|
12
|
-
@operation.store('FooStatus', [1, 2])
|
13
|
-
@operation.structure!('FooStatus', 'Foo')
|
14
|
-
refute @operation.key?('FooStatus')
|
15
|
-
assert_equal 1, @operation['FooStatus.Foo.1']
|
16
|
-
assert_equal 2, @operation['FooStatus.Foo.2']
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_that_it_converts_nested_keys_to_structured_list
|
20
|
-
@operation.store('Foo.1.Status', [{ 'Baz' => 1 }])
|
21
|
-
@operation.store('Foo.2.Status', [{ 'Baz' => 2 }])
|
22
|
-
@operation.structure!('Status', 'Bar')
|
23
|
-
refute @operation.key?('Foo.1.Status')
|
24
|
-
refute @operation.key?('Foo.2.Status')
|
25
|
-
assert_equal 1, @operation['Foo.1.Status.Bar.1.Baz']
|
26
|
-
assert_equal 2, @operation['Foo.2.Status.Bar.1.Baz']
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_that_store_camelizes_symbol_key
|
30
|
-
@operation.store(:foo_bar, 'baz')
|
31
|
-
assert @operation.key?('FooBar')
|
32
|
-
refute @operation.key?(:foo_bar)
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_that_store_wont_camelize_string_key
|
36
|
-
@operation.store('foo_bar', 'baz')
|
37
|
-
assert @operation.key?('foo_bar')
|
38
|
-
refute @operation.key?('FooBar')
|
39
|
-
end
|
40
|
-
|
41
|
-
def test_that_store_wont_camelize_symbol_key_with_capital_letter
|
42
|
-
@operation.store('MarketplaceId'.to_sym, '1')
|
43
|
-
assert @operation.key?('MarketplaceId')
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_that_store_upcases_sku
|
47
|
-
@operation.store(:seller_sku, 'foo')
|
48
|
-
assert @operation.key?('SellerSKU')
|
49
|
-
refute @operation.key?(:seller_sku)
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_that_store_upcases_cod
|
53
|
-
@operation.store(:include_cod_fulfillment_preview, 'foo')
|
54
|
-
assert @operation.key?('IncludeCODFulfillmentPreview')
|
55
|
-
refute @operation.key?(:include_cod_fulfillment_preview)
|
56
|
-
end
|
57
|
-
|
58
|
-
def test_that_store_timestamps_time_values
|
59
|
-
ts = Minitest::Mock.new
|
60
|
-
ts.expect(:iso8601, 'foo')
|
61
|
-
@operation.store('time', ts)
|
62
|
-
|
63
|
-
assert_equal 'foo', @operation.fetch('time')
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_stringifying_hash_values
|
67
|
-
@operation.store('Foo', bar: 1)
|
68
|
-
assert_equal 1, @operation.fetch('Foo.Bar')
|
69
|
-
refute @operation.key?('Foo')
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_stringifying_nested_hash_values
|
73
|
-
@operation.store('Foo', bar: { baz: 1 })
|
74
|
-
assert_equal 1, @operation.fetch('Foo.Bar.Baz')
|
75
|
-
refute @operation.key?('Foo')
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_stringifying_struct_values
|
79
|
-
@operation.store('Foo', Struct.new(:bar, :baz).new(1, 2))
|
80
|
-
assert_equal 1, @operation.fetch('Foo.Bar')
|
81
|
-
assert_equal 2, @operation.fetch('Foo.Baz')
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_that_update_returns_delegator
|
85
|
-
assert_kind_of Peddler::Operation, @operation.add(foo: 'bar')
|
86
|
-
end
|
87
|
-
end
|
@@ -1,36 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
require 'peddler/parser'
|
5
|
-
|
6
|
-
class TestPeddlerParser < MiniTest::Test
|
7
|
-
def assert_parser(klass, *content_types, body: '')
|
8
|
-
content_types.each do |content_type|
|
9
|
-
res = OpenStruct.new(
|
10
|
-
headers: { 'Content-Type' => content_type },
|
11
|
-
body: body
|
12
|
-
)
|
13
|
-
parser = Peddler::Parser.new(res, 'Cp1252')
|
14
|
-
|
15
|
-
assert_kind_of klass, parser
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_parsing_xml
|
20
|
-
assert_parser Peddler::XMLParser,
|
21
|
-
'text/xml',
|
22
|
-
'text/xml; charset=UTF-8'
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_parsing_incorrect_content_type
|
26
|
-
assert_parser Peddler::XMLParser,
|
27
|
-
'xml; charset=UTF-8',
|
28
|
-
body: '<?xml version="1.0"?><GetLowestOfferListingsForASINResponse>...'
|
29
|
-
end
|
30
|
-
|
31
|
-
def test_parsing_flat_files
|
32
|
-
assert_parser Peddler::FlatFileParser,
|
33
|
-
'text/plain',
|
34
|
-
'application/octet-stream'
|
35
|
-
end
|
36
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
require 'peddler/structured_list'
|
5
|
-
|
6
|
-
class TestPeddlerStructuredList < MiniTest::Test
|
7
|
-
def setup
|
8
|
-
@list = Peddler::StructuredList.new('OrderStatus', 'Status')
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_building_a_structured_list_for_a_single_value
|
12
|
-
exp = { 'OrderStatus.Status.1' => 'foo' }
|
13
|
-
assert_equal exp, @list.build('foo')
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_building_a_structured_list_for_an_array_of_values
|
17
|
-
exp = { 'OrderStatus.Status.1' => 'foo', 'OrderStatus.Status.2' => 'bar' }
|
18
|
-
assert_equal exp, @list.build(%w[foo bar])
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_flattening_nested_arrays_of_values
|
22
|
-
exp = { 'OrderStatus.Status.1' => 'foo', 'OrderStatus.Status.2' => 'bar' }
|
23
|
-
assert_equal exp, @list.build([%w[foo bar]])
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_handling_single_key
|
27
|
-
list = Peddler::StructuredList.new('Foo')
|
28
|
-
exp = { 'Foo.1' => 'bar' }
|
29
|
-
|
30
|
-
assert_equal exp, list.build('bar')
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_handling_more_than_two_keys
|
34
|
-
list = Peddler::StructuredList.new('QueryList', 'Query', '1', 'FilterOptions', 'FilterOption')
|
35
|
-
exp = { 'QueryList.Query.1.FilterOptions.FilterOption.1' => 'foo' }
|
36
|
-
|
37
|
-
assert_equal exp, list.build('foo')
|
38
|
-
end
|
39
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
require 'null_client'
|
5
|
-
require 'peddler/vcr_matcher'
|
6
|
-
require 'recorder'
|
7
|
-
|
8
|
-
class TestPeddlerVCRMatcher < MiniTest::Test
|
9
|
-
include Recorder
|
10
|
-
::Peddler::VCRMatcher.ignore_seller!
|
11
|
-
|
12
|
-
def setup
|
13
|
-
VCR.insert_cassette(test_name)
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_matching_recorded_post_without_body
|
17
|
-
client.run
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_wont_match_unrecorded_post_without_body
|
21
|
-
client.operation.add(foo: 'bar')
|
22
|
-
assert_raises(VCR::Errors::UnhandledHTTPRequestError) do
|
23
|
-
client.run
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_matching_recorded_post_with_body
|
28
|
-
client.body = 'content'
|
29
|
-
client.run
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_that_it_wont_match_unrecorded_post_with_different_query_and_same_body
|
33
|
-
client.operation.add(foo: 'bar')
|
34
|
-
client.body = 'content'
|
35
|
-
assert_raises(VCR::Errors::UnhandledHTTPRequestError) do
|
36
|
-
client.run
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_that_it_wont_match_unrecorded_post_with_same_query_and_different_body
|
41
|
-
client.body = 'other content'
|
42
|
-
assert_raises(VCR::Errors::UnhandledHTTPRequestError) do
|
43
|
-
client.run
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def client
|
48
|
-
@client ||= begin
|
49
|
-
client = Class.new(Null::Client).new
|
50
|
-
client.configure_with_mock_data!
|
51
|
-
client.operation('Action')
|
52
|
-
client
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|