-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug/12035 not possible to delete a data model in studio (#12115)
* fixed removing datamodell and old datamodell
- Loading branch information
1 parent
f72dadf
commit 97fef76
Showing
7 changed files
with
201 additions
and
36 deletions.
There are no files selected for viewing
This file contains 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 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
71 changes: 71 additions & 0 deletions
71
frontend/app-development/hooks/mutations/useDeleteDatamodelMutation.test.ts
This file contains 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,71 @@ | ||
import { renderHookWithMockStore } from '../../test/mocks'; | ||
import { useDeleteDatamodelMutation } from './useDeleteDatamodelMutation'; | ||
import type { ServicesContextProps } from 'app-shared/contexts/ServicesContext'; | ||
import type { QueryClient } from '@tanstack/react-query'; | ||
import { createQueryClientMock } from 'app-shared/mocks/queryClientMock'; | ||
import { waitFor } from '@testing-library/react'; | ||
import { QueryKey } from 'app-shared/types/QueryKey'; | ||
import { queriesMock } from 'app-shared/mocks/queriesMock'; | ||
import { createJsonModelPathMock } from 'app-shared/mocks/modelPathMocks'; | ||
import { | ||
createJsonMetadataMock, | ||
createXsdMetadataMock, | ||
} from 'app-shared/mocks/datamodelMetadataMocks'; | ||
|
||
const modelName = 'modelName'; | ||
const modelPath = createJsonModelPathMock(modelName); | ||
const org = 'org'; | ||
const app = 'app'; | ||
const modelMetadataJson = createJsonMetadataMock(modelName); | ||
const modelMetadataXsd = createXsdMetadataMock(modelName); | ||
|
||
describe('useDeleteDatamodelMutation', () => { | ||
beforeEach(jest.clearAllMocks); | ||
|
||
it('Calls deleteDatamodel with correct parameters', async () => { | ||
const client = createQueryClientMock(); | ||
client.setQueryData([QueryKey.DatamodelsJson, org, app], [modelMetadataJson]); | ||
client.setQueryData([QueryKey.DatamodelsXsd, org, app], [modelMetadataXsd]); | ||
const { | ||
renderHookResult: { result }, | ||
} = render({}, client); | ||
expect(result.current).toBeDefined(); | ||
result.current.mutate(modelPath); | ||
await waitFor(() => result.current.isSuccess); | ||
expect(queriesMock.deleteDatamodel).toHaveBeenCalledTimes(1); | ||
expect(queriesMock.deleteDatamodel).toHaveBeenCalledWith(org, app, modelPath); | ||
}); | ||
|
||
it('Removes the metadata instances from the query cache', async () => { | ||
const client = createQueryClientMock(); | ||
client.setQueryData([QueryKey.DatamodelsJson, org, app], [modelMetadataJson]); | ||
client.setQueryData([QueryKey.DatamodelsXsd, org, app], [modelMetadataXsd]); | ||
const { | ||
renderHookResult: { result }, | ||
} = render({}, client); | ||
result.current.mutate(modelPath); | ||
await waitFor(() => result.current.isSuccess); | ||
expect(client.getQueryData([QueryKey.DatamodelsJson, org, app])).toEqual([]); | ||
expect(client.getQueryData([QueryKey.DatamodelsXsd, org, app])).toEqual([]); | ||
}); | ||
|
||
it('Removes the schema queries from the query cache', async () => { | ||
const client = createQueryClientMock(); | ||
client.setQueryData([QueryKey.DatamodelsJson, org, app], [modelMetadataJson]); | ||
client.setQueryData([QueryKey.DatamodelsXsd, org, app], [modelMetadataXsd]); | ||
const { | ||
renderHookResult: { result }, | ||
} = render({}, client); | ||
result.current.mutate(modelPath); | ||
await waitFor(() => result.current.isSuccess); | ||
expect(client.getQueryData([QueryKey.JsonSchema, org, app, modelPath])).toBeUndefined(); | ||
expect( | ||
client.getQueryData([QueryKey.JsonSchema, org, app, modelMetadataXsd.repositoryRelativeUrl]), | ||
).toBeUndefined(); | ||
}); | ||
}); | ||
|
||
const render = ( | ||
queries: Partial<ServicesContextProps> = {}, | ||
queryClient: QueryClient = createQueryClientMock(), | ||
) => renderHookWithMockStore({}, queries, queryClient)(() => useDeleteDatamodelMutation()); |
This file contains 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 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 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,2 @@ | ||
export const createJsonModelPathMock = (name: string): string => `/App/models/${name}.schema.json`; | ||
export const createXsdModelPathMock = (name: string): string => `/App/models/${name}.xsd`; |
This file contains 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