Skip to content

feat: add new unit test to check if request data is formatted in updateCourseAdvancedSettings #2193

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jignaciopm
Copy link
Contributor

@jignaciopm jignaciopm commented Jun 19, 2025

Description

This PR adds a unit test to check whether the request body of updateCourseAdvancedSettings is formatted in snake_case.

Supporting information

This PR is based on the suggestion in this comment

Testing instructions

N/A

Other information

N/A

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Jun 19, 2025
@openedx-webhooks
Copy link

Thanks for the pull request, @jignaciopm!

This repository is currently maintained by @bradenmacdonald.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.


Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

Copy link

codecov bot commented Jun 19, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.09%. Comparing base (920f4a5) to head (a4d76e2).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2193      +/-   ##
==========================================
- Coverage   94.09%   94.09%   -0.01%     
==========================================
  Files        1164     1164              
  Lines       24493    24493              
  Branches     5196     5195       -1     
==========================================
- Hits        23047    23046       -1     
- Misses       1378     1379       +1     
  Partials       68       68              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jignaciopm
Copy link
Contributor Author

jignaciopm commented Jun 19, 2025

@bradenmacdonald @arbrandes What do you think? Does it make sense to you?

Copy link
Contributor

@bradenmacdonald bradenmacdonald left a comment

Choose a reason for hiding this comment

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

I don't think this test is particularly realistic.

I was thinking something like this:

  1. Create a mock based on the actual data from the API
{
    "display_name": {
        "value": "Test Course Name",
        "display_name": "Course Display Name",
        "help": "Enter the name of the course as it should appear in the course list.",
        "deprecated": false,
        "hide_on_enabled_publisher": false
    },
    "course_edit_method": {
        "value": "Studio",
        "display_name": "Course Editor",
        "help": "Enter the method by which this course is edited (\"XML\" or \"Studio\").",
        "deprecated": true,
        "hide_on_enabled_publisher": false
    },
    "showanswer": {
        "value": "after_all_attempts_or_correct",
        "display_name": "Show Answer",
        "help": "Specify when the Show Answer button appears for each problem. Valid values are \"always\", \"answered\", \"attempted\", \"closed\", \"finished\", \"past_due\", \"correct_or_past_due\", \"after_all_attempts\", \"after_all_attempts_or_correct\", \"attempted_no_past_due\", and \"never\".",
        "deprecated": false,
        "hide_on_enabled_publisher": false
    },
    "advanced_modules": {
        "value": ["poll", "lti_consumer", "survey", "google-document"],
        "display_name": "Advanced Module List",
        "help": "Enter the names of the advanced modules to use in your course.",
        "deprecated": false,
        "hide_on_enabled_publisher": false
    },
    "cert_html_view_overrides": {
        "value": {
            "accomplishment_banner_opening": "{fullname}, congrats on this certificate!",
            "camelCaseKey": "camel case keys should be preserved if used",
        },
        "display_name": "Certificate Web/HTML View Overrides",
        "help": "Enter course-specific overrides for the Web/HTML template parameters here (JSON format)",
        "deprecated": false,
        "hide_on_enabled_publisher": false
    }
}
  1. Mock the HTTP endpoint for /api/contentstore/v0/advanced_settings/:course_id with that value
  2. Call getCourseAdvancedSettings(), modify one or two values.
  3. Call updateCourseAdvancedSettings() with the new values.
  4. Assert that it calls the axios POST mock with the exact same data as in the mock (1) except for the changed values.

The mock includes: plain values, object values, deprecated value, and a JSON object value with both snake_case and camelCase so it should be a thorough test.

Then we can use the same mock to create an accurate test on the settings page itself: mock the endpoint, render the settings UI, make a couple changes, "click" on the Save button, and assert that the POST request to the server matches the original mock exactly except for the changes.

What do you think?

test_camel_case: { value: 'To come snake_case' },
pascal_case: { value: true },
kebab_case: {
value: { nestedOption: 'This key must not be formatted' },
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we have a value with a nested option in snake_case ?

@mphilbrick211 mphilbrick211 moved this from Needs Triage to In Eng Review in Contributions Jun 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
Status: In Eng Review
Development

Successfully merging this pull request may close these issues.

3 participants