gentle 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +64 -0
- data/Rakefile +9 -0
- data/gentle.gemspec +29 -0
- data/lib/gentle.rb +8 -0
- data/lib/gentle/blackboard.rb +44 -0
- data/lib/gentle/client.rb +92 -0
- data/lib/gentle/documents/document.rb +15 -0
- data/lib/gentle/documents/request/hash_converter.rb +55 -0
- data/lib/gentle/documents/request/shipment_order.rb +167 -0
- data/lib/gentle/documents/response/shipment_order_result.rb +56 -0
- data/lib/gentle/error_message.rb +19 -0
- data/lib/gentle/message.rb +43 -0
- data/lib/gentle/phase_1_set.rb +53 -0
- data/lib/gentle/queue.rb +40 -0
- data/lib/gentle/request.rb +11 -0
- data/lib/gentle/response.rb +11 -0
- data/lib/gentle/version.rb +3 -0
- data/spec/fixtures/credentials.yml +12 -0
- data/spec/fixtures/documents/responses/shipment_order_result.xml +23 -0
- data/spec/fixtures/messages/error_message.xml +10 -0
- data/spec/fixtures/messages/purchase_order_message.xml +11 -0
- data/spec/remote/blackboard_spec.rb +43 -0
- data/spec/remote/queue_spec.rb +64 -0
- data/spec/spec_helper.rb +323 -0
- data/spec/unit/blackboard_spec.rb +102 -0
- data/spec/unit/client_spec.rb +97 -0
- data/spec/unit/documents/document_spec.rb +44 -0
- data/spec/unit/documents/request/hash_converter_spec.rb +42 -0
- data/spec/unit/documents/request/shipment_order_spec.rb +164 -0
- data/spec/unit/documents/response/shipment_order_result_spec.rb +26 -0
- data/spec/unit/error_message_spec.rb +31 -0
- data/spec/unit/message_spec.rb +71 -0
- data/spec/unit/phase_1_set_spec.rb +76 -0
- data/spec/unit/queue_spec.rb +57 -0
- metadata +196 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'gentle/documents/response/shipment_order_result'
|
3
|
+
|
4
|
+
module Gentle
|
5
|
+
module Documents
|
6
|
+
module Response
|
7
|
+
describe "ShipmentOrderResult" do
|
8
|
+
include Fixtures
|
9
|
+
|
10
|
+
it "should be able to successfully parse a response document" do
|
11
|
+
document = load_response('shipment_order_result')
|
12
|
+
order_result = ShipmentOrderResult.new(io: document)
|
13
|
+
|
14
|
+
assert_equal 'Gentle', order_result.client_id
|
15
|
+
assert_equal 'Gentle', order_result.business_unit
|
16
|
+
assert_equal 1, order_result.carton_count
|
17
|
+
assert_equal Time.new(2009, 9, 1, 0, 0, 0).utc, order_result.date_shipped
|
18
|
+
|
19
|
+
assert_equal "40000000000", order_result.tracking_number
|
20
|
+
assert_equal "FIRST", order_result.service_level
|
21
|
+
assert_equal "USPS", order_result.carrier
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'gentle/error_message'
|
3
|
+
|
4
|
+
module Gentle
|
5
|
+
describe ErrorMessage do
|
6
|
+
include Fixtures
|
7
|
+
|
8
|
+
before do
|
9
|
+
@xml_content = load_message('error_message')
|
10
|
+
@message = ErrorMessage.new(xml: @xml_content)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should be able to generate an XML document" do
|
14
|
+
assert_equal normalize(@xml_content), normalize(@message.to_xml)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "extracts the shipment number from the error message" do
|
18
|
+
assert_equal "H123456789", @message.shipment_number
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns nil for shipment number if it cannot find it" do
|
22
|
+
message = ErrorMessage.new(xml: "<ErrorMessage ResultDescription='No shipping number'/>")
|
23
|
+
|
24
|
+
assert_nil message.shipment_number
|
25
|
+
end
|
26
|
+
|
27
|
+
def normalize(content)
|
28
|
+
content.delete("\n").squeeze(" ")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'gentle/message'
|
3
|
+
|
4
|
+
module Gentle
|
5
|
+
describe "Message" do
|
6
|
+
include Fixtures
|
7
|
+
before do
|
8
|
+
prepare_models
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should be possible to initialize a Message" do
|
12
|
+
message = Message.new(:document => @document, :client => @client)
|
13
|
+
assert_equal @document, message.document
|
14
|
+
assert_equal @client, message.client
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should raise an error if the document is missing when trying to generate XML" do
|
18
|
+
message = Message.new(:client => @client)
|
19
|
+
assert_raises Message::MissingDocumentError do
|
20
|
+
message.to_xml
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should raise an error if the client is missing when trying to generate XML" do
|
25
|
+
message = Message.new(:document => @document)
|
26
|
+
assert_raises Message::MissingClientError do
|
27
|
+
message.to_xml
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should be possible to create a Message with XML and query it for information" do
|
32
|
+
message = Message.new(:xml => load_message('purchase_order_message'))
|
33
|
+
|
34
|
+
assert_equal 'PurchaseOrder', message.document_type
|
35
|
+
assert_equal 'Gentle_PurchaseOrder_1234_20100927_132505124.xml', message.document_name
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should be able to generate an XML document" do
|
39
|
+
message = Message.new(:document => @document, :client => @client)
|
40
|
+
document = Nokogiri::XML::Document.parse(message.to_xml)
|
41
|
+
|
42
|
+
expected_namespaces = {'xmlns' => Message::NAMESPACE}
|
43
|
+
assert_equal expected_namespaces, document.collect_namespaces()
|
44
|
+
|
45
|
+
assert node = document.css('EventMessage').first
|
46
|
+
assert_equal @document.type, node['DocumentType']
|
47
|
+
assert_equal @document.filename, node['DocumentName']
|
48
|
+
assert_equal @document.warehouse, node['Warehouse']
|
49
|
+
assert_equal @document.date.utc.iso8601.to_s, node['MessageDate']
|
50
|
+
assert_equal @document.message_id, node['MessageId']
|
51
|
+
|
52
|
+
assert_equal @client.client_id, node['ClientId']
|
53
|
+
assert_equal @client.business_unit, node['BusinessUnit']
|
54
|
+
end
|
55
|
+
|
56
|
+
def prepare_models
|
57
|
+
@document = DocumentDouble.new(
|
58
|
+
type: "PurchaseOrder",
|
59
|
+
filename: "abracadabra.xml",
|
60
|
+
message_id: "alakazam",
|
61
|
+
warehouse: "Onett1",
|
62
|
+
date: Time.new(2013, 4, 1, 12, 30, 0)
|
63
|
+
)
|
64
|
+
|
65
|
+
@client = ClientDouble.new(
|
66
|
+
client_id: 'Gentle',
|
67
|
+
business_unit: 'Gentle'
|
68
|
+
)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'gentle/phase_1_set'
|
3
|
+
|
4
|
+
module Gentle
|
5
|
+
describe "Gentle::Phase1Set" do
|
6
|
+
|
7
|
+
it "checks if an item i a Phase 1" do
|
8
|
+
assert Phase1Set.match(line_item("GPS1-5"))
|
9
|
+
refute Phase1Set.match(line_item("non-phase-1"))
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns a collection of items included in the Phase 1 Set" do
|
13
|
+
phase1Set = Gentle::Phase1Set.new(line_item("GPS1-5", 2))
|
14
|
+
items = phase1Set.included_items
|
15
|
+
|
16
|
+
assert_equal 4, items.count
|
17
|
+
assert_includes_all items, [ milky_jelly, priming_moisturizer, balm_dotcom, skin_tint ]
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns the skin tint for Phase 1 Set - Shade: Light" do
|
21
|
+
phase1Set = Phase1Set.new(line_item("GPS1-5"))
|
22
|
+
|
23
|
+
assert_equal "GPST100 - 2", phase1Set.skin_tint.sku
|
24
|
+
end
|
25
|
+
|
26
|
+
it "returns the skin tint for Phase 1 Set - Shade: Medium" do
|
27
|
+
phase1Set = Phase1Set.new(line_item("GPS2-5"))
|
28
|
+
|
29
|
+
assert_equal "GPST200 - 2", phase1Set.skin_tint.sku
|
30
|
+
end
|
31
|
+
|
32
|
+
it "returns the skin tint for Phase 1 Set - Shade: Dark" do
|
33
|
+
phase1Set = Phase1Set.new(line_item("GPS3-5"))
|
34
|
+
|
35
|
+
assert_equal "GPST300", phase1Set.skin_tint.sku
|
36
|
+
end
|
37
|
+
|
38
|
+
it "returns the skin tint for Phase 1 Set - Shade: Deep" do
|
39
|
+
phase1Set = Phase1Set.new(line_item("GPS4-5"))
|
40
|
+
|
41
|
+
assert_equal "GPST400", phase1Set.skin_tint.sku
|
42
|
+
end
|
43
|
+
|
44
|
+
it "returns the skin tint for Phase 1 Set - Shade: Rich" do
|
45
|
+
phase1Set = Phase1Set.new(line_item("GPS5-5"))
|
46
|
+
|
47
|
+
assert_equal "GPST500", phase1Set.skin_tint.sku
|
48
|
+
end
|
49
|
+
|
50
|
+
def assert_includes_all(collection, expected)
|
51
|
+
collection.each { |item| assert_includes collection, item }
|
52
|
+
end
|
53
|
+
|
54
|
+
def line_item(sku = "GPS1-5", quantity = 1)
|
55
|
+
LineItemDouble.example(sku: sku, quantity: quantity)
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def milky_jelly
|
60
|
+
LineItem.new("GMJC100", 97, 2, 18.0)
|
61
|
+
end
|
62
|
+
|
63
|
+
def priming_moisturizer
|
64
|
+
LineItem.new("GPM100", 3, 2, 25.0)
|
65
|
+
end
|
66
|
+
|
67
|
+
def balm_dotcom
|
68
|
+
LineItem.new("GPM100", 3, 2, 25.0)
|
69
|
+
end
|
70
|
+
|
71
|
+
def skin_tint
|
72
|
+
LineItem.new("GPST100", 6, 2, 26.0)
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'gentle/queue'
|
3
|
+
require 'gentle/error_message'
|
4
|
+
|
5
|
+
module Gentle
|
6
|
+
describe "Queue" do
|
7
|
+
include Fixtures
|
8
|
+
before do
|
9
|
+
@sqs_queue = mock()
|
10
|
+
|
11
|
+
@client = mock()
|
12
|
+
@client.stubs(:to_quiet_queue).returns(@sqs_queue)
|
13
|
+
@client.stubs(:from_quiet_queue).returns(@sqs_queue)
|
14
|
+
@client.stubs(:quiet_inventory_queue).returns(@sqs_queue)
|
15
|
+
|
16
|
+
@message = mock()
|
17
|
+
|
18
|
+
@queue = Queue.new(@client)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should be able to write a message to a queue" do
|
22
|
+
@message.stubs(:to_xml).returns('hello world')
|
23
|
+
@sqs_queue.expects(:send_message).with('hello world')
|
24
|
+
|
25
|
+
@queue.send(@message)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should return a message when receiving from a queue" do
|
29
|
+
@message.stubs(:body).returns(load_message('purchase_order_message'))
|
30
|
+
@sqs_queue.expects(:receive_message).yields(@message)
|
31
|
+
|
32
|
+
received_message = @queue.receive
|
33
|
+
assert_equal 'PurchaseOrder', received_message.document_type
|
34
|
+
assert_equal 'Gentle_PurchaseOrder_1234_20100927_132505124.xml', received_message.document_name
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should return a message when receiving even if the queue did not return anything" do
|
38
|
+
@sqs_queue.expects(:receive_message)
|
39
|
+
|
40
|
+
received_message = @queue.receive
|
41
|
+
assert_equal false, received_message.nil?
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should return an error message when receiving an error from a queue" do
|
45
|
+
@message.stubs(:body).returns(load_message('error_message'))
|
46
|
+
@sqs_queue.expects(:receive_message).yields(@message)
|
47
|
+
|
48
|
+
received_message = @queue.receive
|
49
|
+
assert_instance_of Gentle::ErrorMessage, received_message
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should be possible to get an approximate number of pending messages" do
|
53
|
+
@sqs_queue.expects(:approximate_number_of_messages).returns(10)
|
54
|
+
assert_equal 10, @queue.approximate_pending_messages
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,196 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gentle
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- DynamoMTL
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "<"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "<"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 5.0.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 5.0.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: mocha
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: API Client for Quiet Logistics Services
|
112
|
+
email:
|
113
|
+
- ''
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- Gemfile
|
120
|
+
- LICENSE.txt
|
121
|
+
- README.md
|
122
|
+
- Rakefile
|
123
|
+
- gentle.gemspec
|
124
|
+
- lib/gentle.rb
|
125
|
+
- lib/gentle/blackboard.rb
|
126
|
+
- lib/gentle/client.rb
|
127
|
+
- lib/gentle/documents/document.rb
|
128
|
+
- lib/gentle/documents/request/hash_converter.rb
|
129
|
+
- lib/gentle/documents/request/shipment_order.rb
|
130
|
+
- lib/gentle/documents/response/shipment_order_result.rb
|
131
|
+
- lib/gentle/error_message.rb
|
132
|
+
- lib/gentle/message.rb
|
133
|
+
- lib/gentle/phase_1_set.rb
|
134
|
+
- lib/gentle/queue.rb
|
135
|
+
- lib/gentle/request.rb
|
136
|
+
- lib/gentle/response.rb
|
137
|
+
- lib/gentle/version.rb
|
138
|
+
- spec/fixtures/credentials.yml
|
139
|
+
- spec/fixtures/documents/responses/shipment_order_result.xml
|
140
|
+
- spec/fixtures/messages/error_message.xml
|
141
|
+
- spec/fixtures/messages/purchase_order_message.xml
|
142
|
+
- spec/remote/blackboard_spec.rb
|
143
|
+
- spec/remote/queue_spec.rb
|
144
|
+
- spec/spec_helper.rb
|
145
|
+
- spec/unit/blackboard_spec.rb
|
146
|
+
- spec/unit/client_spec.rb
|
147
|
+
- spec/unit/documents/document_spec.rb
|
148
|
+
- spec/unit/documents/request/hash_converter_spec.rb
|
149
|
+
- spec/unit/documents/request/shipment_order_spec.rb
|
150
|
+
- spec/unit/documents/response/shipment_order_result_spec.rb
|
151
|
+
- spec/unit/error_message_spec.rb
|
152
|
+
- spec/unit/message_spec.rb
|
153
|
+
- spec/unit/phase_1_set_spec.rb
|
154
|
+
- spec/unit/queue_spec.rb
|
155
|
+
homepage: http://github.com/DynamoMTL/qls
|
156
|
+
licenses:
|
157
|
+
- MIT
|
158
|
+
metadata: {}
|
159
|
+
post_install_message:
|
160
|
+
rdoc_options: []
|
161
|
+
require_paths:
|
162
|
+
- lib
|
163
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - ">="
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '0'
|
168
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0'
|
173
|
+
requirements: []
|
174
|
+
rubyforge_project:
|
175
|
+
rubygems_version: 2.4.5.1
|
176
|
+
signing_key:
|
177
|
+
specification_version: 4
|
178
|
+
summary: Integrates with QL Blackboard and work Queue
|
179
|
+
test_files:
|
180
|
+
- spec/fixtures/credentials.yml
|
181
|
+
- spec/fixtures/documents/responses/shipment_order_result.xml
|
182
|
+
- spec/fixtures/messages/error_message.xml
|
183
|
+
- spec/fixtures/messages/purchase_order_message.xml
|
184
|
+
- spec/remote/blackboard_spec.rb
|
185
|
+
- spec/remote/queue_spec.rb
|
186
|
+
- spec/spec_helper.rb
|
187
|
+
- spec/unit/blackboard_spec.rb
|
188
|
+
- spec/unit/client_spec.rb
|
189
|
+
- spec/unit/documents/document_spec.rb
|
190
|
+
- spec/unit/documents/request/hash_converter_spec.rb
|
191
|
+
- spec/unit/documents/request/shipment_order_spec.rb
|
192
|
+
- spec/unit/documents/response/shipment_order_result_spec.rb
|
193
|
+
- spec/unit/error_message_spec.rb
|
194
|
+
- spec/unit/message_spec.rb
|
195
|
+
- spec/unit/phase_1_set_spec.rb
|
196
|
+
- spec/unit/queue_spec.rb
|