|
58 | 58 | stub_request(:post, create_school_url) |
59 | 59 | .to_return( |
60 | 60 | status: 201, |
61 | | - body: '{"id":"","schoolCode":"","updatedAt":"","createdAt":"","discardedAt":""}', |
| 61 | + body: '{"id":"","schoolCode":"","updatedAt":"","createdAt":"","discardedAt":"","studentEmailDomains":[]}', |
62 | 62 | headers: { 'content-type' => 'application/json' } |
63 | 63 | ) |
64 | 64 | end |
|
67 | 67 | it_behaves_like 'a request that handles standard HTTP errors', :post, url: -> { create_school_url } |
68 | 68 | it_behaves_like 'a request that handles an unexpected response status', :post, url: -> { "#{api_url}/api/v1/schools" }, status: 200 |
69 | 69 |
|
70 | | - it 'sends the school id and code in the request body as json' do |
| 70 | + it 'sends the school id, code and studentEmailDomains in the request body as json' do |
71 | 71 | create_school_response |
72 | | - expected_body = { id: school.id, schoolCode: school.code }.to_json |
| 72 | + expected_body = { id: school.id, schoolCode: school.code, studentEmailDomains: [] }.to_json |
73 | 73 | expect(WebMock).to have_requested(:post, create_school_url).with(body: expected_body) |
74 | 74 | end |
75 | 75 |
|
76 | 76 | it 'returns the created school if successful' do |
77 | | - data = { id: 'id', schoolCode: 'code', updatedAt: '2024-07-09T10:31:13.196Z', createdAt: '2024-07-09T10:31:13.196Z', discardedAt: nil } |
| 77 | + data = { id: 'id', schoolCode: 'code', updatedAt: '2024-07-09T10:31:13.196Z', createdAt: '2024-07-09T10:31:13.196Z', discardedAt: nil, |
| 78 | + studentEmailDomains: [] } |
78 | 79 | expected = ProfileApiClient::School.new(**data) |
79 | 80 | stub_request(:post, create_school_url) |
80 | 81 | .to_return(status: 201, body: data.to_json, headers: { 'Content-Type' => 'application/json' }) |
|
91 | 92 | expect(WebMock).not_to have_requested(:post, create_school_url) |
92 | 93 | end |
93 | 94 |
|
94 | | - it 'returns the id and code of the school supplied' do |
95 | | - expected = { 'id' => school.id, 'schoolCode' => school.code } |
| 95 | + it 'returns the id, code and email domains of the school supplied' do |
| 96 | + expected = { 'id' => school.id, 'schoolCode' => school.code, 'studentEmailDomains' => [] } |
96 | 97 | expect(create_school_response).to eq(expected) |
97 | 98 | end |
98 | 99 | end |
@@ -558,4 +559,62 @@ def school_student |
558 | 559 | described_class.school_student(token:, school_id: school.id, student_id:) |
559 | 560 | end |
560 | 561 | end |
| 562 | + |
| 563 | + describe '.update_school_email_domains' do |
| 564 | + subject(:update_school_email_domains_response) { update_school_email_domains } |
| 565 | + |
| 566 | + let(:school) { build(:school, id: SecureRandom.uuid, code: SecureRandom.uuid) } |
| 567 | + let(:update_school_email_domains_url) { "#{api_url}/api/v1/schools/#{school.id}" } |
| 568 | + let(:school_email_domains) { ['student.example.edu', 'mail.example.org'] } |
| 569 | + |
| 570 | + before do |
| 571 | + stub_request(:patch, update_school_email_domains_url) |
| 572 | + .to_return( |
| 573 | + status: 201, |
| 574 | + body: '{"id":"","schoolCode":"","updatedAt":"","createdAt":"","discardedAt":"","studentEmailDomains":[]}', |
| 575 | + headers: { 'content-type' => 'application/json' } |
| 576 | + ) |
| 577 | + end |
| 578 | + |
| 579 | + it_behaves_like 'an authenticated JSON API request', :patch, url: -> { update_school_email_domains_url } |
| 580 | + it_behaves_like 'a request that handles standard HTTP errors', :patch, url: -> { update_school_email_domains_url } |
| 581 | + it_behaves_like 'a request that handles an unexpected response status', :patch, url: -> { "#{api_url}/api/v1/schools/#{school.id}" }, status: 200 |
| 582 | + |
| 583 | + it 'sends studentEmailDomains in the JSON body' do |
| 584 | + update_school_email_domains_response |
| 585 | + expected_body = { studentEmailDomains: school_email_domains }.to_json |
| 586 | + expect(WebMock).to have_requested(:patch, update_school_email_domains_url).with(body: expected_body) |
| 587 | + end |
| 588 | + |
| 589 | + it 'returns a school if successful' do |
| 590 | + data = { id: 'id', schoolCode: 'code', updatedAt: '2024-07-09T10:31:13.196Z', createdAt: '2024-07-09T10:31:13.196Z', discardedAt: nil, |
| 591 | + studentEmailDomains: school_email_domains } |
| 592 | + expected = ProfileApiClient::School.new(**data) |
| 593 | + stub_request(:patch, update_school_email_domains_url) |
| 594 | + .to_return(status: 200, body: data.to_json, headers: { 'Content-Type' => 'application/json' }) |
| 595 | + expect(update_school_email_domains_response).to eq(expected) |
| 596 | + end |
| 597 | + |
| 598 | + describe 'when BYPASS_OAUTH is true' do |
| 599 | + before do |
| 600 | + allow(ENV).to receive(:[]).with('BYPASS_OAUTH').and_return(true) |
| 601 | + end |
| 602 | + |
| 603 | + it 'does not make a request to Profile API' do |
| 604 | + update_school_email_domains_response |
| 605 | + expect(WebMock).not_to have_requested(:patch, update_school_email_domains_url) |
| 606 | + end |
| 607 | + |
| 608 | + it 'returns the id and email domains of the school supplied' do |
| 609 | + expected = { 'id' => school.id, 'studentEmailDomains' => school_email_domains } |
| 610 | + expect(update_school_email_domains_response).to eq(expected) |
| 611 | + end |
| 612 | + end |
| 613 | + |
| 614 | + private |
| 615 | + |
| 616 | + def update_school_email_domains |
| 617 | + described_class.update_school_email_domains(token:, school_id: school.id, school_email_domains:) |
| 618 | + end |
| 619 | + end |
561 | 620 | end |
0 commit comments