From ca1fe8a16bd35e68f9886436eed8f2e66c4b44f4 Mon Sep 17 00:00:00 2001 From: Dan Milne Date: Fri, 11 Oct 2019 10:18:58 +1100 Subject: [PATCH] Add tests for item parsing --- test/item_test.rb | 59 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 test/item_test.rb diff --git a/test/item_test.rb b/test/item_test.rb new file mode 100644 index 0000000..ecb53d6 --- /dev/null +++ b/test/item_test.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +require 'test_helper' + +class ItemTest < Minitest::Test + + TEST_CASES = [ + { + name: 'Search Items with multiple EANS', + response: 'search_items_multiple_eans.json', + item_count: 10, + items: [ + { + title: "FUNKO POP! Movie Moment: Marvel - Thor vs Thanos", + asin: 'B07HBBC1M5', + image_url: 'https://m.media-amazon.com/images/I/51B3xXr-ElL.jpg', + eans: ["0889698357999", "6952669003752"], + authors: [], + brand: 'Funko', + model: '35799' + } + ] + }, + { + name: 'Get ', + response: 'items_get_B079PQ7T6B.json', + item_count: 1, + items: [ + { + title: "FUNKO POP! Marvel: Avengers Infinity War - Thanos", + asin: 'B079PQ7T6B', + image_url: 'https://m.media-amazon.com/images/I/4107DRyNZpL.jpg', + eans: ["0889698264679", "0615912346988"], + authors: [], + brand: 'Funko', + model: '26467' + } + ] + } + ] + + def test_response_parsing + TEST_CASES.each do |tc| + + http_resp = MockHttpResponse.new(File.read(File.join('test/data/', tc[:response]))) + resp = Paapi::Response.new(http_resp) + + assert_equal tc[:item_count], resp.items.count if tc.key?(:item_count) + + tc[:items].each_with_index do |item, idx| + item.keys.each do |exp| + assert_equal item[exp], resp.items[idx].send(exp) + end + end + end + end + + +end \ No newline at end of file