Skip to content

Commit

Permalink
test(js): Add the connected groups to existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zak39 committed Dec 11, 2024
1 parent 4c5a027 commit 2ee5544
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
31 changes: 27 additions & 4 deletions src/tests/unit/groupfoldersService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*
*/

import { expect } from '@jest/globals'
import { getAll, formatGroups, formatUsers, checkGroupfolderNameExist, enableAcl, addGroupToGroupfolder, addGroupToManageACLForGroupfolder, removeGroupToManageACLForGroupfolder, createGroupfolder, destroy, rename } from '../../services/groupfoldersService.js'
import axios from '@nextcloud/axios'

Expand Down Expand Up @@ -285,11 +286,33 @@ describe('destroy', () => {
jest.resetAllMocks()
})
it('calls axios.delete method with proper parameters', async () => {
axios.delete.mockResolvedValue(responseValue)
await destroy('foobar')
expect(axios.delete).toHaveBeenCalledWith('/apps/workspace/api/delete/space', {
data: { workspace: 'foobar' },
const workspace = { id: 1, groupfolderId: 1 }
const spaceId = workspace.id

axios.delete.mockResolvedValue(
{
http: {
statuscode: 200,
message: 'The space is deleted.'
},
data: {
name: 'foobar',
groups: ['SPACE-WM-1', 'SPACE-U-1'],
space_id: 1,
groupfolder_id: 1,
state: 'delete'
}
}
)
axios.delete.mockResolvedValue({ status: 200, data: { ocs: { meta: { status: 'ok' } } } })

await destroy(workspace)

expect(axios.delete).toHaveBeenCalledWith(`/apps/workspace/spaces/${spaceId}`, {
data: { workspace },
})

expect(axios.delete).toHaveBeenCalledWith(`/apps/groupfolders/folders/${workspace.groupfolderId}`)
})
it('calls axios.delete 2 times and returns resp.data value', async () => {
const mockAxios = axios.delete.mockImplementationOnce(() => Promise.resolve({ status: 200, ...responseValue }))
Expand Down
6 changes: 3 additions & 3 deletions src/tests/unit/selectUsers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('SelectUsers component tests', () => {
]

wrappedSelectUsers.vm.$route.params.space = 'foobar'
wrappedSelectUsers.vm.$route.params.group = 'subgroup-42'
wrappedSelectUsers.vm.$route.params.slug = 'subgroup-42'

wrappedSelectUsers.vm.addUsersToWorkspaceOrGroup()
const count = wrappedSelectUsers.vm.$store.getters.groupUserCount('foobar', 'subgroup-42')
Expand All @@ -102,7 +102,7 @@ describe('SelectUsers component tests', () => {
},
]

wrappedSelectUsers.vm.$route.params.group = undefined
wrappedSelectUsers.vm.$route.params.slug = undefined

wrappedSelectUsers.vm.addUsersToWorkspaceOrGroup()
const count = wrappedSelectUsers.vm.$store.getters.groupUserCount('foobar', 'SPACE-U-42')
Expand All @@ -123,7 +123,7 @@ describe('SelectUsers component tests', () => {
},
]

wrappedSelectUsers.vm.$route.params.group = undefined
wrappedSelectUsers.vm.$route.params.slug = undefined

wrappedSelectUsers.vm.addUsersToWorkspaceOrGroup()
const count = wrappedSelectUsers.vm.$store.getters.groupUserCount('foobar', 'SPACE-GE-42')
Expand Down
4 changes: 4 additions & 0 deletions src/tests/unit/store.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,15 @@ describe('Vuex store tests', () => {
mutations.addGroupToSpace(state, {
name: 'test-space',
gid: 'test-group',
slug: 'test-group',
usersCount: 0,
})

expect(state.spaces['test-space'].groups['test-group']).toEqual({
gid: 'test-group',
displayName: 'test-group',
slug: 'test-group',
usersCount: 0,
})
})

Expand Down

0 comments on commit 2ee5544

Please sign in to comment.