separate test and default data providers#10001
Merged
djhi merged 3 commits intomarmelab:masterfrom Jul 19, 2024
Merged
Conversation
Contributor
|
Hi @Nilegfx and thanks for your contribution 👍 We used to type result as import {
CreateResult,
DataProvider,
DeleteResult,
GetOneResult,
UpdateResult,
} from '../types';
export const defaultDataProvider: DataProvider = {
create: () => Promise.resolve<CreateResult>({ data: null }),
delete: () => Promise.resolve<DeleteResult>({ data: null }),
deleteMany: () => Promise.resolve({ data: [] }),
getList: () => Promise.resolve({ data: [], total: 0 }),
getMany: () => Promise.resolve({ data: [] }),
getManyReference: () => Promise.resolve({ data: [], total: 0 }),
getOne: () => Promise.resolve<GetOneResult>({ data: null }),
update: () => Promise.resolve<UpdateResult>({ data: null }),
updateMany: () => Promise.resolve({ data: [] }),
};What do you think about that @djhi ? |
adguernier
reviewed
Jul 16, 2024
| getList: () => Promise.resolve({ data: [], total: 0 }), | ||
| getMany: () => Promise.resolve({ data: [] }), | ||
| getManyReference: () => Promise.resolve({ data: [], total: 0 }), | ||
| getOne: () => Promise.resolve({ data: { id: 'o' } }), |
Contributor
There was a problem hiding this comment.
question: why { data: { id: 'o' } } instead of { data: null } like the others?
Contributor
Author
There was a problem hiding this comment.
oh, that was committed by mistake, I will remove it.
adguernier
approved these changes
Jul 18, 2024
Contributor
|
Awaiting further approval |
djhi
approved these changes
Jul 19, 2024
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.
Problem
defaultDataProvider behaviour changed in V5. the change was intended to just support the tests. this affect the end users if they use the exported
defaultDataProviderin their implementation which means one extra migration step for them and one extra migration documentation entry point react-admin team has to add.Solution
Implement testing-related changes for the
defaultDataProviderin the right placetestDataProviderand revert thedefaultDataProviderto its original behaviour (which is dummy responses but at least it doesn't throw)Struggles/Challenges
I implemented the refactoring in 30 seconds, then I spent almost half an hour trying to make the
defaultDataProviderwork with theDataProvidertype but I failed. I would appreciate if one of the core members can explain to me what I miss here or how to correctly type thedefaultDataProvider.you can reproduce the issue by just changing
export const defaultDataProvider = {toexport const defaultDataProvider:DataProvider = {(and of course import theDataProvidertype.I used a workaround
export const defaultDataProvider: DataProvider = {} as DataProviderbut I don't like this. I am still interested to understand this TypeError (I used AI but it couldn't give me logical answer)How To Test
giving that this change was intended to keep everything as the same, I assumed that the current tests should be enough for this simple and small refactoring
Additional Checks
masterfor a bugfix, ornextfor a featureAlso, please make sure to read the contributing guidelines.