pixi_client 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +34 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +4 -0
  5. data/Guardfile +45 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +171 -0
  8. data/Rakefile +8 -0
  9. data/lib/pixi_client/configuration.rb +5 -0
  10. data/lib/pixi_client/requests/add_comment_to_order.rb +20 -0
  11. data/lib/pixi_client/requests/base.rb +25 -0
  12. data/lib/pixi_client/requests/cancel_order.rb +19 -0
  13. data/lib/pixi_client/requests/cancel_order_line.rb +19 -0
  14. data/lib/pixi_client/requests/get_changed_item_stock.rb +27 -0
  15. data/lib/pixi_client/requests/get_changed_items.rb +19 -0
  16. data/lib/pixi_client/requests/get_invoice.rb +19 -0
  17. data/lib/pixi_client/requests/get_item_info.rb +19 -0
  18. data/lib/pixi_client/requests/get_item_stock_bins.rb +18 -0
  19. data/lib/pixi_client/requests/get_items_info.rb +34 -0
  20. data/lib/pixi_client/requests/get_items_on_stock_bin.rb +19 -0
  21. data/lib/pixi_client/requests/get_items_stock_history.rb +18 -0
  22. data/lib/pixi_client/requests/get_order_comments.rb +19 -0
  23. data/lib/pixi_client/requests/get_order_header.rb +19 -0
  24. data/lib/pixi_client/requests/get_order_line_history.rb +22 -0
  25. data/lib/pixi_client/requests/get_order_lines.rb +21 -0
  26. data/lib/pixi_client/requests/get_order_nr_external_by_box_nr.rb +19 -0
  27. data/lib/pixi_client/requests/get_stock.rb +19 -0
  28. data/lib/pixi_client/requests/get_stock_by_bin.rb +19 -0
  29. data/lib/pixi_client/requests/get_unshippable_orders.rb +19 -0
  30. data/lib/pixi_client/requests/itemable.rb +24 -0
  31. data/lib/pixi_client/requests/read_items.rb +23 -0
  32. data/lib/pixi_client/requests/read_orderlines.rb +18 -0
  33. data/lib/pixi_client/requests/set_stock_multiple.rb +19 -0
  34. data/lib/pixi_client/requests/shipping_get_picklist_details.rb +19 -0
  35. data/lib/pixi_client/requests/shipping_get_picklist_headers.rb +19 -0
  36. data/lib/pixi_client/requests.rb +27 -0
  37. data/lib/pixi_client/response.rb +12 -0
  38. data/lib/pixi_client/response_parser.rb +137 -0
  39. data/lib/pixi_client/version.rb +3 -0
  40. data/lib/pixi_client.rb +17 -0
  41. data/pixi_client.gemspec +32 -0
  42. data/spec/fixtures/get_order_nr_external_by_box_nr.xml +51 -0
  43. data/spec/fixtures/pixi_get_changed_item_stock.xml +140 -0
  44. data/spec/integration/pixi_get_changed_item_stock_spec.rb +85 -0
  45. data/spec/lib/pixi_client/configuration_spec.rb +47 -0
  46. data/spec/lib/pixi_client/requests/add_comment_to_order_spec.rb +48 -0
  47. data/spec/lib/pixi_client/requests/cancel_order_line_spec.rb +47 -0
  48. data/spec/lib/pixi_client/requests/cancel_order_spec.rb +47 -0
  49. data/spec/lib/pixi_client/requests/get_changed_item_stock_spec.rb +61 -0
  50. data/spec/lib/pixi_client/requests/get_changed_items_spec.rb +54 -0
  51. data/spec/lib/pixi_client/requests/get_invoice_spec.rb +46 -0
  52. data/spec/lib/pixi_client/requests/get_item_info_spec.rb +48 -0
  53. data/spec/lib/pixi_client/requests/get_item_stock_bins_spec.rb +48 -0
  54. data/spec/lib/pixi_client/requests/get_items_info_spec.rb +60 -0
  55. data/spec/lib/pixi_client/requests/get_items_on_stock_bin_spec.rb +47 -0
  56. data/spec/lib/pixi_client/requests/get_items_stock_history_spec.rb +47 -0
  57. data/spec/lib/pixi_client/requests/get_order_comments_spec.rb +46 -0
  58. data/spec/lib/pixi_client/requests/get_order_header_spec.rb +47 -0
  59. data/spec/lib/pixi_client/requests/get_order_line_history_spec.rb +47 -0
  60. data/spec/lib/pixi_client/requests/get_order_lines_spec.rb +47 -0
  61. data/spec/lib/pixi_client/requests/get_order_nr_external_by_box_nr_spec.rb +51 -0
  62. data/spec/lib/pixi_client/requests/get_stock_by_bin_spec.rb +47 -0
  63. data/spec/lib/pixi_client/requests/get_stock_spec.rb +47 -0
  64. data/spec/lib/pixi_client/requests/get_unshippable_orders_spec.rb +47 -0
  65. data/spec/lib/pixi_client/requests/itemable_shared_examples.rb +52 -0
  66. data/spec/lib/pixi_client/requests/read_items_spec.rb +56 -0
  67. data/spec/lib/pixi_client/requests/read_orderlines_spec.rb +47 -0
  68. data/spec/lib/pixi_client/requests/set_stock_multiple_spec.rb +53 -0
  69. data/spec/lib/pixi_client/requests/shipping_get_picklist_details_spec.rb +47 -0
  70. data/spec/lib/pixi_client/requests/shipping_get_picklist_headers_spec.rb +47 -0
  71. data/spec/lib/pixi_client/response_parser_spec.rb +96 -0
  72. data/spec/lib/pixi_client/soap_request_spec.rb +30 -0
  73. data/spec/lib/pixi_client_spec.rb +19 -0
  74. data/spec/spec_helper.rb +11 -0
  75. data/spec/support/test_helpers.rb +136 -0
  76. metadata +306 -0
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe PixiClient::Requests::ShippingGetPicklistDetails do
4
+ let(:picklist_key) { 1 }
5
+ subject { PixiClient::Requests::ShippingGetPicklistDetails.new(picklist_key) }
6
+
7
+ before do
8
+ set_default_config
9
+ end
10
+
11
+ it { is_expected.to be_a_kind_of(PixiClient::Requests::Base) }
12
+
13
+ describe '#api_method' do
14
+ it 'should return :pixi_add_order_comment' do
15
+ expect(subject.api_method).to eq :pixi_shipping_get_picklist_details
16
+ end
17
+ end
18
+
19
+ describe 'call behaviour' do
20
+ let(:expected_response) { double(body: { pixi_shipping_get_picklist_details_response: { pixi_shipping_get_picklist_details_result: sql_row_set_response_mock } }) }
21
+ let(:double_client) { double }
22
+
23
+ before do
24
+ allow(subject).to receive(:client).and_return(double_client)
25
+ end
26
+
27
+ it 'should call the client with the appropriate parameters' do
28
+ expect(double_client).to receive(:call)
29
+ .with(:pixi_shipping_get_picklist_details, attributes: { xmlns: PixiClient.configuration.endpoint }, message: { 'PicklistKey' => picklist_key })
30
+ .and_return(expected_response)
31
+
32
+ subject.call
33
+ end
34
+
35
+ it 'should instanciate an instance of Response with the response body' do
36
+ expect(double_client).to receive(:call).and_return(expected_response)
37
+ expect(PixiClient::Response).to receive(:new).with(:pixi_shipping_get_picklist_details, expected_response.body)
38
+ subject.call
39
+ end
40
+
41
+ it 'should return an instance of Response' do
42
+ expect(double_client).to receive(:call).and_return(expected_response)
43
+ expect(subject.call).to be_an_instance_of(PixiClient::Response)
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe PixiClient::Requests::ShippingGetPicklistHeaders do
4
+ let(:location) { '001' }
5
+ subject { PixiClient::Requests::ShippingGetPicklistHeaders.new(location) }
6
+
7
+ before do
8
+ set_default_config
9
+ end
10
+
11
+ it { is_expected.to be_a_kind_of(PixiClient::Requests::Base) }
12
+
13
+ describe '#api_method' do
14
+ it 'should return :pixi_add_order_comment' do
15
+ expect(subject.api_method).to eq :pixi_shipping_get_picklist_headers
16
+ end
17
+ end
18
+
19
+ describe 'call behaviour' do
20
+ let(:expected_response) { double(body: { pixi_shipping_get_picklist_headers_response: { pixi_shipping_get_picklist_headers_result: sql_row_set_response_mock } }) }
21
+ let(:double_client) { double }
22
+
23
+ before do
24
+ allow(subject).to receive(:client).and_return(double_client)
25
+ end
26
+
27
+ it 'should call the client with the appropriate parameters' do
28
+ expect(double_client).to receive(:call)
29
+ .with(:pixi_shipping_get_picklist_headers, attributes: { xmlns: PixiClient.configuration.endpoint }, message: { 'LocID' => location })
30
+ .and_return(expected_response)
31
+
32
+ subject.call
33
+ end
34
+
35
+ it 'should instanciate an instance of Response with the response body' do
36
+ expect(double_client).to receive(:call).and_return(expected_response)
37
+ expect(PixiClient::Response).to receive(:new).with(:pixi_shipping_get_picklist_headers, expected_response.body)
38
+ subject.call
39
+ end
40
+
41
+ it 'should return an instance of Response' do
42
+ expect(double_client).to receive(:call).and_return(expected_response)
43
+ expect(subject.call).to be_an_instance_of(PixiClient::Response)
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,96 @@
1
+ require 'spec_helper'
2
+
3
+ describe PixiClient::ResponseParser do
4
+ let(:ts) { Time.at(Time.now.to_i) } # HACK: avoid microseconds strange behaviour
5
+ let(:response_body) { sql_row_set_response_mock(ts) }
6
+
7
+ describe 'parsing' do
8
+ subject(:parser) { PixiClient::ResponseParser.new(response_body) }
9
+
10
+ it { is_expected.to be_an_instance_of(PixiClient::ResponseParser) }
11
+
12
+ # examples modeled according to our mock (see spec/support/test_helpers)
13
+
14
+ describe 'rows building' do
15
+ before { parser.parse! }
16
+
17
+ let(:first_row) { parser.rows.first }
18
+ let(:second_row) { parser.rows.last }
19
+
20
+ it 'should create two rows' do
21
+ expect(parser.rows.length).to eq 2
22
+ end
23
+
24
+ it 'should set and convert integer attributes' do
25
+ expect(first_row.int_attr).to eq 1
26
+ expect(second_row.int_attr).to eq 2
27
+ end
28
+
29
+ it 'should set and convert datetime attributes' do
30
+ expect(first_row.datetime).to eq ts
31
+ expect(second_row.datetime).to eq ts
32
+ end
33
+
34
+ it 'should set and convert boolean attributes' do
35
+ expect(first_row.boolean).to eq true
36
+ expect(second_row.boolean).to eq false
37
+ end
38
+
39
+ it 'should set and convert string attributes' do
40
+ expect(first_row.string_attr).to eq 'string1'
41
+ expect(second_row.string_attr).to eq 'string2'
42
+ end
43
+
44
+ it 'should be able to process attributes with restriction description' do
45
+ expect(first_row.string_attr_with_restriction).to eq 'restricted_string_1'
46
+ expect(second_row.string_attr_with_restriction).to eq 'restricted_string_2'
47
+ end
48
+ end
49
+
50
+ describe 'sql messages building' do
51
+ before { parser.parse! }
52
+
53
+ context 'only one message' do
54
+ it 'should create an array of one message' do
55
+ expect(parser.sql_messages.length).to eq 1
56
+ end
57
+
58
+ describe 'messages attributes building' do
59
+ let(:sql_message) { parser.sql_messages.first }
60
+
61
+ it 'should set the message class' do
62
+ expect(sql_message.message_class).to eq '0'
63
+ end
64
+
65
+ it 'should set the message line number' do
66
+ expect(sql_message.line_number).to eq '103'
67
+ end
68
+
69
+ it 'should set the message text' do
70
+ expect(sql_message.message).to eq 'Warning: Null value is eliminated by an aggregate or other SET operation.'
71
+ end
72
+
73
+ it 'sholud set the message number' do
74
+ expect(sql_message.number).to eq '8153'
75
+ end
76
+
77
+ it 'should set the procedure' do
78
+ expect(sql_message.procedure).to eq 'pipiGetChangedItemStock'
79
+ end
80
+
81
+ it 'should set the message server' do
82
+ expect(sql_message.server).to eq 'RGPSQL4'
83
+ end
84
+
85
+ it 'should set the message source' do
86
+ expect(sql_message.source).to eq 'Microsoft-SQL/10.0'
87
+ end
88
+
89
+ it 'should set the message state' do
90
+ expect(sql_message.state).to eq '1'
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe PixiClient::Requests::Base do
4
+ let(:savon_client) { double('savon_client') }
5
+ subject { PixiClient::Requests::Base.new }
6
+
7
+ before do
8
+ allow(subject).to receive(:api_method).and_return(:fancy_soap_call)
9
+ allow(subject).to receive(:message).and_return({ a: 1 })
10
+ allow(subject).to receive(:client).and_return(savon_client)
11
+ end
12
+
13
+ describe '#call' do
14
+ it 'should call the savon client with the corresponding params' do
15
+ expect(savon_client).to(
16
+ receive(:call).
17
+ with(subject.api_method, attributes: { xmlns: PixiClient.configuration.endpoint }, message: subject.message).
18
+ and_return(OpenStruct.new(body: {}))
19
+ )
20
+ allow(PixiClient::Response).to receive(:new)
21
+ subject.call
22
+ end
23
+
24
+ it 'instantiates a PixiClient::Response instance' do
25
+ allow(savon_client).to receive(:call).and_return(OpenStruct.new(body: {}))
26
+ expect(PixiClient::Response).to receive(:new).with(subject.api_method, {})
27
+ response = subject.call
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe PixiClient do
4
+ before do
5
+ PixiClient.configure do |configuration|
6
+ configuration.endpoint = 'endpoint'
7
+ configuration.username = 'username'
8
+ configuration.password = 'random-password'
9
+ end
10
+ end
11
+
12
+ describe '::configuration' do
13
+ it 'returns the configuration' do
14
+ expect(PixiClient.configuration.endpoint).to eq 'endpoint'
15
+ expect(PixiClient.configuration.username).to eq 'username'
16
+ expect(PixiClient.configuration.password).to eq 'random-password'
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ require 'pry'
2
+ require 'pixi_client'
3
+
4
+ Dir[('./spec/support/**/*.rb')].each {|f| require f}
5
+
6
+ require File.join('lib', 'pixi_client', 'requests', 'itemable_shared_examples')
7
+
8
+ RSpec.configure do |config|
9
+ config.filter_run_excluding skip: true
10
+ config.include TestHelpers
11
+ end
@@ -0,0 +1,136 @@
1
+ require 'yaml'
2
+
3
+ module TestHelpers
4
+ def set_default_config
5
+ config_data = YAML.load_file(File.join(File.dirname(__FILE__), '../..', 'config', 'pixi.yml'))['test']
6
+
7
+ PixiClient.configure do |config|
8
+ config.endpoint = config_data['endpoint']
9
+ config.username = config_data['username']
10
+ config.password = config_data['password']
11
+ end
12
+ end
13
+
14
+ def set_stock_multiple_parameter_xml_mock
15
+ <<-EOS
16
+ <ITEMSTOCK>
17
+ <ITEM>
18
+ <EANUPC>12345</EANUPC>
19
+ <INVBINS>
20
+ <INVBIN>
21
+ <BINNAME>A</BINNAME>
22
+ <STOCK>5</STOCK>
23
+ </INVBIN>
24
+ </INVBINS>
25
+ </ITEM>
26
+ </ITEMSTOCK>
27
+ EOS
28
+ end
29
+
30
+ def sql_row_set_response_mock(ts = Time.now)
31
+ { :sql_message =>
32
+ {
33
+ :class => "0",
34
+ :line_number => "103",
35
+ :message => "Warning: Null value is eliminated by an aggregate or other SET operation.",
36
+ :number => "8153",
37
+ :procedure => "pipiGetChangedItemStock",
38
+ :server => "RGPSQL4",
39
+ :source => "Microsoft-SQL/10.0",
40
+ :state => "1",
41
+ :"@xsi:type" => "sqlmessage:SqlMessage"
42
+ },
43
+ :sql_row_set => {
44
+ :schema => [
45
+ {
46
+ :simple_type => [
47
+ {
48
+ :restriction => { :@base => "xsd:int" },
49
+ :@name => "int"
50
+ },
51
+ {
52
+ :restriction => { :@base => "xsd:string" },
53
+ :@name => "varchar"
54
+ },
55
+ {
56
+ :restriction => {
57
+ :pattern => { :@value => "((000[1-9])|(00[1-9][0-9])|(0[1-9][0-9]{2})|([1-9][0-9]{3}))-((0[1-9])|(1[012]))-((0[1-9])|([12][0-9])|(3[01]))T(([01][0-9])|(2[0-3]))(:[0-5][0-9]){2}(\\.[0-9]{2}[037])?" },
58
+ :min_inclusive => { :@value => "1753-01-01T00:00:00.000" },
59
+ :max_inclusive => { :@value=>"9999-12-31T23:59:59.997" },
60
+ :@base => "xsd:dateTime"
61
+ },
62
+ :@name => "datetime"
63
+ },
64
+ {
65
+ :restriction => { :@base => "xsd:boolean" },
66
+ :@name => "bit"
67
+ }
68
+ ],
69
+ :"@xmlns:xsd" => "http://www.w3.org/2001/XMLSchema",
70
+ :@target_namespace => "http://schemas.microsoft.com/sqlserver/2004/sqltypes"
71
+ },
72
+ {
73
+ :import => { :@namespace => "http://schemas.microsoft.com/sqlserver/2004/sqltypes" },
74
+ :element => {
75
+ :complex_type => {
76
+ :sequence => {
77
+ :element => {
78
+ :complex_type => {
79
+ :sequence => {
80
+ :element => [
81
+ { :@name => "int_attr", :@type => "sqltypes:int" },
82
+ { :@name => "DATETIME", :@type => "sqltypes:datetime", :@min_occurs => "0"},
83
+ { :@name => "boolean", :@type => "sqltypes:bit", :@min_occurs => "0"},
84
+ { :@name => "StringAttr", :@type => "sqltypes:varchar"},
85
+ {
86
+ :simple_type => {
87
+ :restriction => {
88
+ :max_length => { :@value => "13" },
89
+ :@base => "sqltypes:varchar",
90
+ :"@sqltypes:locale_id" => "1033",
91
+ :"@sqltypes:sql_compare_options" => "IgnoreCase IgnoreKanaType IgnoreWidth"
92
+ }
93
+ },
94
+ :@name => "StringAttrWithRestriction",
95
+ :@min_occurs=>"0"
96
+ },
97
+ ]
98
+ }
99
+ },
100
+ :@name => "row",
101
+ :@min_occurs => "0",
102
+ :@max_occurs => "unbounded"
103
+ }
104
+ }
105
+ },
106
+ :@name => "SqlRowSet1",
107
+ :"@msdata:is_data_set" => "true",
108
+ :"@msdata:data_set_namespace" => "urn:schemas-microsoft-com:sql:SqlDataSet",
109
+ :"@msdata:data_set_name" => "SqlDataSet"
110
+ },
111
+ :@xmlns=>"",
112
+ :"@xmlns:xsd" => "http://www.w3.org/2001/XMLSchema",
113
+ :"@xmlns:sqltypes" => "http://schemas.microsoft.com/sqlserver/2004/sqltypes",
114
+ :@target_namespace => "urn:schemas-microsoft-com:sql:SqlRowSet1",
115
+ :@element_form_default => "qualified"
116
+ }
117
+ ],
118
+ :diffgram => {
119
+ :sql_row_set1 => {
120
+ :row => [
121
+ { :int_attr => '1', :datetime => ts, :boolean => '1', :string_attr => 'string1', :string_attr_with_restriction => 'restricted_string_1' },
122
+ { :int_attr => '2', :datetime => ts, :boolean => '0', :string_attr => 'string2', :string_attr_with_restriction => 'restricted_string_2' }
123
+ ],
124
+ :@xmlns => "urn:schemas-microsoft-com:sql:SqlRowSet1"
125
+ },
126
+ :"@xmlns:diffgr" => "urn:schemas-microsoft-com:xml-diffgram-v1"
127
+ },
128
+ :"@xsi:type" => "sqlsoaptypes:SqlRowSet",
129
+ :"@msdata:use_data_set_schema_only" => "true",
130
+ :"@msdata:udt_column_value_wrapped" => "true"
131
+ },
132
+ :sql_result_code => "0",
133
+ :@xmlns => ""
134
+ }
135
+ end
136
+ end