-
Notifications
You must be signed in to change notification settings - Fork 304
Expand file tree
/
Copy pathitem_spec.rb
More file actions
97 lines (75 loc) · 2.9 KB
/
Copy pathitem_spec.rb
File metadata and controls
97 lines (75 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
describe "Quickbooks::Service::Item" do
before(:all) do
construct_service :item
end
it "can query for items" do
xml = fixture("items.xml")
model = Quickbooks::Model::Item
stub_http_request(:get, @service.url_for_query, ["200", "OK"], xml)
items = @service.query
expect(items.entries.count).to eq(2)
doll = items.entries.first
expect(doll.name).to eq('Plush Baby Doll')
end
it "can fetch an Item by ID" do
xml = fixture("fetch_item_by_id.xml")
model = Quickbooks::Model::Item
stub_http_request(:get, "#{@service.url_for_base}/item/2", ["200", "OK"], xml)
item = @service.fetch_by_id(2)
expect(item.name).to eq("Plush Baby Doll")
end
it "cannot create an Item without a name" do
item = Quickbooks::Model::Item.new
# invalid because the name contains a colon
expect do
@service.create(item)
end.to raise_error(Quickbooks::InvalidModelException)
expect(item.valid?).to eq(false)
expect(item.errors.keys.include?(:name)).to eq(true)
end
it "can create an Item" do
xml = fixture("fetch_item_by_id.xml")
model = Quickbooks::Model::Item
stub_http_request(:post, @service.url_for_resource(model::REST_RESOURCE), ["200", "OK"], xml)
item = Quickbooks::Model::Item.new
item.name = "Comfy Pillow"
created_item = @service.create(item)
expect(created_item.id).to eq("2")
end
it "can create an Item with minorversion and requestid" do
xml = fixture("fetch_item_by_id.xml")
model = Quickbooks::Model::Item
url = "#{@service.url_for_resource(model::REST_RESOURCE)}?requestid=123"
stub_http_request(:post, url, ["200", "OK"], xml)
item = Quickbooks::Model::Item.new
item.name = "Comfy Pillow"
created_item = @service.create(item, query: {requestid: 123})
expect(created_item.id).to eq("2")
end
it "can sparse update an Item" do
model = Quickbooks::Model::Item
item = Quickbooks::Model::Item.new
item.name = "Plush Baby Doll"
item.sync_token = 2
item.id = 1
# purposefully unset an element - which if we were not using
# sparse update would cause Intuit to unset the field remotely as well.
item.description = nil
xml = fixture("fetch_item_by_id.xml")
stub_http_request(:post, @service.url_for_resource(model::REST_RESOURCE), ["200", "OK"], xml, {}, true)
update_response = @service.update(item, :sparse => true)
expect(update_response.name).to eq('Plush Baby Doll')
expect(update_response.description).not_to be_nil
end
it "can delete an Item" do
model = Quickbooks::Model::Item
item = Quickbooks::Model::Item.new
item.name = "Thrifty Meats"
item.sync_token = 2
item.id = 1
xml = fixture("item_delete_success_response.xml")
stub_http_request(:post, @service.url_for_resource(model::REST_RESOURCE), ["200", "OK"], xml, {}, true)
response = @service.delete(item)
expect(response.active?).to be_nil
end
end