Browse Source
* Empty commit * CLDC-3224: Parse noint correctly in bulk upload row parsers * CLDC-3224: Add task to fix previous noint data * CLDC-3224: Remove nonsensical value for noint field in bu test * CLDC-3224: Move where bulk upload noint fix status is set to ensure it matches processing version * Put BU noint_fix_status setting before creating any logspull/2259/head v0.4.19
Rachael Booth
10 months ago
committed by
GitHub
16 changed files with 164 additions and 9 deletions
@ -0,0 +1,5 @@ |
|||||||
|
class AddNoIntFixMarkerToBulkUploads < ActiveRecord::Migration[7.0] |
||||||
|
def change |
||||||
|
add_column :bulk_uploads, :noint_fix_status, :string, default: "not_applied" |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,24 @@ |
|||||||
|
desc "Alter noint values for bulk uploaded sales logs where these have not been set in the service" |
||||||
|
task correct_noint_value: :environment do |
||||||
|
update_counts = { |
||||||
|
in_progress: 0, |
||||||
|
completed: 0, |
||||||
|
pending: 0, |
||||||
|
deleted: 0, |
||||||
|
} |
||||||
|
affected_uploads = BulkUpload.where(log_type: "sales", noint_fix_status: BulkUpload.noint_fix_statuses[:not_applied]) |
||||||
|
affected_uploads.each do |upload| |
||||||
|
upload.logs.where(noint: 2).each do |log| |
||||||
|
noint_at_upload = log.versions.length == 1 ? log.noint : log.versions.first.next.reify.noint |
||||||
|
next unless noint_at_upload == 2 |
||||||
|
|
||||||
|
Rails.logger.info("Updating noint value on log #{log.id}, owning org #{log.owning_organisation_id}") |
||||||
|
update_counts[log.status.to_sym] += 1 |
||||||
|
log.noint = 1 |
||||||
|
log.skip_update_status = true |
||||||
|
log.save! |
||||||
|
end |
||||||
|
upload.update!(noint_fix_status: BulkUpload.noint_fix_statuses[:applied]) |
||||||
|
end |
||||||
|
Rails.logger.info("Logs updated; #{update_counts}") |
||||||
|
end |
@ -0,0 +1,87 @@ |
|||||||
|
require "rails_helper" |
||||||
|
require "rake" |
||||||
|
|
||||||
|
RSpec.describe "correct_noint_value" do |
||||||
|
describe ":correct_noint_value", type: :task do |
||||||
|
subject(:task) { Rake::Task["correct_noint_value"] } |
||||||
|
|
||||||
|
before do |
||||||
|
Rake.application.rake_require("tasks/correct_noint_value") |
||||||
|
Rake::Task.define_task(:environment) |
||||||
|
task.reenable |
||||||
|
end |
||||||
|
|
||||||
|
context "when the rake task is run" do |
||||||
|
context "and there is a sales bulk upload with the fix needed" do |
||||||
|
let(:bulk_upload) { create(:bulk_upload, :sales, noint_fix_status: BulkUpload.noint_fix_statuses[:not_applied]) } |
||||||
|
|
||||||
|
before do |
||||||
|
bulk_upload.save! |
||||||
|
end |
||||||
|
|
||||||
|
it "updates the noint value on a log with noint = 2 where it was set to 2 on create" do |
||||||
|
log = create(:sales_log, :completed, noint: 2, bulk_upload:) |
||||||
|
|
||||||
|
task.invoke |
||||||
|
log.reload |
||||||
|
|
||||||
|
expect(log.noint).to be(1) |
||||||
|
end |
||||||
|
|
||||||
|
it "updates the noint value on a log with noint = 2 where it was set to 2 on create and other fields have since changed" do |
||||||
|
log = create(:sales_log, :in_progress, noint: 2, bulk_upload:) |
||||||
|
log.update!(status: Log.statuses[:completed]) |
||||||
|
|
||||||
|
task.invoke |
||||||
|
log.reload |
||||||
|
|
||||||
|
expect(log.noint).to be(1) |
||||||
|
end |
||||||
|
|
||||||
|
it "does not update the noint value on a log that has noint = 1" do |
||||||
|
log = create(:sales_log, :completed, noint: 2, bulk_upload:) |
||||||
|
log.update!(noint: 1) |
||||||
|
|
||||||
|
task.invoke |
||||||
|
log.reload |
||||||
|
|
||||||
|
expect(log.noint).to be(1) |
||||||
|
end |
||||||
|
|
||||||
|
it "does not update the noint value on a log with noint = 2 where noint was nil on create" do |
||||||
|
log = create(:sales_log, :completed, noint: nil, bulk_upload:) |
||||||
|
log.update!(noint: 2) |
||||||
|
|
||||||
|
task.invoke |
||||||
|
log.reload |
||||||
|
|
||||||
|
expect(log.noint).to be(2) |
||||||
|
end |
||||||
|
|
||||||
|
it "updates the noint_fix_status value on the bulk upload" do |
||||||
|
task.invoke |
||||||
|
bulk_upload.reload |
||||||
|
|
||||||
|
expect(bulk_upload.noint_fix_status).to eq(BulkUpload.noint_fix_statuses[:applied]) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "and there is a sales bulk upload with the fix marked as not needed" do |
||||||
|
let(:bulk_upload) { create(:bulk_upload, :sales, noint_fix_status: BulkUpload.noint_fix_statuses[:not_needed]) } |
||||||
|
|
||||||
|
before do |
||||||
|
bulk_upload.save! |
||||||
|
end |
||||||
|
|
||||||
|
it "does not update the noint values on logs" do |
||||||
|
log = create(:sales_log, :completed, noint: 2, bulk_upload:) |
||||||
|
|
||||||
|
task.invoke |
||||||
|
log.reload |
||||||
|
|
||||||
|
expect(log.noint).to be(2) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue