Add better assertions to program enrollments test #3157
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?
Part of https://github.com/mitodl/hq/issues/9559
Description (What does it do?)
In order to give higher confidence that later PRs to actually fix the above issue don't introduce regressions, this puts in place more complete tests for the
/api/v1/program_enrollmentsand/api/v2/program_enrollmentsAPIs. Previously the tests either didn't exist or only tested top-level response ordinality.A large amount of the work here is around setting up the correct state, so I've leaned a lot on the generation of random data to ensure there is a good mix of the user being enrolled, program/course certificates, b2b contracts, etc. This represents the majority of the variability of API responses. There are some fields I didn't worry about testing more thoroughly so they just have hardcoded values.
I also added some default sorting to the API responses, sorting by descending
idsince that will mean newer programs/courses first. In practices this tends to align to how it was being sorted already, there was just a small random chance (<0.5% in my testing) that it would sort a different way. This was needed to make the sorting deterministic for tests to reliably pass.How can this be tested?
Tests should pass and things like the dashboard should still be functional. It's probably worth testing this with the Learn organization dashboards too since those call these APIs and I altered the sorting.