-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow manual loads for all solar feeds (#3216)
- Loading branch information
Showing
21 changed files
with
503 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Solar | ||
class LowCarbonHubLoaderJob < BaseSolarLoaderJob | ||
private | ||
|
||
def upserter(start_date, end_date) | ||
Solar::LowCarbonHubDownloadAndUpsert.new(installation: @installation, start_date: start_date, end_date: end_date) | ||
end | ||
|
||
def solar_feed_type | ||
"Rtone" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Solar | ||
class RtoneVariantLoaderJob < BaseSolarLoaderJob | ||
private | ||
|
||
def upserter(start_date, end_date) | ||
Solar::RtoneVariantDownloadAndUpsert.new(installation: @installation, start_date: start_date, end_date: end_date) | ||
end | ||
|
||
def solar_feed_type | ||
"Rtone Variant" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
$('#low-carbon-hub-<%= @low_carbon_hub_installation.id %>-test').html('<i class="fas <%= @api_ok ? 'text-success fa-circle-check' : 'text-danger fa-circle-xmark' %>"></i> Check API'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
$('#rtone-variant-<%= @rtone_variant_installation.id %>-test').html('<i class="fas <%= @api_ok ? 'text-success fa-circle-check' : 'text-danger fa-circle-xmark' %>"></i> Check API'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
require 'rails_helper' | ||
|
||
describe Solar::LowCarbonHubLoaderJob do | ||
include Rails.application.routes.url_helpers | ||
let!(:installation) { create(:solar_edge_installation) } | ||
let(:job) { Solar::LowCarbonHubLoaderJob.new } | ||
|
||
let!(:import_log) { create(:amr_data_feed_import_log, records_updated: 4, records_imported: 100) } | ||
let(:upserter) { instance_double(Solar::LowCarbonHubDownloadAndUpsert, perform: nil, import_log: import_log) } | ||
|
||
include_context "when sending solar loader job emails" | ||
|
||
describe '#perform' do | ||
let(:job_result) { job.perform(installation: installation, start_date: start_date, end_date: end_date, notify_email: admin.email) } | ||
|
||
context 'when the load is successful' do | ||
before do | ||
allow(Solar::LowCarbonHubDownloadAndUpsert).to receive(:new).and_return(upserter) | ||
end | ||
|
||
it 'calls the upserter' do | ||
expect(Solar::LowCarbonHubDownloadAndUpsert).to receive(:new).with(start_date: start_date, end_date: end_date, installation: installation) | ||
job_result | ||
end | ||
|
||
context 'when sending the email' do | ||
before do | ||
job_result | ||
end | ||
|
||
it_behaves_like 'a successful solar loader job', solar_feed_type: 'Rtone' | ||
end | ||
end | ||
|
||
context 'when the load is unsuccessful' do | ||
let!(:import_log) { create(:amr_data_feed_import_log, error_messages: "There are errors here") } | ||
|
||
before do | ||
allow(Solar::LowCarbonHubDownloadAndUpsert).to receive(:new).and_return(upserter) | ||
end | ||
|
||
context 'with a loading error' do | ||
before do | ||
job_result | ||
end | ||
|
||
it_behaves_like 'a solar loader job with loader errors', solar_feed_type: 'Rtone' | ||
end | ||
|
||
context 'with an unexpected exception' do | ||
before do | ||
allow(Solar::LowCarbonHubDownloadAndUpsert).to receive(:new).and_raise("Its broken") | ||
#rubocop:disable RSpec/ExpectInHook | ||
expect(Rollbar).to receive(:error).with(anything, job: :import_solar_edge_readings) | ||
#rubocop:enable RSpec/ExpectInHook | ||
job_result | ||
end | ||
|
||
it_behaves_like 'a solar loader job that had an exception', solar_feed_type: 'Rtone' | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
require 'rails_helper' | ||
|
||
describe Solar::RtoneVariantLoaderJob do | ||
include Rails.application.routes.url_helpers | ||
let!(:installation) { create(:solar_edge_installation) } | ||
let(:job) { Solar::RtoneVariantLoaderJob.new } | ||
|
||
let!(:import_log) { create(:amr_data_feed_import_log, records_updated: 4, records_imported: 100) } | ||
let(:upserter) { instance_double(Solar::RtoneVariantDownloadAndUpsert, perform: nil, import_log: import_log) } | ||
|
||
include_context "when sending solar loader job emails" | ||
|
||
describe '#perform' do | ||
let(:job_result) { job.perform(installation: installation, start_date: start_date, end_date: end_date, notify_email: admin.email) } | ||
|
||
context 'when the load is successful' do | ||
before do | ||
allow(Solar::RtoneVariantDownloadAndUpsert).to receive(:new).and_return(upserter) | ||
end | ||
|
||
it 'calls the upserter' do | ||
expect(Solar::RtoneVariantDownloadAndUpsert).to receive(:new).with(start_date: start_date, end_date: end_date, installation: installation) | ||
job_result | ||
end | ||
|
||
context 'when sending the email' do | ||
before do | ||
job_result | ||
end | ||
|
||
it_behaves_like 'a successful solar loader job', solar_feed_type: 'Rtone Variant' | ||
end | ||
end | ||
|
||
context 'when the load is unsuccessful' do | ||
let!(:import_log) { create(:amr_data_feed_import_log, error_messages: "There are errors here") } | ||
|
||
before do | ||
allow(Solar::RtoneVariantDownloadAndUpsert).to receive(:new).and_return(upserter) | ||
end | ||
|
||
context 'with a loading error' do | ||
before do | ||
job_result | ||
end | ||
|
||
it_behaves_like 'a solar loader job with loader errors', solar_feed_type: 'Rtone Variant' | ||
end | ||
|
||
context 'with an unexpected exception' do | ||
before do | ||
allow(Solar::RtoneVariantDownloadAndUpsert).to receive(:new).and_raise("Its broken") | ||
#rubocop:disable RSpec/ExpectInHook | ||
expect(Rollbar).to receive(:error).with(anything, job: :import_solar_edge_readings) | ||
#rubocop:enable RSpec/ExpectInHook | ||
job_result | ||
end | ||
|
||
it_behaves_like 'a solar loader job that had an exception', solar_feed_type: 'Rtone Variant' | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.