-
Notifications
You must be signed in to change notification settings - Fork 482
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17422 from code-dot-org/persist_school_district_data
Persist school district data
- Loading branch information
Showing
8 changed files
with
228 additions
and
8 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
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
43 changes: 43 additions & 0 deletions
43
dashboard/test/controllers/api/v1/pd/regional_partner_contacts_controller_test.rb
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,43 @@ | ||
require 'test_helper' | ||
|
||
class Api::V1::Pd::RegionalPartnerContactsControllerTest < ::ActionController::TestCase | ||
SAMPLE_FORM_DATA = { | ||
first_name: 'Harry', | ||
last_name: 'Potter', | ||
title: 'Mr.', | ||
email: 'potter@hogwarts.edu', | ||
role: 'Teacher', | ||
job_title: 'Defense against dark arts', | ||
grade_levels: ['High School'], | ||
school_type: 'public', | ||
school_state: 'NY', | ||
school_district_other: true, | ||
school_district_name: 'Hogwarts' | ||
} | ||
|
||
test 'create creates a new regional partner contact' do | ||
assert_creates Pd::RegionalPartnerContact do | ||
put :create, params: { | ||
form_data: SAMPLE_FORM_DATA | ||
} | ||
end | ||
|
||
assert_response :created | ||
end | ||
|
||
test 'create returns appropriate errors if school district data is missing' do | ||
new_form = SAMPLE_FORM_DATA.dup | ||
new_form.delete :school_district_name | ||
|
||
assert_does_not_create Pd::RegionalPartnerContact do | ||
put :create, params: { | ||
form_data: new_form | ||
} | ||
end | ||
|
||
assert_response :bad_request | ||
response_body = JSON.parse(@response.body) | ||
|
||
assert_equal 'Please fill out data for your school district', response_body['general_error'] | ||
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,94 @@ | ||
require 'test_helper' | ||
|
||
class Pd::RegionalPartnerContactTest < ActiveSupport::TestCase | ||
test 'Test district validation' do | ||
contact = build :pd_regional_partner_contact, form_data: {}.to_json | ||
refute contact.valid? | ||
|
||
form_data = { | ||
first_name: 'firstName', | ||
last_name: 'lastName', | ||
title: 'Dr.', | ||
email: 'email', | ||
role: 'School Administrator', | ||
job_title: 'title', | ||
grade_levels: ['High School'], | ||
school_state: 'NY' | ||
} | ||
|
||
refute build(:pd_regional_partner_contact, form_data: form_data.to_json).valid? | ||
|
||
refute build( | ||
:pd_regional_partner_contact, form_data: form_data.merge( | ||
{ | ||
school_type: 'public', | ||
} | ||
).to_json | ||
).valid? | ||
|
||
refute build( | ||
:pd_regional_partner_contact, form_data: form_data.merge( | ||
{ | ||
school_type: 'private', | ||
} | ||
).to_json | ||
).valid? | ||
|
||
refute build( | ||
:pd_regional_partner_contact, form_data: form_data.merge( | ||
{ | ||
school_type: 'public', | ||
school_district_other: true | ||
} | ||
).to_json | ||
).valid? | ||
|
||
refute build( | ||
:pd_regional_partner_contact, form_data: form_data.merge( | ||
{ | ||
school_type: 'public', | ||
school_district_other: false | ||
} | ||
).to_json | ||
).valid? | ||
|
||
assert build( | ||
:pd_regional_partner_contact, form_data: form_data.merge( | ||
{ | ||
school_type: 'public', | ||
school_district_other: true, | ||
school_district_name: 'District name' | ||
} | ||
).to_json | ||
).valid? | ||
|
||
assert build( | ||
:pd_regional_partner_contact, form_data: form_data.merge( | ||
{ | ||
school_type: 'public', | ||
school_district_other: false, | ||
school_district: 'District' | ||
} | ||
).to_json | ||
).valid? | ||
|
||
refute build( | ||
:pd_regional_partner_contact, form_data: form_data.merge( | ||
{ | ||
school_type: 'private', | ||
school_name: 'Name' | ||
} | ||
).to_json | ||
).valid? | ||
|
||
assert build( | ||
:pd_regional_partner_contact, form_data: form_data.merge( | ||
{ | ||
school_type: 'private', | ||
school_name: 'Name', | ||
school_zipcode: 'Zipcode' | ||
} | ||
).to_json | ||
).valid? | ||
end | ||
end |