Skip to content

Commit

Permalink
Move purge header into graph.ts for disable / delete space (#9534)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan authored Aug 3, 2023
1 parent d2d5483 commit d73fd4a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
12 changes: 9 additions & 3 deletions packages/web-client/src/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export interface Graph {
getDrive: (id: string) => AxiosPromise<Drive>
createDrive: (drive: Drive, options: any) => AxiosPromise<Drive>
updateDrive: (id: string, drive: Drive, options: any) => AxiosPromise<Drive>
deleteDrive: (id: string, ifMatch?: string, options?: any) => AxiosPromise<void>
disableDrive: (id: string) => AxiosPromise<void>
deleteDrive: (id: string) => AxiosPromise<void>
}
users: {
getUser: (userId: string) => AxiosPromise<User>
Expand Down Expand Up @@ -120,8 +121,13 @@ export const graph = (baseURI: string, axiosClient: AxiosInstance): Graph => {
drivesApiFactory.createDrive(drive, options),
updateDrive: (id: string, drive: Drive, options: any): AxiosPromise<Drive> =>
drivesApiFactory.updateDrive(id, drive, options),
deleteDrive: (id: string, ifMatch: string, options: any): AxiosPromise<void> =>
drivesApiFactory.deleteDrive(id, ifMatch, options)
disableDrive: (id: string): AxiosPromise<void> => drivesApiFactory.deleteDrive(id, '', {}),
deleteDrive: (id: string): AxiosPromise<void> =>
drivesApiFactory.deleteDrive(id, '', {
headers: {
Purge: 'T'
}
})
},
users: {
getUser: (userId: string) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,11 @@ export const useSpaceActionsDelete = ({ store }: { store?: Store<any> } = {}) =>
const deleteSpaces = async (spaces: SpaceResource[]) => {
const client = clientService.graphAuthenticated
const promises = spaces.map((space) =>
client.drives
.deleteDrive(space.id.toString(), '', {
headers: {
Purge: 'T'
}
})
.then(() => {
store.commit('Files/REMOVE_FILES', [{ id: space.id }])
store.commit('runtime/spaces/REMOVE_SPACE', { id: space.id })
return true
})
client.drives.deleteDrive(space.id.toString()).then(() => {
store.commit('Files/REMOVE_FILES', [{ id: space.id }])
store.commit('runtime/spaces/REMOVE_SPACE', { id: space.id })
return true
})
)
const results = await loadingService.addTask(() => {
return Promise.allSettled(promises)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const useSpaceActionsDisable = ({ store }: { store?: Store<any> } = {}) =

const client = clientService.graphAuthenticated
const promises = spaces.map((space) =>
client.drives.deleteDrive(space.id.toString()).then(() => {
client.drives.disableDrive(space.id.toString()).then(() => {
if (currentRoute.name === 'files-spaces-generic') {
router.push({ name: 'files-spaces-projects' })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('disable', () => {
it('should hide the modal on success', async () => {
const { wrapper, mocks } = getWrapper({
setup: async ({ disableSpaces }, { storeOptions, clientService }) => {
clientService.graphAuthenticated.drives.deleteDrive.mockResolvedValue(mockAxiosResolve())
clientService.graphAuthenticated.drives.disableDrive.mockResolvedValue(mockAxiosResolve())
await disableSpaces([mock<SpaceResource>({ id: 1, canDisable: () => true })])

expect(storeOptions.actions.hideModal).toHaveBeenCalledTimes(1)
Expand All @@ -103,7 +103,7 @@ describe('disable', () => {
jest.spyOn(console, 'error').mockImplementation(() => undefined)
const { wrapper } = getWrapper({
setup: async ({ actions, disableSpaces }, { storeOptions, clientService }) => {
clientService.graphAuthenticated.drives.deleteDrive.mockRejectedValue(new Error())
clientService.graphAuthenticated.drives.disableDrive.mockRejectedValue(new Error())
await disableSpaces([mock<SpaceResource>({ id: 1, canDisable: () => true })])

expect(storeOptions.actions.showErrorMessage).toHaveBeenCalledTimes(1)
Expand Down

0 comments on commit d73fd4a

Please sign in to comment.