Skip to content

Commit

Permalink
[CPDLP-3349] Add accepted at date field to applications (#1558)
Browse files Browse the repository at this point in the history
* [CPDLP-3349] Add accepted at date field to applications

* [CPDLP-3349] Fix features specs

* [CPDLP-3349] Address PR comments
  • Loading branch information
leandroalemao authored Aug 7, 2024
1 parent ba055fe commit d8294c9
Show file tree
Hide file tree
Showing 38 changed files with 61 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/serializers/api/participant_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class AttributesSerializer < Blueprinter::Base
targeted_delivery_funding_eligibility: application.targeted_delivery_funding_eligibility,
withdrawal: withdrawal(application:, lead_provider: options[:lead_provider]),
deferral: deferral(application:, lead_provider: options[:lead_provider]),
created_at: application.created_at.rfc3339,
created_at: application.accepted_at.rfc3339,
funded_place: application.funded_place,
}
end
Expand Down
1 change: 1 addition & 0 deletions app/services/applications/accept.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def accept_application!
opts = {
lead_provider_approval_status: "accepted",
schedule:,
accepted_at: Time.zone.now,
}

if cohort&.funding_cap?
Expand Down
2 changes: 1 addition & 1 deletion app/services/participants/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def where_from_participant_id_is(from_participant_id)
end

def order_by
sort_order(sort:, model: User, default: { created_at: :asc })
sort_order(sort:, model: User, default: { accepted_at: :asc })
end

def all_participants
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20240725102353_add_accepted_at_to_applications.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddAcceptedAtToApplications < ActiveRecord::Migration[7.1]
def change
add_column :applications, :accepted_at, :datetime
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2024_07_18_091502) do
ActiveRecord::Schema[7.1].define(version: 2024_07_25_102353) do
# These are extensions that must be enabled in order to support this database
enable_extension "btree_gin"
enable_extension "citext"
Expand Down Expand Up @@ -109,6 +109,7 @@
t.enum "training_status", default: "active", null: false, enum_type: "application_statuses"
t.bigint "schedule_id"
t.string "referred_by_return_to_teaching_adviser"
t.datetime "accepted_at"
t.index ["cohort_id"], name: "index_applications_on_cohort_id"
t.index ["course_id"], name: "index_applications_on_course_id"
t.index ["itt_provider_id"], name: "index_applications_on_itt_provider_id"
Expand Down
1 change: 1 addition & 0 deletions spec/factories/applications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
lead_provider_approval_status { :accepted }
schedule { Schedule.find_by(cohort:, course_group: course.course_group) || create(:schedule, course_group: course.course_group, cohort:) }
funded_place { !!eligible_for_funding }
accepted_at { Time.zone.now }
end

trait :rejected do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def run_scenario(js:)
)

deep_compare_application_data(
"accepted_at" => nil,
"cohort_id" => nil,
"course_id" => Course.find_by(identifier: "npq-senior-leadership").id,
"schedule_id" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def run_scenario(js:)
)

deep_compare_application_data(
"accepted_at" => nil,
"cohort_id" => nil,
"course_id" => Course.find_by(identifier: "npq-headship").id,
"schedule_id" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def run_scenario(js:)
)

deep_compare_application_data(
"accepted_at" => nil,
"cohort_id" => nil,
"course_id" => Course.find_by(identifier: "npq-senior-leadership").id,
"schedule_id" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ def run_scenario(js:)
)

deep_compare_application_data(
"accepted_at" => nil,
"cohort_id" => nil,
"course_id" => Course.find_by(identifier: "npq-senior-leadership").id,
"schedule_id" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ def run_scenario(js:)
)

deep_compare_application_data(
"accepted_at" => nil,
"cohort_id" => nil,
"course_id" => Course.find_by(identifier: "npq-senior-leadership").id,
"schedule_id" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def run_scenario(js:)
)

deep_compare_application_data(
"accepted_at" => nil,
"cohort_id" => nil,
"course_id" => Course.find_by(identifier: "npq-early-years-leadership").id,
"schedule_id" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def run_scenario(js:)
)

deep_compare_application_data(
"accepted_at" => nil,
"cohort_id" => nil,
"course_id" => Course.find_by(identifier: "npq-early-headship-coaching-offer").id,
"schedule_id" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def run_scenario(*)
"uid" => user_uid,
)
deep_compare_application_data(
"accepted_at" => nil,
"cohort_id" => nil,
"course_id" => Course.find_by(identifier: "npq-headship").id,
"schedule_id" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def run_scenario(js:)
)

deep_compare_application_data(
"accepted_at" => nil,
"cohort_id" => nil,
"course_id" => Course.find_by(identifier: "npq-early-headship-coaching-offer").id,
"schedule_id" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def run_scenario(js:)
)

deep_compare_application_data(
"accepted_at" => nil,
"cohort_id" => nil,
"course_id" => Course.find_by(identifier: "npq-senior-leadership").id,
"schedule_id" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def run_scenario(js:)
)

deep_compare_application_data(
"accepted_at" => nil,
"cohort_id" => nil,
"course_id" => Course.find_by(identifier: "npq-senior-leadership").id,
"schedule_id" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def run_scenario(js:)
)

deep_compare_application_data(
"accepted_at" => nil,
"cohort_id" => nil,
"course_id" => Course.find_by(identifier: "npq-headship").id,
"schedule_id" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def run_scenario(js:)
)

deep_compare_application_data(
"accepted_at" => nil,
"cohort_id" => nil,
"course_id" => Course.find_by(identifier: "npq-leading-teaching-development").id,
"schedule_id" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ def run_scenario(*)
)

deep_compare_application_data(
"accepted_at" => nil,
"cohort_id" => nil,
"course_id" => Course.find_by(identifier: "npq-leading-primary-mathematics").id,
"schedule_id" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ def run_scenario(js:)
)

deep_compare_application_data(
"accepted_at" => nil,
"cohort_id" => nil,
"course_id" => Course.find_by(identifier: "npq-headship").id,
"schedule_id" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def run_scenario(js:) # rubocop:disable Lint/UnusedMethodArgument
)

deep_compare_application_data(
"accepted_at" => nil,
"cohort_id" => nil,
"course_id" => Course.find_by(identifier: "npq-senior-leadership").id,
"schedule_id" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def run_scenario(js:)
)

deep_compare_application_data(
"accepted_at" => nil,
"cohort_id" => nil,
"course_id" => Course.find_by(identifier: "npq-senior-leadership").id,
"ecf_id" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def run_scenario(js:)
)

deep_compare_application_data(
"accepted_at" => nil,
"cohort_id" => nil,
"course_id" => Course.find_by(identifier: "npq-early-headship-coaching-offer").id,
"schedule_id" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def run_scenario(js:)
)

deep_compare_application_data(
"accepted_at" => nil,
"cohort_id" => nil,
"course_id" => Course.find_by(identifier: "npq-headship").id,
"schedule_id" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def run_scenario(*)
)

deep_compare_application_data(
"accepted_at" => nil,
"cohort_id" => nil,
"course_id" => Course.find_by(identifier: "npq-senior-leadership").id,
"schedule_id" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def run_scenario(js:)
)

deep_compare_application_data(
"accepted_at" => nil,
"cohort_id" => nil,
"course_id" => Course.find_by(identifier: "npq-early-years-leadership").id,
"schedule_id" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def run_scenario(js:)
)

deep_compare_application_data(
"accepted_at" => nil,
"cohort_id" => nil,
"course_id" => Course.find_by(identifier: "npq-early-years-leadership").id,
"schedule_id" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def run_scenario(js:)
)

deep_compare_application_data(
"accepted_at" => nil,
"cohort_id" => nil,
"course_id" => Course.find_by(identifier: "npq-senior-leadership").id,
"schedule_id" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def run_scenario(*)
)

deep_compare_application_data(
"accepted_at" => nil,
"cohort_id" => nil,
"course_id" => Course.find_by(identifier: "npq-early-years-leadership").id,
"schedule_id" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def run_scenario(js:)
)

deep_compare_application_data(
"accepted_at" => nil,
"cohort_id" => nil,
"course_id" => Course.find_by(identifier: "npq-early-headship-coaching-offer").id,
"schedule_id" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def run_scenario(js:)
)

deep_compare_application_data(
"accepted_at" => nil,
"cohort_id" => nil,
"course_id" => Course.find_by(identifier: "npq-senior-leadership").id,
"schedule_id" => nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def run_scenario
)

deep_compare_application_data(
"accepted_at" => nil,
"cohort_id" => nil,
"course_id" => Course.find_by(identifier: "npq-senior-leadership").id,
"schedule_id" => nil,
Expand Down
2 changes: 2 additions & 0 deletions spec/lib/services/handle_submission_for_store_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def stable_as_json(record)
"work_setting" => "a_school",
"raw_application_data" => store.except("current_user"),
"referred_by_return_to_teaching_adviser" => "no",
"accepted_at" => nil,
})
end
end
Expand Down Expand Up @@ -246,6 +247,7 @@ def stable_as_json(record)
"work_setting" => "early_years_or_childcare",
"raw_application_data" => store.except("current_user"),
"referred_by_return_to_teaching_adviser" => "no",
"accepted_at" => nil,
})
end
end
Expand Down
6 changes: 5 additions & 1 deletion spec/serializers/api/applications_csv_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
it { expect(first_row.values).to all(be_present) }

it "returns expected data", :aggregate_failures do
expect(first_row).to include({
expect(first_row).to eq({
id: first_application.ecf_id,
course_identifier: first_application.course.identifier,
email: first_application.user.email,
email_validated: "true",
Expand All @@ -50,6 +51,9 @@
teacher_catchment_iso_country_code: "GBR",
itt_provider: first_application.itt_provider.legal_name,
lead_mentor: first_application.lead_mentor.to_s,
cohort: first_application.cohort.start_year.to_s,
created_at: first_application.created_at.rfc3339,
updated_at: first_application.updated_at.rfc3339,
})
end

Expand Down
6 changes: 3 additions & 3 deletions spec/serializers/api/participant_serializer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
targeted_delivery_funding_eligibility: application.targeted_delivery_funding_eligibility,
withdrawal: nil,
deferral: nil,
created_at: application.created_at.rfc3339,
created_at: application.accepted_at.rfc3339,
funded_place: application.funded_place,
}.stringify_keys,
])
Expand All @@ -155,7 +155,7 @@
date: application.application_states.last.created_at.rfc3339,
},
deferral: nil,
created_at: application.created_at.rfc3339,
created_at: application.accepted_at.rfc3339,
funded_place: application.funded_place,
}.deep_stringify_keys,
])
Expand All @@ -182,7 +182,7 @@
reason: application.application_states.last.reason,
date: application.application_states.last.created_at.rfc3339,
},
created_at: application.created_at.rfc3339,
created_at: application.accepted_at.rfc3339,
funded_place: application.funded_place,
}.deep_stringify_keys,
])
Expand Down
3 changes: 3 additions & 0 deletions spec/services/applications/accept_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
it "rejects other_application" do
service.accept
expect(application.reload.lead_provider_approval_status).to eql("accepted")
expect(application.reload.accepted_at).to be_within(1.minute).of(Time.zone.now)
expect(other_application.reload.lead_provider_approval_status).to eql("rejected")
end
end
Expand Down Expand Up @@ -194,6 +195,7 @@
it "does not reject the other course" do
service.accept
expect(application.reload.lead_provider_approval_status).to eql("accepted")
expect(application.reload.accepted_at).to be_within(1.minute).of(Time.zone.now)
expect(other_application.reload.lead_provider_approval_status).to eql("pending")
end
end
Expand Down Expand Up @@ -357,6 +359,7 @@
expect(service.accept).to be_truthy
expect(service.application.lead_provider_approval_status).to eql("accepted")
expect(service.application.schedule).to eql(new_schedule)
expect(service.application.accepted_at).to be_within(1.minute).of(Time.zone.now)

application_state = ApplicationState.first
expect(application_state.lead_provider).to eql(lead_provider)
Expand Down
12 changes: 10 additions & 2 deletions spec/services/participants/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
expect(query.participants).to contain_exactly(participant1, participant2)
end

it "orders participants by created_at in ascending order" do
it "orders participants by accepted_at in ascending order" do
participant3 = travel_to(1.minute.ago) { create(:user, :with_application, lead_provider:) }

expect(query.participants).to eq([participant3, participant1, participant2])
Expand Down Expand Up @@ -183,7 +183,15 @@

subject(:participants) { query.participants }

it { is_expected.to eq([participant1, participant2, participant3]) }
before do
participant1.applications.first.update!(accepted_at: 1.day.ago)
participant2.applications.first.update!(accepted_at: 10.days.ago)
participant3.applications.first.update!(accepted_at: 2.days.ago)
end

it "orders applications by accepted_at in ascending order" do
expect(query.participants).to eq([participant2, participant3, participant1])
end

context "when sorting by created at, descending" do
let(:sort) { "-created_at" }
Expand Down

0 comments on commit d8294c9

Please sign in to comment.