Skip to content

Send email domains to profile#802

Open
PetarSimonovic wants to merge 2 commits intomainfrom
send-email-domains-to-profile
Open

Send email domains to profile#802
PetarSimonovic wants to merge 2 commits intomainfrom
send-email-domains-to-profile

Conversation

@PetarSimonovic
Copy link
Copy Markdown

@PetarSimonovic PetarSimonovic commented May 1, 2026

Status

What's changed?

  • Add an update_school_email_domains method to ProfileApiClient
  • Create an UpdateSchoolEmailDomains job
  • Update tests and mocks

Manual testing

Prerequisites

Run Profile on the school-domains-api branch.

Run editor-api.

Run editor-standalone.

Profile seeds its db with a school, alongside two users that have the owner and teacher roles required to update the school's email domains.

The school should have nothing in its studentEmailDomains column.

Steps

  1. In the editor UI, sign in as ms.teacher@example.com.

  2. From the editor-api repo, open a console in Docker: docker compose run --rm api rails console

  3. In the browser, open DevTools → Application → Local Storage for the editor and copy the access_token (it should start with ory_at_...

  4. In the console, call ProfileApiClient.update_school_email_domains with:

  • token: — the access_token (string)
  • school_id: — the id of the school in Profile
  • school_email_domains: — an array of hostnames, e.g. ["atestdomain.edu", "anotherdomain.co.uk"].

In Profile, inspect that school again: studentEmailDomains should now list those domains.

@cla-bot cla-bot Bot added the cla-signed label May 1, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

Test coverage

89.35% line coverage reported by SimpleCov.
Run: https://github.com/RaspberryPiFoundation/editor-api/actions/runs/25377557223

@PetarSimonovic PetarSimonovic force-pushed the send-email-domains-to-profile branch 2 times, most recently from 0de41bc to 615dfc5 Compare May 1, 2026 10:11
Comment on lines +603 to +606
it 'does not make a request to Profile API' do
update_school_email_domains_response
expect(WebMock).not_to have_requested(:patch, update_school_email_domains_url)
end
Copy link
Copy Markdown
Author

@PetarSimonovic PetarSimonovic May 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using WebMock rather than expanding ProfileApiMock given the TODO comment at the top of that module

@PetarSimonovic PetarSimonovic force-pushed the send-email-domains-to-profile branch 3 times, most recently from 9570e79 to 224d636 Compare May 5, 2026 10:43
@PetarSimonovic PetarSimonovic temporarily deployed to editor-api-p-send-email-9rqwh6 May 5, 2026 10:43 Inactive
@PetarSimonovic PetarSimonovic force-pushed the send-email-domains-to-profile branch from 224d636 to 99f5e7b Compare May 5, 2026 10:53
@PetarSimonovic PetarSimonovic temporarily deployed to editor-api-p-send-email-9rqwh6 May 5, 2026 10:53 Inactive
@PetarSimonovic PetarSimonovic force-pushed the send-email-domains-to-profile branch from 99f5e7b to 336bf32 Compare May 5, 2026 11:02
@PetarSimonovic PetarSimonovic temporarily deployed to editor-api-p-send-email-9rqwh6 May 5, 2026 11:03 Inactive
Allow the client to PATCH a collection of domains
@PetarSimonovic PetarSimonovic force-pushed the send-email-domains-to-profile branch from 336bf32 to 9d1fef8 Compare May 5, 2026 12:32
@PetarSimonovic PetarSimonovic temporarily deployed to editor-api-p-send-email-loanju May 5, 2026 12:33 Inactive
@PetarSimonovic PetarSimonovic marked this pull request as ready for review May 5, 2026 12:38
Copilot AI review requested due to automatic review settings May 5, 2026 12:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the Profile integration so editor-api can send a school's student email domains to Profile, both when creating school payloads and via a new dedicated update path. It mainly adds the client/job plumbing needed for that Profile-side field and updates test fixtures to match the new school response shape.

Changes:

  • Add studentEmailDomains to the ProfileApiClient::School payload/response handling.
  • Add ProfileApiClient.update_school_email_domains plus a new UpdateSchoolEmailDomainsJob.
  • Update specs and mocks for the new school payload shape and PATCH endpoint.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
spec/support/profile_api_mock.rb Updates the Profile mock school object to include studentEmailDomains.
spec/lib/profile_api_client_spec.rb Extends client specs for the new school field and adds PATCH coverage for updating email domains.
spec/jobs/update_school_email_domains_job_spec.rb Adds job specs for PATCH behavior and GoodJob concurrency key generation.
lib/profile_api_client.rb Adds the new school field, sends it during create, and implements the PATCH client method.
app/jobs/update_school_email_domains_job.rb Introduces a background job to send school email-domain updates to Profile with retry/concurrency settings.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/jobs/update_school_email_domains_job.rb
Comment on lines +14 to +17
retry_on StandardError, wait: :polynomially_longer, attempts: 3 do |_job, e|
Sentry.capture_exception(e)
raise e
end
Comment thread lib/profile_api_client.rb

# rubocop:disable Naming/MethodName
School = Data.define(:id, :schoolCode, :updatedAt, :createdAt, :discardedAt)
School = Data.define(:id, :schoolCode, :studentEmailDomains, :updatedAt, :createdAt, :discardedAt)
Comment thread spec/jobs/update_school_email_domains_job_spec.rb Outdated
Comment on lines +70 to +72
it 'sends the school id, code and studentEmailDomains in the request body as json' do
create_school_response
expected_body = { id: school.id, schoolCode: school.code }.to_json
expected_body = { id: school.id, schoolCode: school.code, studentEmailDomains: [] }.to_json
Set up a job to update Profile's school email domains
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants