moy_sklad 1.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +13 -0
- data/Rakefile +1 -0
- data/bin/gencountry +18 -0
- data/doc/xml/Company.xml +165 -0
- data/doc/xml/CustomEntity.xml +53 -0
- data/doc/xml/CustomerOrder.xml +168 -0
- data/doc/xml/Good.xml +127 -0
- data/doc/xml/GoodFolder.xml +53 -0
- data/doc/xml/MOYsklad.xsd +2450 -0
- data/doc/xml/PaymentIn.xml +81 -0
- data/doc/xml/README.md +1 -0
- data/lib/moy_sklad/client/attribute.rb +119 -0
- data/lib/moy_sklad/client/base.rb +112 -0
- data/lib/moy_sklad/client/collection.rb +52 -0
- data/lib/moy_sklad/client/formatter.rb +37 -0
- data/lib/moy_sklad/client/resource.rb +56 -0
- data/lib/moy_sklad/client.rb +5 -0
- data/lib/moy_sklad/configuration.rb +74 -0
- data/lib/moy_sklad/model/company.rb +23 -0
- data/lib/moy_sklad/model/country.rb +12 -0
- data/lib/moy_sklad/model/custom_entity.rb +4 -0
- data/lib/moy_sklad/model/customer_order.rb +21 -0
- data/lib/moy_sklad/model/data/country_codes.yml +249 -0
- data/lib/moy_sklad/model/demand.rb +20 -0
- data/lib/moy_sklad/model/good.rb +32 -0
- data/lib/moy_sklad/model/good_folder.rb +4 -0
- data/lib/moy_sklad/model/payment_in.rb +9 -0
- data/lib/moy_sklad/model/supply.rb +20 -0
- data/lib/moy_sklad/model/templates/company.builder +132 -0
- data/lib/moy_sklad/model/templates/custom_entity.builder +42 -0
- data/lib/moy_sklad/model/templates/customer_order.builder +151 -0
- data/lib/moy_sklad/model/templates/demand.builder +147 -0
- data/lib/moy_sklad/model/templates/good.builder +83 -0
- data/lib/moy_sklad/model/templates/good_folder.builder +41 -0
- data/lib/moy_sklad/model/templates/payment_in.builder +72 -0
- data/lib/moy_sklad/model/templates/supply.builder +144 -0
- data/lib/moy_sklad/model.rb +13 -0
- data/lib/moy_sklad/nokogiri/document.rb +28 -0
- data/lib/moy_sklad/version.rb +3 -0
- data/lib/moy_sklad.rb +4 -0
- data/moy_sklad.gemspec +28 -0
- data/spec/ms_config.rb +44 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/unit/company_spec.rb +60 -0
- data/spec/unit/country_spec.rb +18 -0
- data/spec/unit/custom_entity_spec.rb +64 -0
- data/spec/unit/customer_order_spec.rb +131 -0
- data/spec/unit/demand_spec.rb +53 -0
- data/spec/unit/fail_spec.rb +12 -0
- data/spec/unit/good_folder_spec.rb +51 -0
- data/spec/unit/good_spec.rb +149 -0
- data/spec/unit/payment_in_spec.rb +120 -0
- data/spec/unit/supply_spec.rb +51 -0
- metadata +211 -0
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Company' do
|
4
|
+
|
5
|
+
describe :index do
|
6
|
+
it "should return list of companies" do
|
7
|
+
comps = MoySklad::Model::Company.find(:all)
|
8
|
+
expect(comps.metadata[:total]).to eq(comps.length)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe :find do
|
13
|
+
it "should find company" do
|
14
|
+
company = MoySklad::Model::Company.new
|
15
|
+
company.name = "Test company"
|
16
|
+
expect(company.save).to eq(true)
|
17
|
+
|
18
|
+
uuid = company.uuid
|
19
|
+
|
20
|
+
company = MoySklad::Model::Company.find(uuid)
|
21
|
+
expect(company.name).to eq("Test company")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe :create do
|
26
|
+
|
27
|
+
it "should create and destroy new Company" do
|
28
|
+
company = MoySklad::Model::Company.new
|
29
|
+
company.name = "Test company"
|
30
|
+
expect(company.save).to eq(true)
|
31
|
+
|
32
|
+
expect(company.uuid.length).to eq(36)
|
33
|
+
uuid = company.uuid
|
34
|
+
|
35
|
+
company.destroy
|
36
|
+
|
37
|
+
expect{MoySklad::Model::Company.find(uuid)}.to raise_error(ActiveResource::ResourceNotFound)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should create new Company with complex attributes" do
|
41
|
+
company = MoySklad::Model::Company.new
|
42
|
+
company.name = "Complex test company"
|
43
|
+
company.contact.phones = "123456"
|
44
|
+
company.contact.email = "foo@bar.baz"
|
45
|
+
company.tags.tag = ["клиент", "дизайнер", "тест"]
|
46
|
+
|
47
|
+
expect(company.save).to eq(true)
|
48
|
+
|
49
|
+
uuid = company.uuid
|
50
|
+
|
51
|
+
company = MoySklad::Model::Company.find(uuid)
|
52
|
+
expect(company.contact.phones).to eq("123456")
|
53
|
+
expect(company.contact.email).to eq("foo@bar.baz")
|
54
|
+
expect(company.tags.tag).to match_array(["клиент", "дизайнер", "тест"])
|
55
|
+
|
56
|
+
company.destroy
|
57
|
+
expect{MoySklad::Model::Company.find(uuid)}.to raise_error(ActiveResource::ResourceNotFound)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Country' do
|
4
|
+
|
5
|
+
describe :index do
|
6
|
+
it "should return list of countries" do
|
7
|
+
cl = MoySklad::Model::Country.find(:all)
|
8
|
+
expect(cl.metadata[:total]).to eq(cl.length)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return correct uuid for code" do
|
12
|
+
uuid = MoySklad::Model::Country.uuid_from_code(643)
|
13
|
+
expect(uuid).to eq("9df7c2c3-7782-4c5c-a8ed-1102af611608")
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'CustomEntity' do
|
4
|
+
|
5
|
+
describe :index do
|
6
|
+
it "should return list of custom entitities" do
|
7
|
+
ents = MoySklad::Model::CustomEntity.find(:all)
|
8
|
+
expect(ents.metadata[:total]).to eq(ents.length)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe :find do
|
13
|
+
it "should return entity", pending: 'need real data in config' do
|
14
|
+
entity = MoySklad::Model::CustomEntity.new
|
15
|
+
entity.name = "повезу на собаках"
|
16
|
+
entity.entityMetadataUuid = CUSTOM_DICT[:delivery_method]
|
17
|
+
expect(entity.save).to eq(true)
|
18
|
+
|
19
|
+
expect(entity.uuid.length).to eq(36)
|
20
|
+
uuid = entity.uuid
|
21
|
+
entity = MoySklad::Model::CustomEntity.find(uuid)
|
22
|
+
expect(entity.entityMetadataUuid).to eq(CUSTOM_DICT[:payment_method])
|
23
|
+
expect(entity.name).to eq("Безналичная оплата")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe :create do
|
28
|
+
|
29
|
+
it "should create and destroy new Entity", pending: 'need real data in config' do
|
30
|
+
entity = MoySklad::Model::CustomEntity.new
|
31
|
+
entity.name = "повезу на собаках"
|
32
|
+
entity.entityMetadataUuid = CUSTOM_DICT[:delivery_method]
|
33
|
+
expect(entity.save).to eq(true)
|
34
|
+
|
35
|
+
expect(entity.uuid.length).to eq(36)
|
36
|
+
uuid = entity.uuid
|
37
|
+
|
38
|
+
entity.destroy
|
39
|
+
|
40
|
+
expect{MoySklad::Model::CustomEntity.find(uuid)}.to raise_error(ActiveResource::ResourceNotFound)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should create, update and destroy new Entity", pending: 'need real data in config' do
|
44
|
+
entity = MoySklad::Model::CustomEntity.new
|
45
|
+
entity.name = "хочу бесплатно"
|
46
|
+
entity.entityMetadataUuid = CUSTOM_DICT[:payment_method]
|
47
|
+
expect(entity.save).to eq(true)
|
48
|
+
|
49
|
+
expect(entity.uuid.length).to eq(36)
|
50
|
+
uuid = entity.uuid
|
51
|
+
|
52
|
+
entity = MoySklad::Model::CustomEntity.find(uuid)
|
53
|
+
entity.name = "отработаю в поле"
|
54
|
+
expect(entity.save).to eq(true)
|
55
|
+
|
56
|
+
entity = MoySklad::Model::CustomEntity.find(uuid)
|
57
|
+
expect(entity.name).to eq("отработаю в поле")
|
58
|
+
expect(entity.entityMetadataUuid).to eq(CUSTOM_DICT[:payment_method])
|
59
|
+
|
60
|
+
entity.destroy
|
61
|
+
expect{MoySklad::Model::CustomEntity.find(uuid)}.to raise_error(ActiveResource::ResourceNotFound)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'CustomerOrder' do
|
4
|
+
|
5
|
+
describe :index do
|
6
|
+
|
7
|
+
it "should enumerate orders, customers and goods (consistency test)" do
|
8
|
+
orders = MoySklad::Model::CustomerOrder.find(:all)
|
9
|
+
expect(orders.metadata[:total]).to eq(orders.length)
|
10
|
+
|
11
|
+
sample = 10
|
12
|
+
sample = orders.metadata[:total] if orders.metadata[:total] < 5
|
13
|
+
|
14
|
+
# Don't check ALL orders, only 5 or less
|
15
|
+
orders.to_a.sample(sample).each do |o|
|
16
|
+
cost = 0
|
17
|
+
|
18
|
+
## We have "bad" order in test DB, just skip them
|
19
|
+
next if o.sourceAgentUuid.is_a?(MoySklad::Client::Attribute::MissingAttr)
|
20
|
+
|
21
|
+
expect(o.sourceAgentUuid.length).to eq(36) # uuid
|
22
|
+
|
23
|
+
customer = MoySklad::Model::Company.find(o.sourceAgentUuid)
|
24
|
+
# puts "#{o.uuid} [##{o.name}] by #{customer.name}"
|
25
|
+
o.to_a(:customerOrderPosition).each do |p|
|
26
|
+
|
27
|
+
cost += ((p.quantity.to_f * p.price.sum.to_f) / 100) ## XXX zero price found in invalid orders
|
28
|
+
|
29
|
+
expect(p.goodUuid.length).to eq(36) # uuid
|
30
|
+
good = MoySklad::Model::Good.find(p.goodUuid)
|
31
|
+
# puts " - #{good.uuid} [#{good.name}], #{p.quantity}"
|
32
|
+
end
|
33
|
+
# puts " total cost: #{cost}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe :find do
|
39
|
+
it "should return order" do
|
40
|
+
order = MoySklad::Model::CustomerOrder.new
|
41
|
+
order.name = "12345"
|
42
|
+
expect(order.save).to eq(true)
|
43
|
+
expect(order.uuid.length).to eq(36)
|
44
|
+
uuid = order.uuid
|
45
|
+
order = MoySklad::Model::CustomerOrder.find(uuid)
|
46
|
+
expect(order.name).to eq("12345")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe :create do
|
51
|
+
it "should create new empty Order" do
|
52
|
+
order = MoySklad::Model::CustomerOrder.new
|
53
|
+
expect(order.save).to eq(true)
|
54
|
+
expect(order.uuid.length).to eq(36)
|
55
|
+
uuid = order.uuid
|
56
|
+
order.destroy
|
57
|
+
expect{MoySklad::Model::CustomerOrder.find(uuid)}.to raise_error(ActiveResource::ResourceNotFound)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should create new Order with values", pending: 'need real data in config' do
|
61
|
+
order = MoySklad::Model::CustomerOrder.new
|
62
|
+
order.name = "12345 - api test"
|
63
|
+
order.targetAgentUuid = TGT_AGENT
|
64
|
+
order.sourceStoreUuid = SRC_STORE
|
65
|
+
order.sourceAgentUuid = SRC_AGENT
|
66
|
+
expect(order.save).to eq(true)
|
67
|
+
expect(order.uuid.length).to eq(36)
|
68
|
+
uuid = order.uuid
|
69
|
+
|
70
|
+
order = MoySklad::Model::CustomerOrder.find(uuid)
|
71
|
+
expect(order.name).to eq("12345 - api test")
|
72
|
+
expect(order.targetAgentUuid).to eq(TGT_AGENT)
|
73
|
+
expect(order.sourceStoreUuid).to eq(SRC_STORE)
|
74
|
+
expect(order.sourceAgentUuid).to eq(SRC_AGENT)
|
75
|
+
|
76
|
+
customer = MoySklad::Model::Company.find(order.sourceAgentUuid)
|
77
|
+
expect(customer.name).to eq("Username")
|
78
|
+
order.destroy
|
79
|
+
expect{MoySklad::Model::CustomerOrder.find(uuid)}.to raise_error(ActiveResource::ResourceNotFound)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should create order with items and check cost", pending: 'need real data in config' do
|
83
|
+
order = MoySklad::Model::CustomerOrder.new
|
84
|
+
order.name = "12345 - api test [items]"
|
85
|
+
order.applicable = true
|
86
|
+
order.targetAgentUuid = TGT_AGENT
|
87
|
+
order.sourceStoreUuid = SRC_STORE
|
88
|
+
order.sourceAgentUuid = SRC_AGENT
|
89
|
+
order.stateUuid = CONFIRMED_UUID
|
90
|
+
order.sum.sum = "100"
|
91
|
+
order.sum.sumInCurrency = "100"
|
92
|
+
|
93
|
+
KNOWN_ITEMS.each do |id, info|
|
94
|
+
order.add_item(id, {quantity: info[:quantity],
|
95
|
+
basePrice: { sum: info[:price] * 100, sumInCurrency: info[:price] * 100},
|
96
|
+
price: { sum: info[:price] * 100, sumInCurrency: info[:price] * 100}})
|
97
|
+
end
|
98
|
+
|
99
|
+
ORDER_OPTIONS.each do |type, opt|
|
100
|
+
order.set_attribute({uuid: opt[:key], value: :entityValueUuid}, opt[:value])
|
101
|
+
end
|
102
|
+
|
103
|
+
expect(order.save).to eq(true)
|
104
|
+
expect(order.uuid.length).to eq(36)
|
105
|
+
uuid = order.uuid
|
106
|
+
|
107
|
+
order = MoySklad::Model::CustomerOrder.find(uuid)
|
108
|
+
expect(order.name).to eq("12345 - api test [items]")
|
109
|
+
expect(order.targetAgentUuid).to eq(TGT_AGENT)
|
110
|
+
expect(order.sourceStoreUuid).to eq(SRC_STORE)
|
111
|
+
expect(order.sourceAgentUuid).to eq(SRC_AGENT)
|
112
|
+
expect(order.stateUuid).to eq(CONFIRMED_UUID)
|
113
|
+
|
114
|
+
ORDER_OPTIONS.each do |type, opt|
|
115
|
+
expect(order.get_attribute(opt[:key]).entityValueUuid).to eq(opt[:value])
|
116
|
+
end
|
117
|
+
|
118
|
+
# This is NORMAL, order sum is always zero :D
|
119
|
+
expect(order.sum.sum).to eq("4.744008E7")
|
120
|
+
expect(order.sum.sumInCurrency).to eq("4.744008E7")
|
121
|
+
|
122
|
+
expect(order.customerOrderPosition.length).to eq(KNOWN_ITEMS.keys.length)
|
123
|
+
customer = MoySklad::Model::Company.find(order.sourceAgentUuid)
|
124
|
+
expect(customer.name).to eq("Username")
|
125
|
+
|
126
|
+
order.destroy
|
127
|
+
expect{MoySklad::Model::CustomerOrder.find(uuid)}.to raise_error(ActiveResource::ResourceNotFound)
|
128
|
+
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Demand' do
|
4
|
+
|
5
|
+
describe :index do
|
6
|
+
it "should return list of demands" do
|
7
|
+
sups = MoySklad::Model::Demand.find(:all)
|
8
|
+
expect(sups.metadata[:total]).to eq(sups.length)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe :find do
|
13
|
+
it "should return demand" do
|
14
|
+
demand = MoySklad::Model::Demand.find("91fbb933-5b4f-11e4-90a2-8ecb0019b941")
|
15
|
+
expect(demand.uuid).to eq("91fbb933-5b4f-11e4-90a2-8ecb0019b941")
|
16
|
+
expect(demand.to_a(:shipmentOut).length).to eq(1)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe :create do
|
21
|
+
|
22
|
+
it "should create new empty Demand" do
|
23
|
+
demand = MoySklad::Model::Demand.new
|
24
|
+
demand.sourceStoreUuid = "b6fd1ae5-213c-11e4-a18f-002590a28eca"
|
25
|
+
demand.customerOrderUuid = "f4fc79f6-5b4b-11e4-7a07-673d00379d95"
|
26
|
+
expect(demand.save).to eq(true)
|
27
|
+
expect(demand.uuid.length).to eq(36)
|
28
|
+
demand.destroy
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should create new non-empty Demand" do
|
32
|
+
demand = MoySklad::Model::Demand.new
|
33
|
+
demand.sourceStoreUuid = "b6fd1ae5-213c-11e4-a18f-002590a28eca"
|
34
|
+
demand.targetAgentUuid = "a114c0a4-5ab2-11e4-7a07-673d00178e52"
|
35
|
+
demand.sourceAgentUuid = "13187298-1ee5-11e4-7dd5-002590a28eca"
|
36
|
+
demand.customerOrderUuid = "f4fc79f6-5b4b-11e4-7a07-673d00379d95"
|
37
|
+
demand.applicable = true
|
38
|
+
demand.add_item("9eccf56d-5ab4-11e4-90a2-8ecb000e5298", { quantity: 850 })
|
39
|
+
expect(demand.save).to eq(true)
|
40
|
+
expect(demand.uuid.length).to eq(36)
|
41
|
+
|
42
|
+
uuid = demand.uuid
|
43
|
+
demand = MoySklad::Model::Demand.find(uuid)
|
44
|
+
expect(demand.sum.sum).to eq("0.0")
|
45
|
+
expect(demand.sum.sumInCurrency).to eq("0.0")
|
46
|
+
expect(demand.to_a(:shipmentOut).length).to eq(1)
|
47
|
+
demand.destroy
|
48
|
+
|
49
|
+
expect{MoySklad::Model::Demand.find(uuid)}.to raise_error(ActiveResource::ResourceNotFound)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Some fail tests" do
|
4
|
+
|
5
|
+
it "should return error on save (invalid uuid)" do
|
6
|
+
p = MoySklad::Model::PaymentIn.new
|
7
|
+
p.demandsUuid = [nil]
|
8
|
+
|
9
|
+
expect(p.save).to eq(false)
|
10
|
+
expect(p.error.message).to eq("Invalid UUID string: ")
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'GoodFolder' do
|
4
|
+
|
5
|
+
describe :index do
|
6
|
+
it "should return list of folders" do
|
7
|
+
folders = MoySklad::Model::GoodFolder.find(:all)
|
8
|
+
expect(folders.metadata[:total]).to eq(folders.length)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe :find do
|
13
|
+
it "should return item" do
|
14
|
+
folder = MoySklad::Model::GoodFolder.new
|
15
|
+
folder.name = "Test::top level"
|
16
|
+
expect(folder.save).to eq(true)
|
17
|
+
folder = MoySklad::Model::GoodFolder.find(folder.uuid)
|
18
|
+
expect(folder.name).to eq("Test::top level")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe :create do
|
23
|
+
|
24
|
+
it "should create new GoodFolder" do
|
25
|
+
folder = MoySklad::Model::GoodFolder.new
|
26
|
+
folder.name = "Test folder"
|
27
|
+
expect(folder.save).to eq(true)
|
28
|
+
expect(folder.uuid.length).to eq(36)
|
29
|
+
folder.destroy
|
30
|
+
end
|
31
|
+
|
32
|
+
it "create tree" do
|
33
|
+
folder = MoySklad::Model::GoodFolder.new
|
34
|
+
folder.name = "Test::top level"
|
35
|
+
expect(folder.save).to eq(true)
|
36
|
+
|
37
|
+
subfolder = MoySklad::Model::GoodFolder.new({name: "Sublevel folder", parentUuid: folder.uuid})
|
38
|
+
expect(subfolder.save).to eq(true)
|
39
|
+
|
40
|
+
expect(subfolder.parentUuid).to eq(folder.uuid)
|
41
|
+
|
42
|
+
uuid = folder.uuid
|
43
|
+
suuid = subfolder.uuid
|
44
|
+
|
45
|
+
folder.destroy
|
46
|
+
|
47
|
+
expect{MoySklad::Model::GoodFolder.find(uuid)}.to raise_error(ActiveResource::ResourceNotFound)
|
48
|
+
expect{MoySklad::Model::GoodFolder.find(suuid)}.to raise_error(ActiveResource::ResourceNotFound)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'securerandom'
|
3
|
+
|
4
|
+
describe 'Good' do
|
5
|
+
|
6
|
+
describe :index do
|
7
|
+
it "should return list of items" do
|
8
|
+
items = MoySklad::Model::Good.find(:all)
|
9
|
+
expect(items.metadata[:total]).to eq(items.length)
|
10
|
+
len = items.metadata[:total]
|
11
|
+
|
12
|
+
# Newly update items, should be less then total
|
13
|
+
items = MoySklad::Model::Good.find(:all, params: { filter: "updated>20141014010000"})
|
14
|
+
expect(items.metadata[:total]).to be < len
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe :find do
|
19
|
+
it "should return good" do
|
20
|
+
item = MoySklad::Model::Good.new
|
21
|
+
item.name = "Sample good"
|
22
|
+
item.save
|
23
|
+
item = MoySklad::Model::Good.find(item.uuid)
|
24
|
+
expect(item.name).to eq("Sample good")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "Simple attribute update" do
|
29
|
+
before(:all) do
|
30
|
+
item = MoySklad::Model::Good.new
|
31
|
+
item.name = "Simple test item for attr update test"
|
32
|
+
item.save
|
33
|
+
@uuid = item.uuid
|
34
|
+
@randomPrice = rand(1.0..100.0).round(2)
|
35
|
+
end
|
36
|
+
|
37
|
+
after(:all) do
|
38
|
+
MoySklad::Model::Good.find(@uuid).destroy
|
39
|
+
end
|
40
|
+
|
41
|
+
it "and update attr" do
|
42
|
+
item = MoySklad::Model::Good.find(@uuid)
|
43
|
+
expect(item.buyPrice).to eq("0.0")
|
44
|
+
item.buyPrice = @randomPrice
|
45
|
+
expect(item.save).to eq(true)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "and read attr" do
|
49
|
+
item = MoySklad::Model::Good.find(@uuid)
|
50
|
+
expect(item.buyPrice.to_f).to eq(@randomPrice)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "create and update" do
|
55
|
+
it "should create a new Good" do
|
56
|
+
item = MoySklad::Model::Good.new
|
57
|
+
item.name = "Just a test item, с русскими букавами in da name"
|
58
|
+
item.description = "Отличный итем, шерстянной такой"
|
59
|
+
expect(item.save).to eq(true)
|
60
|
+
|
61
|
+
expect(item.uuid.length).to eq(36) # Should looks like real uuid
|
62
|
+
|
63
|
+
uuid = item.uuid
|
64
|
+
|
65
|
+
# Check item on server
|
66
|
+
item = MoySklad::Model::Good.find(uuid)
|
67
|
+
expect(item.uuid).to eq(uuid)
|
68
|
+
|
69
|
+
# Remove item
|
70
|
+
item.destroy
|
71
|
+
|
72
|
+
expect{MoySklad::Model::Good.find(uuid)}.to raise_error(ActiveResource::ResourceNotFound)
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "should create item with salePrice and able to update only default",
|
76
|
+
pending: 'need real data in config' do
|
77
|
+
before(:all) do
|
78
|
+
item = MoySklad::Model::Good.new
|
79
|
+
item.name = "Test item with custom prices"
|
80
|
+
|
81
|
+
item.set_sale_price(PRICE_CUR, 100)
|
82
|
+
|
83
|
+
item.save
|
84
|
+
@uuid = item.uuid
|
85
|
+
end
|
86
|
+
|
87
|
+
after(:all) do
|
88
|
+
MoySklad::Model::Good.find(@uuid).destroy
|
89
|
+
end
|
90
|
+
|
91
|
+
it "and get price" do
|
92
|
+
item = MoySklad::Model::Good.find(@uuid)
|
93
|
+
expect(item.get_sale_price(PRICE_CUR).value.to_f / 100).to eq(100)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "and update CUR price (only default price can be updated)" do
|
97
|
+
item = MoySklad::Model::Good.find(@uuid)
|
98
|
+
|
99
|
+
item.set_sale_price(PRICE_CUR, 1000)
|
100
|
+
expect(item.save).to eq(true)
|
101
|
+
|
102
|
+
expect(item.get_sale_price(PRICE_CUR).value.to_f / 100).to eq(1000)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "item with custom attributes" do
|
107
|
+
let(:partno) { SecureRandom.hex }
|
108
|
+
let(:country) { SecureRandom.hex }
|
109
|
+
let(:link) { SecureRandom.hex }
|
110
|
+
|
111
|
+
before(:all) do
|
112
|
+
item = MoySklad::Model::Good.new
|
113
|
+
item.name = "Test item with custom attributes"
|
114
|
+
item.save
|
115
|
+
@uuid = item.uuid
|
116
|
+
end
|
117
|
+
|
118
|
+
after(:all) do
|
119
|
+
MoySklad::Model::Good.find(@uuid).destroy
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should test empty attrs", pending: 'need real data in config' do
|
123
|
+
item = MoySklad::Model::Good.find(@uuid)
|
124
|
+
|
125
|
+
expect(item.get_attribute(META_LINK[:uuid])).to be_nil
|
126
|
+
expect(item.get_attribute(META_ARTNO)).to be_nil
|
127
|
+
expect(item.get_attribute(META_COUNTRY)).to be_nil
|
128
|
+
expect{item.get_attribute("foo")}.to raise_error(ArgumentError)
|
129
|
+
end
|
130
|
+
|
131
|
+
it "set and read attrs", pending: 'need real data in config' do
|
132
|
+
item = MoySklad::Model::Good.find(@uuid)
|
133
|
+
|
134
|
+
item.set_attribute(META_COUNTRY, country)
|
135
|
+
item.set_attribute(META_LINK, link)
|
136
|
+
item.set_attribute(META_ARTNO, partno)
|
137
|
+
|
138
|
+
expect(item.save).to eq(true)
|
139
|
+
|
140
|
+
item = MoySklad::Model::Good.find(@uuid)
|
141
|
+
expect(item.get_attribute(META_LINK)).to eq(link)
|
142
|
+
expect(item.get_attribute(META_ARTNO)).to eq(partno)
|
143
|
+
expect(item.get_attribute(META_COUNTRY[:uuid]).valueString).to eq(country)
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'PaymentIn' do
|
4
|
+
|
5
|
+
describe :index do
|
6
|
+
it "should return list of payments" do
|
7
|
+
payments = MoySklad::Model::PaymentIn.find(:all)
|
8
|
+
expect(payments.metadata[:total]).to eq(payments.length)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe :find do
|
13
|
+
it "should return payment" do
|
14
|
+
payment = MoySklad::Model::PaymentIn.new
|
15
|
+
payment.name = "test - payment"
|
16
|
+
payment.sum.sum = 1000 * 100
|
17
|
+
expect(payment.save).to eq(true)
|
18
|
+
expect(payment.uuid.length).to eq(36)
|
19
|
+
|
20
|
+
uuid = payment.uuid
|
21
|
+
payment = MoySklad::Model::PaymentIn.find(uuid)
|
22
|
+
expect(payment.name).to eq("test - payment")
|
23
|
+
expect(payment.sum.sum).to eq("100000.0")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe :create do
|
28
|
+
|
29
|
+
it "should create new empty PaymentIn" do
|
30
|
+
payment = MoySklad::Model::PaymentIn.new
|
31
|
+
expect(payment.save).to eq(true)
|
32
|
+
expect(payment.uuid.length).to eq(36)
|
33
|
+
payment.destroy
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should create new non-empty PaymentIn" do
|
37
|
+
payment = MoySklad::Model::PaymentIn.new
|
38
|
+
payment.name = "test - payment"
|
39
|
+
payment.sum.sum = 1000 * 100
|
40
|
+
expect(payment.save).to eq(true)
|
41
|
+
expect(payment.uuid.length).to eq(36)
|
42
|
+
|
43
|
+
uuid = payment.uuid
|
44
|
+
payment = MoySklad::Model::PaymentIn.find(uuid)
|
45
|
+
expect(payment.name).to eq("test - payment")
|
46
|
+
expect(payment.sum.sum).to eq("100000.0")
|
47
|
+
expect(payment.sum.sumInCurrency).to eq("100000.0")
|
48
|
+
payment.destroy
|
49
|
+
|
50
|
+
expect{MoySklad::Model::PaymentIn.find(uuid)}.to raise_error(ActiveResource::ResourceNotFound)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should create new order + payment", pending: 'need real data in config' do
|
54
|
+
order = MoySklad::Model::CustomerOrder.new
|
55
|
+
order.name = "Test with payment - API"
|
56
|
+
order.applicable = true
|
57
|
+
order.targetAgentUuid = TGT_AGENT
|
58
|
+
order.sourceStoreUuid = SRC_STORE
|
59
|
+
order.sourceAgentUuid = SRC_AGENT
|
60
|
+
order.stateUuid = CONFIRMED_UUID
|
61
|
+
order.sum.sum = "100"
|
62
|
+
order.sum.sumInCurrency = "100"
|
63
|
+
|
64
|
+
KNOWN_ITEMS.each do |id, info|
|
65
|
+
order.addItem(id, {quantity: info[:quantity],
|
66
|
+
basePrice: { sum: info[:price] * 100, sumInCurrency: info[:price] * 100},
|
67
|
+
price: { sum: info[:price] * 100, sumInCurrency: info[:price] * 100}})
|
68
|
+
end
|
69
|
+
|
70
|
+
ORDER_OPTIONS.each do |type, opt|
|
71
|
+
order.setAttribute({uuid: opt[:key], value: :entityValueUuid}, opt[:value])
|
72
|
+
end
|
73
|
+
|
74
|
+
expect(order.save).to eq(true)
|
75
|
+
expect(order.uuid.length).to eq(36)
|
76
|
+
uuid = order.uuid
|
77
|
+
|
78
|
+
payment = MoySklad::Model::PaymentIn.new
|
79
|
+
payment.sum.sum = order.sum.sum
|
80
|
+
payment.targetAgentUuid = TGT_AGENT
|
81
|
+
payment.sourceAgentUuid = SRC_AGENT
|
82
|
+
payment.describe = "Just a test"
|
83
|
+
payment.customerOrderUuid = uuid
|
84
|
+
|
85
|
+
expect(payment.save).to eq(true)
|
86
|
+
expect(payment.uuid.length).to eq(36)
|
87
|
+
|
88
|
+
# check order and bounded payment
|
89
|
+
order = MoySklad::Model::CustomerOrder.find(uuid)
|
90
|
+
expect(order.paymentsUuid.to_a(:financeInRef).first).to eq(payment.uuid)
|
91
|
+
|
92
|
+
# Order can be destroyed only after the payment
|
93
|
+
expect{order.destroy}.to raise_error(ActiveResource::ResourceNotFound)
|
94
|
+
payment.destroy
|
95
|
+
order.destroy
|
96
|
+
end
|
97
|
+
|
98
|
+
it "create payment and update applicable status", pending: 'need real data in config' do
|
99
|
+
|
100
|
+
payment = MoySklad::Model::PaymentIn.new
|
101
|
+
payment.targetAgentUuid = TGT_AGENT
|
102
|
+
payment.sourceAgentUuid = SRC_AGENT
|
103
|
+
payment.sum.sum = 1000 * 100
|
104
|
+
expect(payment.save).to eq(true)
|
105
|
+
uuid = payment.uuid
|
106
|
+
|
107
|
+
payment = MoySklad::Model::PaymentIn.find(uuid)
|
108
|
+
expect(payment.applicable).to eq("false")
|
109
|
+
payment.applicable = "true"
|
110
|
+
expect(payment.save).to eq(true)
|
111
|
+
|
112
|
+
payment = MoySklad::Model::PaymentIn.find(uuid)
|
113
|
+
expect(payment.applicable).to eq("true")
|
114
|
+
|
115
|
+
payment.destroy
|
116
|
+
|
117
|
+
expect{MoySklad::Model::PaymentIn.find(uuid)}.to raise_error(ActiveResource::ResourceNotFound)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|