-
Notifications
You must be signed in to change notification settings - Fork 210
fix: advanced-settings.api always return exactly what it receives #1581
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
Merged
arbrandes
merged 7 commits into
openedx:master
from
eduNEXT:jipm/fix-setting-snake-case
Jun 13, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7020819
fix: use modifyObjectKeys and snakeCaseObject on api data advanced se…
jignaciopm b688911
fix: improvements from feedback review
jignaciopm b440fc4
fix: add comments
jignaciopm 1ae3763
fix: completly changed the logic to always return exactly what it rec…
jignaciopm 78467d4
fix: unit test and advanced setting titles in blank
jignaciopm 094a210
fix: remove use convertObjectToSnakeCase
jignaciopm 90c69d3
fix: add more cases to expected
jignaciopm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,236 @@ | ||
| import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; | ||
| import { | ||
| getCourseAdvancedSettings, | ||
| updateCourseAdvancedSettings, | ||
| getProctoringExamErrors, | ||
| } from './api'; | ||
|
|
||
| jest.mock('@edx/frontend-platform/auth', () => ({ | ||
| getAuthenticatedHttpClient: jest.fn(), | ||
| })); | ||
|
|
||
| describe('courseSettings API', () => { | ||
| const mockHttpClient = { | ||
| get: jest.fn(), | ||
| patch: jest.fn(), | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| getAuthenticatedHttpClient.mockReturnValue(mockHttpClient); | ||
| }); | ||
|
|
||
| describe('getCourseAdvancedSettings', () => { | ||
| it('should fetch and unformat course advanced settings', async () => { | ||
| const fakeData = { | ||
| key_snake_case: { | ||
| display_name: 'To come camelCase', | ||
| testCamelCase: 'This key must not be formatted', | ||
| PascalCase: 'To come camelCase', | ||
| 'kebab-case': 'To come camelCase', | ||
| UPPER_CASE: 'To come camelCase', | ||
| lowercase: 'This key must not be formatted', | ||
| UPPERCASE: 'To come lowercase', | ||
| 'Title Case': 'To come camelCase', | ||
| 'dot.case': 'To come camelCase', | ||
| SCREAMING_SNAKE_CASE: 'To come camelCase', | ||
| MixedCase: 'To come camelCase', | ||
| 'Train-Case': 'To come camelCase', | ||
| nestedOption: { | ||
| anotherOption: 'To come camelCase', | ||
| }, | ||
| // value is an object with various cases | ||
| // this contain must not be formatted to camelCase | ||
| value: { | ||
| snake_case: 'snake_case', | ||
| camelCase: 'camelCase', | ||
| PascalCase: 'PascalCase', | ||
| 'kebab-case': 'kebab-case', | ||
| UPPER_CASE: 'UPPER_CASE', | ||
| lowercase: 'lowercase', | ||
| UPPERCASE: 'UPPERCASE', | ||
| 'Title Case': 'Title Case', | ||
| 'dot.case': 'dot.case', | ||
| SCREAMING_SNAKE_CASE: 'SCREAMING_SNAKE_CASE', | ||
| MixedCase: 'MixedCase', | ||
| 'Train-Case': 'Train-Case', | ||
| nestedOption: { | ||
| anotherOption: 'nestedContent', | ||
|
jignaciopm marked this conversation as resolved.
|
||
| }, | ||
| }, | ||
|
jignaciopm marked this conversation as resolved.
|
||
| }, | ||
| }; | ||
| const expected = { | ||
| keySnakeCase: { | ||
| displayName: 'To come camelCase', | ||
| testCamelCase: 'This key must not be formatted', | ||
| pascalCase: 'To come camelCase', | ||
| kebabCase: 'To come camelCase', | ||
| upperCase: 'To come camelCase', | ||
| lowercase: 'This key must not be formatted', | ||
| uppercase: 'To come lowercase', | ||
| titleCase: 'To come camelCase', | ||
| dotCase: 'To come camelCase', | ||
| screamingSnakeCase: 'To come camelCase', | ||
| mixedCase: 'To come camelCase', | ||
| trainCase: 'To come camelCase', | ||
| nestedOption: { | ||
| anotherOption: 'To come camelCase', | ||
| }, | ||
| value: fakeData.key_snake_case.value, | ||
| }, | ||
| }; | ||
|
|
||
| mockHttpClient.get.mockResolvedValue({ data: fakeData }); | ||
|
|
||
| const result = await getCourseAdvancedSettings('course-v1:Test+T101+2024'); | ||
| expect(mockHttpClient.get).toHaveBeenCalledWith( | ||
| `${process.env.STUDIO_BASE_URL}/api/contentstore/v0/advanced_settings/course-v1:Test+T101+2024?fetch_all=0`, | ||
| ); | ||
| expect(result).toEqual(expected); | ||
| }); | ||
| }); | ||
|
|
||
| describe('updateCourseAdvancedSettings', () => { | ||
| it('should update and unformat course advanced settings', async () => { | ||
| const fakeData = { | ||
| key_snake_case: { | ||
| display_name: 'To come camelCase', | ||
| testCamelCase: 'This key must not be formatted', // because already be camelCase | ||
| PascalCase: 'To come camelCase', | ||
| 'kebab-case': 'To come camelCase', | ||
| UPPER_CASE: 'To come camelCase', | ||
| lowercase: 'This key must not be formatted', // because camelCase in lowercase not formatted | ||
| UPPERCASE: 'To come lowercase', // because camelCase in UPPERCASE format to lowercase | ||
| 'Title Case': 'To come camelCase', | ||
| 'dot.case': 'To come camelCase', | ||
| SCREAMING_SNAKE_CASE: 'To come camelCase', | ||
| MixedCase: 'To come camelCase', | ||
| 'Train-Case': 'To come camelCase', | ||
| nestedOption: { | ||
| anotherOption: 'To come camelCase', | ||
| }, | ||
| // value is an object with various cases | ||
| // this contain must not be formatted to camelCase | ||
| value: { | ||
| snake_case: 'snake_case', | ||
| camelCase: 'camelCase', | ||
| PascalCase: 'PascalCase', | ||
| 'kebab-case': 'kebab-case', | ||
| UPPER_CASE: 'UPPER_CASE', | ||
| lowercase: 'lowercase', | ||
| UPPERCASE: 'UPPERCASE', | ||
| 'Title Case': 'Title Case', | ||
| 'dot.case': 'dot.case', | ||
| SCREAMING_SNAKE_CASE: 'SCREAMING_SNAKE_CASE', | ||
| MixedCase: 'MixedCase', | ||
| 'Train-Case': 'Train-Case', | ||
| nestedOption: { | ||
| anotherOption: 'nestedContent', | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
| const expected = { | ||
| keySnakeCase: { | ||
| displayName: 'To come camelCase', | ||
| testCamelCase: 'This key must not be formatted', | ||
| pascalCase: 'To come camelCase', | ||
| kebabCase: 'To come camelCase', | ||
| upperCase: 'To come camelCase', | ||
| lowercase: 'This key must not be formatted', | ||
| uppercase: 'To come lowercase', | ||
| titleCase: 'To come camelCase', | ||
| dotCase: 'To come camelCase', | ||
| screamingSnakeCase: 'To come camelCase', | ||
| mixedCase: 'To come camelCase', | ||
| trainCase: 'To come camelCase', | ||
| nestedOption: { | ||
| anotherOption: 'To come camelCase', | ||
| }, | ||
| value: fakeData.key_snake_case.value, | ||
| }, | ||
| }; | ||
|
|
||
| mockHttpClient.patch.mockResolvedValue({ data: fakeData }); | ||
|
|
||
| const result = await updateCourseAdvancedSettings('course-v1:Test+T101+2024', {}); | ||
| expect(mockHttpClient.patch).toHaveBeenCalledWith( | ||
| `${process.env.STUDIO_BASE_URL}/api/contentstore/v0/advanced_settings/course-v1:Test+T101+2024`, | ||
| {}, | ||
| ); | ||
| expect(result).toEqual(expected); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getProctoringExamErrors', () => { | ||
| it('should fetch proctoring errors and return unformat object', async () => { | ||
| const fakeData = { | ||
| key_snake_case: { | ||
| display_name: 'To come camelCase', | ||
| testCamelCase: 'This key must not be formatted', | ||
| PascalCase: 'To come camelCase', | ||
| 'kebab-case': 'To come camelCase', | ||
| UPPER_CASE: 'To come camelCase', | ||
| lowercase: 'This key must not be formatted', | ||
| UPPERCASE: 'To come lowercase', | ||
| 'Title Case': 'To come camelCase', | ||
| 'dot.case': 'To come camelCase', | ||
| SCREAMING_SNAKE_CASE: 'To come camelCase', | ||
| MixedCase: 'To come camelCase', | ||
| 'Train-Case': 'To come camelCase', | ||
| nestedOption: { | ||
| anotherOption: 'To come camelCase', | ||
| }, | ||
| // value is an object with various cases | ||
| // this contain must not be formatted to camelCase | ||
| value: { | ||
| snake_case: 'snake_case', | ||
| camelCase: 'camelCase', | ||
| PascalCase: 'PascalCase', | ||
| 'kebab-case': 'kebab-case', | ||
| UPPER_CASE: 'UPPER_CASE', | ||
| lowercase: 'lowercase', | ||
| UPPERCASE: 'UPPERCASE', | ||
| 'Title Case': 'Title Case', | ||
| 'dot.case': 'dot.case', | ||
| SCREAMING_SNAKE_CASE: 'SCREAMING_SNAKE_CASE', | ||
| MixedCase: 'MixedCase', | ||
| 'Train-Case': 'Train-Case', | ||
| nestedOption: { | ||
| anotherOption: 'nestedContent', | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
| const expected = { | ||
| keySnakeCase: { | ||
| displayName: 'To come camelCase', | ||
| testCamelCase: 'This key must not be formatted', | ||
| pascalCase: 'To come camelCase', | ||
| kebabCase: 'To come camelCase', | ||
| upperCase: 'To come camelCase', | ||
| lowercase: 'This key must not be formatted', | ||
| uppercase: 'To come lowercase', | ||
| titleCase: 'To come camelCase', | ||
| dotCase: 'To come camelCase', | ||
| screamingSnakeCase: 'To come camelCase', | ||
| mixedCase: 'To come camelCase', | ||
| trainCase: 'To come camelCase', | ||
| nestedOption: { | ||
| anotherOption: 'To come camelCase', | ||
| }, | ||
| value: fakeData.key_snake_case.value, | ||
| }, | ||
| }; | ||
|
|
||
| mockHttpClient.get.mockResolvedValue({ data: fakeData }); | ||
|
|
||
| const result = await getProctoringExamErrors('course-v1:Test+T101+2024'); | ||
| expect(mockHttpClient.get).toHaveBeenCalledWith( | ||
| `${process.env.STUDIO_BASE_URL}/api/contentstore/v1/proctoring_errors/course-v1:Test+T101+2024`, | ||
| ); | ||
| expect(result).toEqual(expected); | ||
| }); | ||
| }); | ||
| }); | ||
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.
Uh oh!
There was an error while loading. Please reload this page.