-
-
Notifications
You must be signed in to change notification settings - Fork 572
Expand file tree
/
Copy pathitem_update_service_spec.rb
More file actions
77 lines (66 loc) · 2.07 KB
/
item_update_service_spec.rb
File metadata and controls
77 lines (66 loc) · 2.07 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
# frozen_string_literal: true
require "rspec"
RSpec.describe ItemUpdateService, type: :service do
describe ".call" do
subject { described_class.new(item: item, params: params, request_unit_ids: request_unit_ids).call }
let(:kit) { create(:kit) }
let(:item) { create(:item, kit: kit) }
let(:line_item) { create(:line_item, item: item, quantity: 1) }
let(:params) do
{
name: "Updated Item Name",
reporting_category: "pads",
value_in_cents: 2000
}
end
let(:request_unit_ids) { [] }
before do
kit.line_items = [line_item]
end
context "params are ok" do
it "returns a Result with success? true and the item" do
result = subject
expect(result).to be_a_kind_of(Result)
expect(result.success?).to eq(true)
expect(result.value).to eq(item)
end
it "updates the item attributes" do
subject
item.reload
expect(item.name).to eq("Updated Item Name")
expect(item.value_in_cents).to eq(2000)
end
it "updates the kit value_in_cents" do
subject
kit.reload
expect(kit.value_in_cents).to eq(params[:value_in_cents])
end
end
context "params are invalid" do
let(:params) do
{
name: "" # Invalid as name can't be blank
}
end
it "returns a Result with success? false and an error" do
result = subject
expect(result).to be_a_kind_of(Result)
expect(result.success?).to eq(false)
expect(result.error).to be_a(ActiveRecord::RecordInvalid)
expect(result.error.message).to include("Validation failed: Name can't be blank")
end
it "does not update the item attributes" do
original_name = item.name
subject
item.reload
expect(item.name).to eq(original_name)
end
it "does not update the kit value_in_cents" do
original_kit_value = kit.value_in_cents
subject
kit.reload
expect(kit.value_in_cents).to eq(original_kit_value)
end
end
end
end