fastshop_catalog 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +20 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +52 -0
- data/LICENSE.txt +22 -0
- data/README.md +69 -0
- data/Rakefile +5 -0
- data/fastshop_catalog.gemspec +25 -0
- data/lib/fastshop_catalog/base_entity.rb +30 -0
- data/lib/fastshop_catalog/base_service.rb +71 -0
- data/lib/fastshop_catalog/catalog_service.rb +17 -0
- data/lib/fastshop_catalog/check_availability_service.rb +23 -0
- data/lib/fastshop_catalog/crypto.rb +41 -0
- data/lib/fastshop_catalog/entity/address.rb +30 -0
- data/lib/fastshop_catalog/entity/business_unity.rb +9 -0
- data/lib/fastshop_catalog/entity/order.rb +12 -0
- data/lib/fastshop_catalog/entity/order_item.rb +7 -0
- data/lib/fastshop_catalog/entity/participant.rb +15 -0
- data/lib/fastshop_catalog/external_dne_service.rb +17 -0
- data/lib/fastshop_catalog/order_placement_service.rb +20 -0
- data/lib/fastshop_catalog/order_status_service.rb +18 -0
- data/lib/fastshop_catalog/participant_service.rb +20 -0
- data/lib/fastshop_catalog/product_service.rb +17 -0
- data/lib/fastshop_catalog/service_exception.rb +11 -0
- data/lib/fastshop_catalog/time.rb +15 -0
- data/lib/fastshop_catalog/version.rb +3 -0
- data/lib/fastshop_catalog.rb +20 -0
- data/password_util.rb +48 -0
- data/spec/.DS_Store +0 -0
- data/spec/fastshop_catalog/.DS_Store +0 -0
- data/spec/fastshop_catalog/base_service_spec.rb +44 -0
- data/spec/fastshop_catalog/catalog_service_spec.rb +43 -0
- data/spec/fastshop_catalog/check_availability_service_spec.rb +44 -0
- data/spec/fastshop_catalog/external_dne_service_spec.rb +60 -0
- data/spec/fastshop_catalog/integration/catalog_service_integration_spec.rb +15 -0
- data/spec/fastshop_catalog/integration/check_availability_service_integration_spec.rb +30 -0
- data/spec/fastshop_catalog/integration/external_dne_service_integration_spec.rb +12 -0
- data/spec/fastshop_catalog/integration/order_placement_service_integration_spec.rb +41 -0
- data/spec/fastshop_catalog/integration/order_status_service_integration_spec.rb +31 -0
- data/spec/fastshop_catalog/integration/participant_service_integration_spec.rb +34 -0
- data/spec/fastshop_catalog/integration/product_service_integration_spec.rb +23 -0
- data/spec/fastshop_catalog/order_placement_service_spec.rb +60 -0
- data/spec/fastshop_catalog/order_status_service_spec.rb +62 -0
- data/spec/fastshop_catalog/participant_factory.rb +40 -0
- data/spec/fastshop_catalog/participant_service_spec.rb +60 -0
- data/spec/fastshop_catalog/product_service_spec.rb +60 -0
- data/spec/fixtures/catalog_service_successful_response.xml +11 -0
- data/spec/fixtures/catalog_service_wrong_contract_response.xml +10 -0
- data/spec/fixtures/check_availability_not_available_response.xml +11 -0
- data/spec/fixtures/external_dne_service_successful_response.xml +11 -0
- data/spec/fixtures/external_dne_service_wrong_contract_response.xml +11 -0
- data/spec/fixtures/external_dne_service_wrong_zip_response.xml +11 -0
- data/spec/fixtures/order_placement_cart_not_identified.xml +11 -0
- data/spec/fixtures/order_placement_successful_delivery_payload.json +4 -0
- data/spec/fixtures/order_placement_successful_payload.json +1 -0
- data/spec/fixtures/order_status_service_order_not_found_response.xml +11 -0
- data/spec/fixtures/order_status_service_successful_response.xml +11 -0
- data/spec/fixtures/participant_service_successful_response.xml +11 -0
- data/spec/fixtures/participant_service_successful_token_response.xml +11 -0
- data/spec/fixtures/participant_successful_payload.json +1 -0
- data/spec/fixtures/product_service_successful_response.xml +11 -0
- data/spec/fixtures/product_service_wrong_contract_response.xml +11 -0
- data/spec/fixtures/product_service_wrong_sku_response.xml +11 -0
- data/spec/spec_helper.rb +10 -0
- data/wsdls/catalog.wsdl +49 -0
- data/wsdls/participante.wsdl +52 -0
- metadata +202 -0
data/password_util.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#requires chilkat http://www.example-code.com/ruby/default.asp
|
2
|
+
class PasswordUtil
|
3
|
+
|
4
|
+
MIN_KEY_SIZE = 128
|
5
|
+
|
6
|
+
# for the example, salt = "xW\x8EZ]c\xCB\x06", password = "password"
|
7
|
+
# the salt in hexa is "78578E5A5D63CB06"
|
8
|
+
|
9
|
+
def self.derive(password, salt)
|
10
|
+
require 'chilkat'
|
11
|
+
|
12
|
+
crypt = Chilkat::CkCrypt2.new()
|
13
|
+
|
14
|
+
success = crypt.UnlockComponent(ENV['chilkat_license'] || "Anything for 30-day trial")
|
15
|
+
if (success != true)
|
16
|
+
print crypt.lastErrorText() + "\n"
|
17
|
+
exit
|
18
|
+
end
|
19
|
+
|
20
|
+
# http://www.di-mgt.com.au/cryptoKDFs.html#examplespbkdf
|
21
|
+
|
22
|
+
pwCharset = "ascii"
|
23
|
+
# Hash algorithms may be: sha1, md2, md5, etc.
|
24
|
+
hashAlg = "sha1"
|
25
|
+
# The salt should be 8 bytes:
|
26
|
+
saltHex = text_to_hexa(salt)
|
27
|
+
iterationCount = 100
|
28
|
+
# Derive a 128-bit key from the password.
|
29
|
+
outputBitLen = 128
|
30
|
+
enc = "hex"
|
31
|
+
|
32
|
+
hexKey = crypt.pbkdf1(password,pwCharset,hashAlg,saltHex,iterationCount,outputBitLen,enc)
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.text_to_hexa(value)
|
37
|
+
value.bytes.map{|x| x.to_s(16).upcase}.map{|x| (x.length < 2) ? '0'+x : x}.join('')
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.fill_key(key)
|
41
|
+
(MIN_KEY_SIZE/8 - key.length).times{ key << '*'} && key
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.derive_fastshop_default(key='Fast', salt='')
|
45
|
+
derive(fill_key(key), salt)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
data/spec/.DS_Store
ADDED
Binary file
|
Binary file
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe FastshopCatalog::BaseService do
|
4
|
+
|
5
|
+
describe "camelize" do
|
6
|
+
|
7
|
+
it 'should convert the underscore string to camel' do
|
8
|
+
expect(FastshopCatalog::BaseService.camelize('some_dull_text')).to eq('SomeDullText')
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "initialization" do
|
14
|
+
|
15
|
+
let(:service) do
|
16
|
+
class TempService < FastshopCatalog::BaseService
|
17
|
+
def initialize
|
18
|
+
@service = 'SomePath/some_service'
|
19
|
+
@interface = 'ISomeInterface'
|
20
|
+
@soap_method = :some_method
|
21
|
+
@return_key = 'SomeName'
|
22
|
+
super
|
23
|
+
end
|
24
|
+
end
|
25
|
+
TempService.new
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should return the correct service_url' do
|
29
|
+
expect(service.service_url).to eq('http://www.fastincentivos.com.br/SomePath/some_service')
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should return the correct service_url if base_url changed' do
|
33
|
+
FastshopCatalog::BaseService.base_url = 'http://yourserverhere.com'
|
34
|
+
expect(service.service_url).to eq('http://yourserverhere.com/SomePath/some_service')
|
35
|
+
FastshopCatalog::BaseService.base_url = FastshopCatalog::BaseService::DEFAULT_BASE_URL
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should return the correct action' do
|
39
|
+
expect(service.action).to eq('ISomeInterface/SomeMethod')
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe FastshopCatalog::CatalogService do
|
4
|
+
|
5
|
+
include Savon::SpecHelper
|
6
|
+
before(:all) { savon.mock! }
|
7
|
+
after(:all) { savon.unmock! }
|
8
|
+
|
9
|
+
let(:contract_number) do
|
10
|
+
"1234567890"
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:service) do
|
14
|
+
service = FastshopCatalog::CatalogService.new
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:fixture) do
|
18
|
+
File.read("spec/fixtures/catalog_service_successful_response.xml")
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:fixture_wrong_contract) do
|
22
|
+
File.read("spec/fixtures/catalog_service_wrong_contract_response.xml")
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "search" do
|
26
|
+
|
27
|
+
it "should return the list with the expected size" do
|
28
|
+
savon.expects(:busca_catalogo).with(:message => {'tns:contrato' => contract_number}).returns(fixture)
|
29
|
+
result = service.search(contract_number)
|
30
|
+
expect(result.length).to eq(866)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return wrong contract exception" do
|
34
|
+
savon.expects(:busca_catalogo).with(:message => {'tns:contrato' => 'lixo'}).returns(fixture_wrong_contract)
|
35
|
+
expect{service.search('lixo')}.to raise_error(FastshopCatalog::ServiceException) do |e|
|
36
|
+
expect(e.code).to eq(2)
|
37
|
+
expect(e.description).to eq('Contrato invalido')
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe FastshopCatalog::CheckAvailabilityService do
|
5
|
+
|
6
|
+
include Savon::SpecHelper
|
7
|
+
before(:all) { savon.mock! }
|
8
|
+
after(:all) { savon.unmock! }
|
9
|
+
|
10
|
+
let(:order) do
|
11
|
+
order = FastshopCatalog::Entity::Order.new
|
12
|
+
order.contract_code = '1234567890'
|
13
|
+
order.zip_code = '02029001'
|
14
|
+
order.document = '73978898160'
|
15
|
+
order.number = '1560'
|
16
|
+
order.total_amount = "69.00"
|
17
|
+
order_item = FastshopCatalog::Entity::OrderItem.new
|
18
|
+
order_item.sku = 'IVIEP314RED'
|
19
|
+
order_item.quantity = 1
|
20
|
+
order_item.price = "69.00"
|
21
|
+
order.items = [order_item]
|
22
|
+
order
|
23
|
+
end
|
24
|
+
|
25
|
+
let(:order_fixture) do
|
26
|
+
{"tns:dadosPedido"=>{"fas:Cep"=>"02029001", "fas:Contrato"=>"1234567890", "fas:Cpf"=>"73978898160", "fas:Itens"=>[{"fas:PedidoItensEntity"=>{"tns:Quantidade"=>1, "tns:Sku"=>"IVIEP314RED", "tns:ValorUnitario"=>"69.00"}}], "fas:Numero"=>"1560", "fas:ValorTotal"=>"69.00"}}
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:fixture) do
|
30
|
+
File.read("spec/fixtures/check_availability_not_available_response.xml")
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "check" do
|
34
|
+
it "should check that the order is not available" do
|
35
|
+
|
36
|
+
savon.expects(:retorna_dados).with(:message => order_fixture).returns(fixture)
|
37
|
+
service = FastshopCatalog::CheckAvailabilityService.new
|
38
|
+
expect{service.check(order)}.to raise_error(FastshopCatalog::ServiceException) do |e|
|
39
|
+
expect(e.code).to eq(36)
|
40
|
+
expect(e.description).to eq('Pedido indisponível')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe FastshopCatalog::ExternalDneService do
|
5
|
+
|
6
|
+
include Savon::SpecHelper
|
7
|
+
before(:all) { savon.mock! }
|
8
|
+
after(:all) { savon.unmock! }
|
9
|
+
|
10
|
+
let(:service) do
|
11
|
+
FastshopCatalog::ExternalDneService.new
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:contract_number) do
|
15
|
+
"1234567890"
|
16
|
+
end
|
17
|
+
let(:zip_code) do
|
18
|
+
'04562030'
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:fixture) do
|
22
|
+
File.read("spec/fixtures/external_dne_service_successful_response.xml")
|
23
|
+
end
|
24
|
+
|
25
|
+
let(:fixture_wrong_contract) do
|
26
|
+
File.read("spec/fixtures/external_dne_service_wrong_contract_response.xml")
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:fixture_wrong_zip) do
|
30
|
+
File.read("spec/fixtures/external_dne_service_wrong_zip_response.xml")
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "query" do
|
34
|
+
|
35
|
+
it "should return the list with the expected size" do
|
36
|
+
savon.expects(:consultar).with(:message => {'tns:contrato' => contract_number, 'tns:cep' => zip_code }).returns(fixture)
|
37
|
+
result = service.query(contract_number, zip_code)
|
38
|
+
expect(result['Cidade']).to eq('SAO PAULO')
|
39
|
+
expect(result['Endereco']).to eq('ARANDU')
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should return wrong contract exception" do
|
43
|
+
savon.expects(:consultar).with(:message => {'tns:contrato' => 'lixo', 'tns:cep' => zip_code}).returns(fixture_wrong_contract)
|
44
|
+
expect{service.query('lixo', zip_code)}.to raise_error(FastshopCatalog::ServiceException) do |e|
|
45
|
+
expect(e.code).to eq(2)
|
46
|
+
expect(e.description).to eq('Contrato invalido')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should return invalid zip exception" do
|
51
|
+
savon.expects(:consultar).with(:message => {'tns:contrato' => 'lixo', 'tns:cep' => '1111'}).returns(fixture_wrong_zip)
|
52
|
+
expect{service.query('lixo', '1111')}.to raise_error(FastshopCatalog::ServiceException) do |e|
|
53
|
+
expect(e.code).to eq(9)
|
54
|
+
expect(e.description).to eq('CEP invalido')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe FastshopCatalog::CatalogService do
|
4
|
+
|
5
|
+
let(:contract_number) do
|
6
|
+
"1234567890"
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "search integration", :integration => true do
|
10
|
+
it "should return the catalog for the contract number" do
|
11
|
+
service = FastshopCatalog::CatalogService.new
|
12
|
+
result = service.search(contract_number)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "spec_helper"
|
3
|
+
|
4
|
+
describe FastshopCatalog::CheckAvailabilityService do
|
5
|
+
|
6
|
+
let(:order) do
|
7
|
+
order = FastshopCatalog::Entity::Order.new
|
8
|
+
order.contract_code = '1234567890'
|
9
|
+
order.zip_code = '02029001'
|
10
|
+
order.document = '73978898160'
|
11
|
+
order.number = '1560'
|
12
|
+
order.total_amount = "69.00"
|
13
|
+
order_item = FastshopCatalog::Entity::OrderItem.new
|
14
|
+
order_item.sku = 'IVIEP314RED'
|
15
|
+
order_item.quantity = 1
|
16
|
+
order_item.price = "69.00"
|
17
|
+
order.items = [order_item]
|
18
|
+
order
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "check integration", :integration => true do
|
22
|
+
it "should check that the order is not available" do
|
23
|
+
service = FastshopCatalog::CheckAvailabilityService.new
|
24
|
+
expect{service.check(order)}.to raise_error(FastshopCatalog::ServiceException) do |e|
|
25
|
+
expect(e.code).to eq(36)
|
26
|
+
expect(e.description).to eq('Pedido indisponível')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe FastshopCatalog::ExternalDneService do
|
4
|
+
|
5
|
+
describe "query integration", :integration => true do
|
6
|
+
it "should return the address information for the contract number and zip_code" do
|
7
|
+
service = FastshopCatalog::ExternalDneService.new
|
8
|
+
result = service.query('1234567890', '04562030')
|
9
|
+
expect(result['Cidade']).to eq('SAO PAULO')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe FastshopCatalog::OrderPlacementService do
|
4
|
+
|
5
|
+
let(:contract_number) do
|
6
|
+
"1234567890"
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:order) do
|
10
|
+
order = FastshopCatalog::Entity::Order.new
|
11
|
+
order.contract_code = '1234567890'
|
12
|
+
order.zip_code = '02029001'
|
13
|
+
order.document = '73978898160'
|
14
|
+
order.number = '1560'
|
15
|
+
order.total_amount = "69.00"
|
16
|
+
order.delivery_type = "P"
|
17
|
+
order.partner_order_number = "1234568119"
|
18
|
+
order_item = FastshopCatalog::Entity::OrderItem.new
|
19
|
+
order_item.sku = 'IVIEP314RED'
|
20
|
+
order_item.quantity = 1
|
21
|
+
order_item.price = "69.00"
|
22
|
+
order.items = [order_item]
|
23
|
+
order
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:service) do
|
27
|
+
service = FastshopCatalog::OrderPlacementService.new
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "place_order integration", :integration => true do
|
31
|
+
|
32
|
+
it "should raise cart not identified" do
|
33
|
+
expect{service.place_order(order)}.to raise_error(FastshopCatalog::ServiceException) do |e|
|
34
|
+
expect(e.code).to eq(37)
|
35
|
+
expect(e.description).to eq('Carrinho nao identificado no sistema')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe FastshopCatalog::ProductService do
|
4
|
+
|
5
|
+
let(:contract_number) do
|
6
|
+
"1234567890"
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:order_number) do
|
10
|
+
"3353496"
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:partner_order_number) do
|
14
|
+
"12121"
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:sku) do
|
18
|
+
'IVIEP314RED'
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "check integration", :integration => true do
|
22
|
+
|
23
|
+
it "should return the list with the order items" do
|
24
|
+
service = FastshopCatalog::OrderStatusService.new
|
25
|
+
result = service.check(contract_number, order_number, partner_order_number)
|
26
|
+
expect(result.first['Sku']).to eq(sku)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe FastshopCatalog::OrderPlacementService do
|
4
|
+
|
5
|
+
let(:contract_number) do
|
6
|
+
"1234567890"
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:participant) do
|
10
|
+
ParticipantFactory.build
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:service) do
|
14
|
+
service = FastshopCatalog::ParticipantService.new
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "insert integration", :integration => true do
|
18
|
+
|
19
|
+
it "should insert the participant and return a null token" do
|
20
|
+
result = service.insert(participant)
|
21
|
+
expect(result).to be_nil
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should raise incompatible address exception" do
|
25
|
+
participant.address.neighborhood = 'Moema'
|
26
|
+
expect{service.insert(participant)}.to raise_error(FastshopCatalog::ServiceException) do |e|
|
27
|
+
expect(e.code).to eq(2)
|
28
|
+
expect(e.description).to eq('Contrato invalido')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe FastshopCatalog::ProductService do
|
4
|
+
|
5
|
+
let(:contract_number) do
|
6
|
+
"1234567890"
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:sku) do
|
10
|
+
"A5IMT237"
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "search integration", :integration => true do
|
14
|
+
|
15
|
+
it "should return the product for the contract number and sku" do
|
16
|
+
service = FastshopCatalog::ProductService.new
|
17
|
+
result = service.search(contract_number, sku)
|
18
|
+
expect(result['ProdutoSkus'].first['Sku']).to eq(sku)
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe FastshopCatalog::OrderPlacementService do
|
4
|
+
|
5
|
+
include Savon::SpecHelper
|
6
|
+
before(:all) { savon.mock! }
|
7
|
+
after(:all) { savon.unmock! }
|
8
|
+
|
9
|
+
let(:contract_number) do
|
10
|
+
"1234567890"
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:order) do
|
14
|
+
order = FastshopCatalog::Entity::Order.new
|
15
|
+
order.contract_code = '1234567890'
|
16
|
+
order.zip_code = '02029001'
|
17
|
+
order.document = '73978898160'
|
18
|
+
order.number = '1560'
|
19
|
+
order.total_amount = "69.00"
|
20
|
+
order.delivery_type = "P"
|
21
|
+
order.partner_order_number = "1234568119"
|
22
|
+
order_item = FastshopCatalog::Entity::OrderItem.new
|
23
|
+
order_item.sku = 'IVIEP314RED'
|
24
|
+
order_item.quantity = 1
|
25
|
+
order_item.price = "69.00"
|
26
|
+
order.items = [order_item]
|
27
|
+
order
|
28
|
+
end
|
29
|
+
|
30
|
+
let(:service) do
|
31
|
+
service = FastshopCatalog::OrderPlacementService.new
|
32
|
+
end
|
33
|
+
|
34
|
+
let(:order_attr) do
|
35
|
+
File.read("spec/fixtures/order_placement_successful_payload.json")
|
36
|
+
end
|
37
|
+
|
38
|
+
let(:fixture_cart_not_identified) do
|
39
|
+
File.read("spec/fixtures/order_placement_cart_not_identified.xml")
|
40
|
+
end
|
41
|
+
|
42
|
+
let(:fixture_wrong_contract) do
|
43
|
+
File.read("spec/fixtures/catalog_service_wrong_contract_response.xml")
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "place_order" do
|
47
|
+
|
48
|
+
it "should raise cart not identified" do
|
49
|
+
encrypted_payload = service.encrypt(order_attr)
|
50
|
+
savon.expects(:incluir_pedido).with(:message => {'tns:contrato' => contract_number,
|
51
|
+
'tns:entrada' => encrypted_payload, 'tns:salt' => ''}).returns(fixture_cart_not_identified)
|
52
|
+
expect{service.place_order(order)}.to raise_error(FastshopCatalog::ServiceException) do |e|
|
53
|
+
expect(e.code).to eq(37)
|
54
|
+
expect(e.description).to eq('Carrinho nao identificado no sistema')
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe FastshopCatalog::OrderStatusService do
|
4
|
+
|
5
|
+
include Savon::SpecHelper
|
6
|
+
before(:all) { savon.mock! }
|
7
|
+
after(:all) { savon.unmock! }
|
8
|
+
|
9
|
+
let(:contract_number) do
|
10
|
+
"1234567890"
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:order_number) do
|
14
|
+
"3353496"
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:partner_order_number) do
|
18
|
+
"12121"
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:service) do
|
22
|
+
service = FastshopCatalog::OrderStatusService.new
|
23
|
+
end
|
24
|
+
|
25
|
+
let(:fixture) do
|
26
|
+
File.read("spec/fixtures/order_status_service_successful_response.xml")
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:sku) do
|
30
|
+
'IVIEP314RED'
|
31
|
+
end
|
32
|
+
|
33
|
+
let(:fixture_order_not_found) do
|
34
|
+
File.read("spec/fixtures/order_status_service_order_not_found_response.xml")
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "check" do
|
38
|
+
|
39
|
+
it "should return the list with the order items" do
|
40
|
+
savon.expects(:retorna_dados).with(:message => {'tns:contrato' => contract_number,
|
41
|
+
'tns:numeroPedidoFast' => order_number,
|
42
|
+
'tns:numeroPedidoParceiro' => partner_order_number}).returns(fixture)
|
43
|
+
result = service.check(contract_number, order_number, partner_order_number)
|
44
|
+
expect(result.length).to eq(1)
|
45
|
+
expect(result.first['Sku']).to eq(sku)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should return raise order not found" do
|
49
|
+
savon.expects(:retorna_dados).with(:message => {'tns:contrato' => contract_number,
|
50
|
+
'tns:numeroPedidoFast' => 1111,
|
51
|
+
'tns:numeroPedidoParceiro' => partner_order_number}).returns(fixture_order_not_found)
|
52
|
+
expect do
|
53
|
+
service.check(contract_number, 1111, partner_order_number)
|
54
|
+
end.to raise_error(FastshopCatalog::ServiceException) do |e|
|
55
|
+
expect(e.code).to eq(21)
|
56
|
+
expect(e.description).to eq('Pedido nao encontrado')
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class ParticipantFactory
|
2
|
+
def self.build
|
3
|
+
participant = FastshopCatalog::Entity::Participant.new
|
4
|
+
participant.contract_code = '1234567890'
|
5
|
+
participant.document = '73978898160'
|
6
|
+
participant.registry = '11111111'
|
7
|
+
participant.name = 'TESTE PARTICIPANTE'
|
8
|
+
#year, month, day
|
9
|
+
participant.birth_date = FastshopCatalog::Time.new(1980,1,1)
|
10
|
+
participant.gender = 'M'
|
11
|
+
participant.category = 'Vendedor'
|
12
|
+
participant.home_phone_prefix = '11'
|
13
|
+
participant.home_phone = '11111111'
|
14
|
+
participant.work_phone_prefix = '11'
|
15
|
+
participant.work_phone = '11111111'
|
16
|
+
participant.mobile_phone_prefix = '11'
|
17
|
+
participant.mobile_phone = '11111111'
|
18
|
+
participant.email = 'teste@teste.com.br'
|
19
|
+
participant.status = 'A'
|
20
|
+
participant.operation_type = '0'
|
21
|
+
participant.address = FastshopCatalog::Entity::Address.new
|
22
|
+
participant.address.description = 'FASTSHOP'
|
23
|
+
participant.address.address_type = 'R'
|
24
|
+
participant.address.address = 'ARANDU'
|
25
|
+
participant.address.number = '1560'
|
26
|
+
participant.address.complement = ''
|
27
|
+
participant.address.neighborhood = 'BROOKLIN PAULISTA'
|
28
|
+
participant.address.city = 'SAO PAULO'
|
29
|
+
participant.address.state = 'SP'
|
30
|
+
participant.address.zip_code = '04562030'
|
31
|
+
# Don't use directly the setters, use this helper, home_type which will set
|
32
|
+
# both home_type_id and home_type_description.
|
33
|
+
participant.address.home_type = FastshopCatalog::Entity::Address::HOME_TYPE_COMPANY
|
34
|
+
participant.business_unity = FastshopCatalog::Entity::BusinessUnity.new
|
35
|
+
participant.business_unity.company_document = '03792703000198'
|
36
|
+
participant.business_unity.company_name = 'TESTE UNID LTD'
|
37
|
+
participant.business_unity.trading_name = 'TESTE UNI'
|
38
|
+
participant
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "fastshop_catalog/participant_factory"
|
3
|
+
|
4
|
+
describe FastshopCatalog::ParticipantService do
|
5
|
+
|
6
|
+
include Savon::SpecHelper
|
7
|
+
before(:all) { savon.mock! }
|
8
|
+
after(:all) { savon.unmock! }
|
9
|
+
|
10
|
+
let(:contract_number) do
|
11
|
+
"1234567890"
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:participant) do
|
15
|
+
ParticipantFactory.build
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:service) do
|
19
|
+
service = FastshopCatalog::ParticipantService.new
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:participant_attr) do
|
23
|
+
File.read("spec/fixtures/participant_successful_payload.json")
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:fixture) do
|
27
|
+
File.read("spec/fixtures/participant_service_successful_response.xml")
|
28
|
+
end
|
29
|
+
|
30
|
+
let(:fixture_token) do
|
31
|
+
File.read("spec/fixtures/participant_service_successful_token_response.xml")
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "insert" do
|
35
|
+
|
36
|
+
it "should insert the participant and return a null token" do
|
37
|
+
participant_attr.gsub!("315543600000-10800", time_helper(participant.birth_date))
|
38
|
+
encrypted_payload = service.encrypt(participant_attr)
|
39
|
+
savon.expects(:cadastrar_participante).with(:message => {'tns:contrato' => contract_number,
|
40
|
+
'tns:entrada' => encrypted_payload, 'tns:salt' => ''}).returns(fixture)
|
41
|
+
result = service.insert(participant)
|
42
|
+
expect(result).to be_nil
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should insert the participant and return a non null token" do
|
46
|
+
participant_attr.gsub!("315543600000-10800", time_helper(participant.birth_date))
|
47
|
+
encrypted_payload = service.encrypt(participant_attr)
|
48
|
+
savon.expects(:cadastrar_participante).with(:message => {'tns:contrato' => contract_number,
|
49
|
+
'tns:entrada' => encrypted_payload, 'tns:salt' => ''}).returns(fixture_token)
|
50
|
+
result = service.insert(participant)
|
51
|
+
expect(result).to eq('xpto')
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
def time_helper(datetime)
|
57
|
+
"#{(datetime.to_f*1000).to_i}#{datetime.utc_offset}"
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|