Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion app/controllers/api/v3/export_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@ def production_parameters

# GET /api/v3/scenarios/:id/energy_flow
#
# Returns a CSV file containing the energetic inputs and outputs of every node in the graph.
# Returns a CSV file containing the energetic inputs and outputs of every node in the future graph.
def energy_flow
send_csv(NodeFlowSerializer.new(@scenario.gql.future.graph, 'MJ'), 'energy_flow.%d.csv')
end

# GET /api/v3/scenarios/:id/energy_flow_present
#
# Returns a CSV file containing the energetic inputs and outputs of every node in the present graph.
def energy_flow_present
send_csv(NodeFlowSerializer.new(@scenario.gql.present.graph, 'MJ'), 'energy_flow_present.%d.csv')
end

# GET /api/v3/scenarios/:id/molecule_flow
#
# Returns a CSV file containing the flow of molecules through the molecule graph.
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
get :batch
get :production_parameters, to: 'export#production_parameters'
get :energy_flow, to: 'export#energy_flow'
get :energy_flow_present, to: 'export#energy_flow_present'
get :molecule_flow, to: 'export#molecule_flow'
get :costs_parameters, to: 'export#costs_parameters'
get :sankey, to: 'export#sankey'
Expand Down
25 changes: 24 additions & 1 deletion spec/controllers/api/v3/exports_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
let(:user) { create(:user) }
let(:headers) { access_token_header(user, :write) }

describe 'GET energy_flows.csv' do
describe 'GET energy_flow.csv' do
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, I would keep this as energy_flows, not energy_flow. Then the present one should be renamed to energy_flows_present as well?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was always energy_flow this was a typo @aaccensi fixed

before do
request.headers.merge!(headers)
get :energy_flow, params: { id: scenario.id }, format: :csv
Expand All @@ -30,6 +30,29 @@
end
end

describe 'GET energy_flow_present.csv' do
before do
request.headers.merge!(headers)
get :energy_flow_present, params: { id: scenario.id }, format: :csv
end

it 'is successful' do
expect(response).to be_ok
end

it 'sets the content type to text/csv' do
expect(response.media_type).to eq('text/csv')
end

it 'sets the CSV filename' do
expect(response.headers['Content-Disposition']).to include("energy_flow_present.#{scenario.id}.csv")
end

it 'renders the CSV' do
expect(response.body).to eq(NodeFlowSerializer.new(scenario.gql.present.graph, 'MJ').as_csv)
end
end

describe 'GET molecule_flows.csv' do
before do
request.headers.merge!(headers)
Expand Down