Skip to content

Commit 08c98e0

Browse files
committed
Move adjustment export format tests into requests spec
1 parent a446909 commit 08c98e0

2 files changed

Lines changed: 68 additions & 85 deletions

File tree

spec/controllers/adjustments_controller_spec.rb

Lines changed: 0 additions & 82 deletions
This file was deleted.

spec/requests/adjustments_requests_spec.rb

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
RSpec.describe "Adjustments", type: :request do
1+
RSpec.describe "Adjustments", :wip, type: :request do
22
let(:organization) { create(:organization) }
33
let(:user) { create(:user, organization: organization) }
44

@@ -72,10 +72,75 @@
7272

7373
context "csv" do
7474
let(:response_format) { 'csv' }
75+
let(:storage_location) { create(:storage_location, organization: organization) }
76+
let(:item1) { create(:item, name: "Item One", organization: organization) }
77+
let(:item2) { create(:item, name: "Item Two", organization: organization) }
78+
79+
let!(:adjustment1) do
80+
adj = create(:adjustment,
81+
organization: organization,
82+
storage_location: storage_location,
83+
comment: "First adjustment",
84+
created_at: 1.day.ago)
85+
adj.line_items << build(:line_item, quantity: 10, item: item1, itemizable: adj)
86+
adj.line_items << build(:line_item, quantity: 5, item: item2, itemizable: adj)
87+
adj
88+
end
89+
90+
let!(:adjustment2) do
91+
adj = create(:adjustment,
92+
organization: organization,
93+
storage_location: storage_location,
94+
comment: "Second adjustment",
95+
created_at: 5.days.ago)
96+
adj.line_items << build(:line_item, quantity: -5, item: item1, itemizable: adj)
97+
adj
98+
end
99+
100+
before { get adjustments_path(format: 'csv') }
101+
102+
it "returns a CSV file" do
103+
expect(response).to be_successful
104+
expect(response.header['Content-Type']).to include 'text/csv'
105+
end
106+
107+
it "includes appropriate headers for adjustments" do
108+
expect(response.body).to include("Created date")
109+
expect(response.body).to include("Storage Area")
110+
expect(response.body).to include("Comment")
111+
expect(response.body).to include("# of changes")
112+
expect(response.body).to include(item1.name)
113+
expect(response.body).to include(item2.name)
114+
end
115+
116+
it "includes data from the adjustments" do
117+
parsed_csv = CSV.parse(response.body, headers: true)
75118

76-
before { adjustment }
119+
expect(parsed_csv.count).to eq(2)
77120

78-
it { is_expected.to be_successful }
121+
expect(parsed_csv[0]["Comment"]).to eq(adjustment1.comment)
122+
expect(parsed_csv[1]["Comment"]).to eq(adjustment2.comment)
123+
124+
expect(parsed_csv[0][item1.name]).to eq("10")
125+
expect(parsed_csv[0][item2.name]).to eq("5")
126+
expect(parsed_csv[0]["# of changes"]).to eq("2")
127+
128+
expect(parsed_csv[1][item1.name]).to eq("-5")
129+
expect(parsed_csv[1]["# of changes"]).to eq("1")
130+
end
131+
132+
context "when filtering by date" do
133+
it "returns adjustments filtered by date range" do
134+
start_date = 3.days.ago.to_fs(:date_picker)
135+
end_date = Time.zone.today.to_fs(:date_picker)
136+
137+
get adjustments_path, params: { filters: { date_range: "#{start_date} - #{end_date}" }, format: 'csv' }
138+
139+
parsed_csv = CSV.parse(response.body, headers: true)
140+
expect(parsed_csv.count).to eq(1)
141+
expect(parsed_csv[0]["Comment"]).to eq(adjustment1.comment)
142+
end
143+
end
79144
end
80145
end
81146

0 commit comments

Comments
 (0)