Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Withdrawing or Declining your seat in the Teachercon registration will also update your application #19961

Merged
merged 4 commits into from
Jan 16, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export default class Joining extends Teachercon1819FormComponent {
</ul>
{this.radioButtonsFor("teacherAcceptSeat")}
{(
this.props.data.teacherAcceptSeat === TeacherSeatAcceptanceOptions.withdrawDate ||
this.props.data.teacherAcceptSeat === TeacherSeatAcceptanceOptions.withdrawOther
this.props.data.teacherAcceptSeat === TeacherSeatAcceptanceOptions.waitlistDate ||
this.props.data.teacherAcceptSeat === TeacherSeatAcceptanceOptions.waitlistOther
) &&
<FormGroup>
<p>
Expand Down
30 changes: 28 additions & 2 deletions dashboard/app/models/pd/teachercon1819_registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ class Pd::Teachercon1819Registration < ActiveRecord::Base
YES_OR_NO = [YES, NO].freeze
OTHER = 'Other'.freeze

after_create :update_application_status
def update_application_status
if waitlisted?
pd_application.update!(status: "waitlisted")
elsif declined?
pd_application.update!(status: "withdrawn")
end
end

def self.options
{
dietaryNeeds: [
Expand All @@ -49,8 +58,8 @@ def self.options
needAda: [YES, NO, 'Other (please explain):'],
teacherAcceptSeat: [
TEACHER_SEAT_ACCEPTANCE_OPTIONS[:accept],
TEACHER_SEAT_ACCEPTANCE_OPTIONS[:withdraw_date],
TEACHER_SEAT_ACCEPTANCE_OPTIONS[:withdraw_other],
TEACHER_SEAT_ACCEPTANCE_OPTIONS[:waitlist_date],
TEACHER_SEAT_ACCEPTANCE_OPTIONS[:waitlist_other],
TEACHER_SEAT_ACCEPTANCE_OPTIONS[:decline],
],
photoRelease: [YES],
Expand Down Expand Up @@ -109,4 +118,21 @@ def dynamic_required_fields(hash)

return requireds
end

def accepted?
accept_status == TEACHER_SEAT_ACCEPTANCE_OPTIONS[:accept]
end

def waitlisted?
accept_status == TEACHER_SEAT_ACCEPTANCE_OPTIONS[:waitlist_date] ||
accept_status == TEACHER_SEAT_ACCEPTANCE_OPTIONS[:waitlist_other]
end

def declined?
accept_status == TEACHER_SEAT_ACCEPTANCE_OPTIONS[:decline]
end

def accept_status
sanitize_form_data_hash.try(:[], :teacher_accept_seat)
end
end
37 changes: 25 additions & 12 deletions dashboard/test/factories/pd_factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -785,20 +785,21 @@

factory :pd_teachercon1819_registration_hash, class: 'Hash' do
transient do
accepted true
full_form_data true
end

# default to accepted
initialize_with do
{
email: "ssnape@hogwarts.edu",
preferredFirstName: "Sevvy",
lastName: "Snape",
phone: "5558675309",
teacherAcceptSeat: "Yes, I accept my seat in the Professional Learning Program"
}.tap do |hash|
if accepted
if full_form_data
hash.merge!(
{
teacherAcceptSeat: "Yes, I accept my seat in the Professional Learning Program",
addressCity: "Albuquerque",
addressState: "Alabama",
addressStreet: "123 Street Ave",
Expand All @@ -817,22 +818,34 @@
photoRelease: "Yes",
}
)
else
hash.merge!(
{
teacherAcceptSeat: "No, I decline my seat in the Professional Learning Program.",
}
)
end
end.stringify_keys
end

trait :accepted do
# accepted is the default, trait included here just for completeness
end

trait :withdrawn do
full_form_data false
after :build do |hash|
hash['teacherAcceptSeat'] = "No, I decline my seat in the Professional Learning Program."
end
end

trait :waitlisted do
after :build do |hash|
hash['teacherAcceptSeat'] = "Yes, I want to participate, but I'm unable to attend my assigned summer workshop date. Please place me on your waitlist. I understand that I am not guaranteed a space in a different summer workshop."
end
end
end

factory :pd_teachercon1819_registration, class: 'Pd::Teachercon1819Registration' do
association :pd_application, factory: :pd_teacher1819_application
transient do
accepted false
hash_trait :accepted
end
form_data {build(:pd_teachercon1819_registration_hash, accepted: accepted).to_json}

association :pd_application, factory: :pd_teacher1819_application
form_data {build(:pd_teachercon1819_registration_hash, hash_trait).to_json}
end
end
18 changes: 17 additions & 1 deletion dashboard/test/models/pd/teachercon1819_registration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,26 @@ class Pd::Teachercon1819RegistrationTest < ActiveSupport::TestCase
end

test 'declined application requires fewer fields' do
registration = create(:pd_teachercon1819_registration, accepted: false)
registration = create(:pd_teachercon1819_registration, hash_trait: :withdrawn)

assert registration.valid?
refute registration.sanitize_form_data_hash.key?(:contact_first_name)
refute registration.sanitize_form_data_hash.key?(:dietary_needs)
end

test 'waitlisting or withdrawing in the registration will also update the application' do
%w(
accepted
waitlisted
withdrawn
).each do |status|
application = create(:pd_teacher1819_application)
application.status = "accepted"
application.lock!

create(:pd_teachercon1819_registration, pd_application: application, hash_trait: status.to_sym)

assert_equal application.reload.status, status
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Teachercon1819RegistrationConstants
TEACHER_SEAT_ACCEPTANCE_OPTIONS = {
accept: "Yes, I accept my seat in the Professional Learning Program",
decline: "No, I decline my seat in the Professional Learning Program.",
withdraw_date: "Yes, I want to participate, but I'm unable to attend my assigned summer workshop date. Please place me on your waitlist. I understand that I am not guaranteed a space in a different summer workshop.",
withdraw_other: "Yes, I want to participate, but I'm not able to for a different reason. Please place me on your waitlist. I understand that I am not guaranteed a space in a different summer workshop.",
waitlist_date: "Yes, I want to participate, but I'm unable to attend my assigned summer workshop date. Please place me on your waitlist. I understand that I am not guaranteed a space in a different summer workshop.",
waitlist_other: "Yes, I want to participate, but I'm not able to for a different reason. Please place me on your waitlist. I understand that I am not guaranteed a space in a different summer workshop.",
}
end