Skip to content

Swap out the API used for enrollments for program-related enrollments#3066

Open
jkachel wants to merge 6 commits intomainfrom
jkachel/10559-verified-prog-enrollments-needs-different-api
Open

Swap out the API used for enrollments for program-related enrollments#3066
jkachel wants to merge 6 commits intomainfrom
jkachel/10559-verified-prog-enrollments-needs-different-api

Conversation

@jkachel
Copy link
Contributor

@jkachel jkachel commented Mar 18, 2026

What are the relevant tickets?

Closes mitodl/hq#10559

Description (What does it do?)

If we're creating an enrollment for a course that's within a program it's better that we use the "one-click" API, so that the course run enrollment gets created in a manner that matches the learner's program enrollment.

This was using the regular v1/enrollments API, which does not consider the learner's program enrollment (and doesn't have enough information to do so, necessarily), and always creates an audit enrollment. So, this PR swaps usage of that API out for the verified program enrollments "one-click" API instead.

How can this be tested?

It's not vitally important that the courses used here exist in edX for this test. If you do want to fully test (including ensuring that the edX enrollments work), make sure your courses have course modes set up appropriately.

In MITx Online:

  1. Set up a couple of programs with at least one course each.
  2. Ensure one of the programs has a product, so it can be purchased.
  3. Ensure at least the course that's in the purchasable program also has a product.
  4. Ensure your test user is not enrolled in any of these programs or courses.

In Learn:

  1. Navigate to the product page for the audit-only program, and enroll in it.
  2. You should be delivered back to your dashboard and should have the program loaded up. (If not, go back to the product page and hit the Enrolled button, and it should take you there.)
  3. Observe that the courses appear as expected for the program.
  4. Open Developer Tools and switch to the Network tab, and ensure Preserve Log is turned on.
  5. Click on Start Course.
  6. In the Network tab, you should see a call to the proper api/v2/verified_program_enrollments API, and it should return a 201 Created.
  7. Check the enrollment in MITx Online. It should be of type audit.
  8. Repeat these steps, except using the purchasable program. When you enroll, ensure that you purchase the program and that you receive a verified enrollment in the program. You should end up with a verified enrollment in the course run, and an order should be created for the course run enrollment.

Additional Context

We can use the standard enrollment API for program enrollments, but only if the learner has an audit enrollment in the program since it can only create audit enrollments. But it's a bit easier to use the one-click API across the board since it will check to see what enrollment the learner should get for the course.

Copilot AI review requested due to automatic review settings March 18, 2026 16:10
Copy link
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

Updates the dashboard course card enrollment flow to use a dedicated “verified program enrollment” API endpoint (and hook/client wiring) when a course is being started from a verified program context.

Changes:

  • Add VerifiedProgramEnrollmentsApi client + useCreateVerifiedProgramEnrollment mutation hook.
  • Update DashboardCard to call the verified-program enrollment mutation (instead of the generic enrollment mutation) and pass program readable ID.
  • Update frontend test utilities and DashboardCard tests to mock/assert against the new verified-program enrollment endpoint.

Reviewed changes

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

Show a summary per file
File Description
frontends/main/src/app-pages/DashboardPage/CoursewareDisplay/DashboardCard.tsx Switches verified-program one-click enrollment to the new mutation and adjusts parameters.
frontends/main/src/app-pages/DashboardPage/CoursewareDisplay/DashboardCard.test.tsx Updates the verified-program enrollment test to mock/assert the new endpoint.
frontends/api/src/mitxonline/test-utils/urls.ts Adds a test URL helper for the verified-program enrollment create endpoint.
frontends/api/src/mitxonline/hooks/enrollment/index.ts Adds useCreateVerifiedProgramEnrollment hook exporting a mutation for the new endpoint.
frontends/api/src/mitxonline/clients.ts Adds and exports verifiedProgramEnrollmentsApi client instance.

Comment on lines 296 to 300
const mitxOnlineUser = useQuery(mitxUserQueries.me())
const createB2bEnrollment = useCreateB2bEnrollment()
const createEnrollment = useCreateEnrollment()
const createVerifiedProgramEnrollment = useCreateVerifiedProgramEnrollment()

Comment on lines 308 to 316
programId,
}: {
course: CourseWithCourseRunsSerializerV2
readableId?: string
href?: string
isB2B?: boolean
isVerifiedProgram?: boolean
programCourseRunId?: number
programId?: string
}) => {

const verifiedProgramEnrollments = {
create: (programId: string, courserunId: string) =>
`${API_BASE_URL}/api/v2/verified_program_enrollments/${programId}/${courserunId}/`,
@jkachel jkachel force-pushed the jkachel/10559-verified-prog-enrollments-needs-different-api branch from aebb7b1 to 0e571f5 Compare March 19, 2026 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants