Swap out the API used for enrollments for program-related enrollments#3066
Open
Swap out the API used for enrollments for program-related enrollments#3066
Conversation
frontends/main/src/app-pages/DashboardPage/CoursewareDisplay/DashboardCard.tsx
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment.
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
VerifiedProgramEnrollmentsApiclient +useCreateVerifiedProgramEnrollmentmutation hook. - Update
DashboardCardto call the verified-program enrollment mutation (instead of the generic enrollment mutation) and pass program readable ID. - Update frontend test utilities and
DashboardCardtests 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}/`, |
frontends/main/src/app-pages/DashboardPage/CoursewareDisplay/DashboardCard.tsx
Show resolved
Hide resolved
…specific one when the card displays an course in a program
aebb7b1 to
0e571f5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/enrollmentsAPI, 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:
In Learn:
api/v2/verified_program_enrollmentsAPI, and it should return a201 Created.audit.verifiedenrollment in the program. You should end up with averifiedenrollment 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.