Skip to content

Make profile api client more robust#824

Open
zetter-rpf wants to merge 3 commits into
mainfrom
make-profile-api-client-more-robust
Open

Make profile api client more robust#824
zetter-rpf wants to merge 3 commits into
mainfrom
make-profile-api-client-more-robust

Conversation

@zetter-rpf
Copy link
Copy Markdown
Contributor

@zetter-rpf zetter-rpf commented May 19, 2026

Status

What's changed?

The error was caused by editor-api erroring when unexpected keys were added in the profile API response.

I think generally JSON APIs should be able to add more attributes without breaking clients.

  • Remove the profile API response objects that aren't used
  • Remove profile API safeguarding_flags methods that aren't used
  • Make profile API response succeed even if new keys are added.

See commits for more

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

github-actions Bot commented May 19, 2026

Test coverage

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

This isn't used anywhere and makes the code brittle as it will fail if new attributes are added to profile
It looks like were not using this, so remove it
It's common when developing with APIs to add in new keys to the response
if this happens we don't want this code to error.
@PetarSimonovic PetarSimonovic force-pushed the make-profile-api-client-more-robust branch from d80bf88 to 2c57635 Compare May 19, 2026 15:52
@zetter-rpf zetter-rpf marked this pull request as ready for review May 19, 2026 15:54
Copilot AI review requested due to automatic review settings May 19, 2026 15:54
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

Makes the ProfileApiClient more robust against changes in the upstream profile API by removing unused response struct definitions/methods and ignoring unexpected keys in student responses.

Changes:

  • Remove unused School and SafeguardingFlag Data structs and the safeguarding_flags method, simplifying create_school and update_school_email_domains to return true.
  • Filter response keys in build_student to only known Student members so extra keys from the profile API don't raise.
  • Update specs and the stub_profile_api_create_school test helper to match the new return values and add a regression test for unexpected keys.

Reviewed changes

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

File Description
lib/profile_api_client.rb Drops unused School/SafeguardingFlag structs and safeguarding_flags method; returns true from create_school/update_school_email_domains; slices unknown keys in build_student.
spec/lib/profile_api_client_spec.rb Updates tests to assert true return values, removes the .safeguarding_flags describe block, and adds a test for unexpected keys in student responses.
spec/support/profile_api_mock.rb Simplifies stub_profile_api_create_school to stub a true return and drop the School struct construction.

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

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.

3 participants