Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
3c907b53
Commit
3c907b53
authored
Jan 10, 2022
by
Fernando Arias
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement corpus delete logic
* Use graphQL mutation * Add vue and apollo unit tests
parent
3e98649b
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
72 additions
and
30 deletions
+72
-30
ee/app/assets/javascripts/security_configuration/corpus_management/components/corpus_management.vue
...ration/corpus_management/components/corpus_management.vue
+16
-1
ee/app/assets/javascripts/security_configuration/corpus_management/components/corpus_table.vue
...nfiguration/corpus_management/components/corpus_table.vue
+2
-6
ee/app/assets/javascripts/security_configuration/corpus_management/graphql/mutations/delete_corpus.mutation.graphql
...nagement/graphql/mutations/delete_corpus.mutation.graphql
+2
-2
ee/app/assets/javascripts/security_configuration/corpus_management/graphql/resolvers/resolvers.js
...guration/corpus_management/graphql/resolvers/resolvers.js
+0
-3
ee/spec/frontend/security_configuration/corpus_management/corpus_management_spec.js
...configuration/corpus_management/corpus_management_spec.js
+34
-2
ee/spec/frontend/security_configuration/corpus_management/corpus_table_spec.js
...rity_configuration/corpus_management/corpus_table_spec.js
+10
-16
ee/spec/frontend/security_configuration/corpus_management/mock_data.js
...end/security_configuration/corpus_management/mock_data.js
+8
-0
No files found.
ee/app/assets/javascripts/security_configuration/corpus_management/components/corpus_management.vue
View file @
3c907b53
...
...
@@ -4,6 +4,7 @@ import CorpusTable from 'ee/security_configuration/corpus_management/components/
import
CorpusUpload
from
'
ee/security_configuration/corpus_management/components/corpus_upload.vue
'
;
import
{
s__
,
__
}
from
'
~/locale
'
;
import
getCorpusesQuery
from
'
../graphql/queries/get_corpuses.query.graphql
'
;
import
deleteCorpusMutation
from
'
../graphql/mutations/delete_corpus.mutation.graphql
'
;
export
default
{
components
:
{
...
...
@@ -79,6 +80,20 @@ export default {
};
this
.
$apollo
.
queries
.
states
.
refetch
();
},
onDelete
(
id
)
{
return
this
.
$apollo
.
mutate
({
mutation
:
deleteCorpusMutation
,
variables
:
{
input
:
{
id
,
},
},
})
.
then
(()
=>
{
this
.
$apollo
.
queries
.
states
.
refetch
();
});
},
nextPage
()
{
this
.
pagination
=
{
firstPageSize
:
this
.
$options
.
pageSize
,
...
...
@@ -113,7 +128,7 @@ export default {
<gl-loading-icon
v-if=
"isLoading"
size=
"lg"
class=
"gl-py-13"
/>
<template
v-else
>
<corpus-table
:corpuses=
"corpuses"
/>
<corpus-table
:corpuses=
"corpuses"
@
delete=
"onDelete"
/>
</
template
>
<div
v-if=
"hasPagination"
class=
"gl-display-flex gl-justify-content-center gl-mt-5"
>
...
...
ee/app/assets/javascripts/security_configuration/corpus_management/components/corpus_table.vue
View file @
3c907b53
...
...
@@ -6,7 +6,6 @@ import Target from 'ee/security_configuration/corpus_management/components/colum
import
{
s__
}
from
'
~/locale
'
;
import
UserDate
from
'
~/vue_shared/components/user_date.vue
'
;
import
{
ISO_SHORT_FORMAT
}
from
'
~/vue_shared/constants
'
;
import
deleteCorpusMutation
from
'
../graphql/mutations/delete_corpus.mutation.graphql
'
;
const
thClass
=
'
gl-bg-transparent! gl-border-gray-100! gl-border-b-solid! gl-border-b-1!
'
;
...
...
@@ -56,11 +55,8 @@ export default {
emptyTable
:
s__
(
'
CorpusManagement|Currently, there are no uploaded or generated corpuses.
'
),
},
methods
:
{
onDelete
({
name
})
{
this
.
$apollo
.
mutate
({
mutation
:
deleteCorpusMutation
,
variables
:
{
name
,
projectPath
:
this
.
projectFullPath
},
});
onDelete
({
package
:
{
id
}
})
{
this
.
$emit
(
'
delete
'
,
id
);
},
target
(
corpus
)
{
return
corpus
.
package
.
pipelines
.
nodes
[
0
]?.
ref
;
...
...
ee/app/assets/javascripts/security_configuration/corpus_management/graphql/mutations/delete_corpus.mutation.graphql
View file @
3c907b53
mutation
deleteCorpus
(
$
projectPath
:
ID
!,
$name
:
String
!)
{
de
leteCorpus
(
projectPath
:
$projectPath
,
name
:
$name
)
@client
{
mutation
deleteCorpus
(
$
input
:
DestroyPackageInput
!)
{
de
stroyPackage
(
input
:
$input
)
{
errors
}
}
ee/app/assets/javascripts/security_configuration/corpus_management/graphql/resolvers/resolvers.js
View file @
3c907b53
...
...
@@ -44,9 +44,6 @@ export default {
},
});
},
deleteCorpus
:
()
=>
{
// NO-OP
},
uploadCorpus
:
(
_
,
{
projectPath
,
name
,
files
},
{
cache
,
client
})
=>
{
const
onUploadProgress
=
(
e
)
=>
{
client
.
mutate
({
...
...
ee/spec/frontend/security_configuration/corpus_management/corpus_management_spec.js
View file @
3c907b53
...
...
@@ -8,11 +8,12 @@ import CorpusManagement from 'ee/security_configuration/corpus_management/compon
import
CorpusTable
from
'
ee/security_configuration/corpus_management/components/corpus_table.vue
'
;
import
CorpusUpload
from
'
ee/security_configuration/corpus_management/components/corpus_upload.vue
'
;
import
getCorpusesQuery
from
'
ee/security_configuration/corpus_management/graphql/queries/get_corpuses.query.graphql
'
;
import
deleteCorpusMutation
from
'
ee/security_configuration/corpus_management/graphql/mutations/delete_corpus.mutation.graphql
'
;
import
createMockApollo
from
'
helpers/mock_apollo_helper
'
;
import
waitForPromises
from
'
helpers/wait_for_promises
'
;
import
{
getCorpusesQueryResponse
}
from
'
./mock_data
'
;
import
{
getCorpusesQueryResponse
,
deleteCorpusMutationResponse
}
from
'
./mock_data
'
;
const
TEST_PROJECT_FULL_PATH
=
'
/namespace/project
'
;
const
TEST_CORPUS_HELP_PATH
=
'
/docs/corpus-management
'
;
...
...
@@ -22,10 +23,14 @@ describe('EE - CorpusManagement', () => {
const
createMockApolloProvider
=
({
getCorpusesQueryRequestHandler
=
jest
.
fn
().
mockResolvedValue
(
getCorpusesQueryResponse
),
deleteCorpusMutationHandler
=
jest
.
fn
().
mockResolvedValue
(
deleteCorpusMutationResponse
),
}
=
{})
=>
{
Vue
.
use
(
VueApollo
);
const
requestHandlers
=
[[
getCorpusesQuery
,
getCorpusesQueryRequestHandler
]];
const
requestHandlers
=
[
[
getCorpusesQuery
,
getCorpusesQueryRequestHandler
],
[
deleteCorpusMutation
,
deleteCorpusMutationHandler
],
];
const
mockResolvers
=
{
Query
:
{
...
...
@@ -178,6 +183,33 @@ describe('EE - CorpusManagement', () => {
});
});
});
describe
(
'
corpus deletion
'
,
()
=>
{
it
(
'
deletes the corpus
'
,
async
()
=>
{
const
mutationVars
=
{
input
:
{
id
:
1
}
};
const
getCorpusesQueryRequestHandler
=
jest
.
fn
()
.
mockResolvedValue
(
getCorpusesQueryResponse
);
const
deleteCorpusMutationHandler
=
jest
.
fn
()
.
mockResolvedValue
(
deleteCorpusMutationResponse
);
createComponent
({
apolloProvider
:
createMockApolloProvider
({
getCorpusesQueryRequestHandler
,
deleteCorpusMutationHandler
,
}),
});
await
waitForPromises
();
const
corpusTable
=
wrapper
.
findComponent
(
CorpusTable
);
corpusTable
.
vm
.
$emit
(
'
delete
'
,
mutationVars
.
input
.
id
);
await
waitForPromises
();
expect
(
deleteCorpusMutationHandler
).
toHaveBeenCalledWith
(
mutationVars
);
});
});
});
describe
(
'
when loading
'
,
()
=>
{
...
...
ee/spec/frontend/security_configuration/corpus_management/corpus_table_spec.js
View file @
3c907b53
...
...
@@ -5,6 +5,12 @@ import { corpuses } from './mock_data';
const
TEST_PROJECT_FULL_PATH
=
'
/namespace/project
'
;
const
CORPUS
=
{
package
:
{
id
:
1
,
},
};
describe
(
'
Corpus table
'
,
()
=>
{
let
wrapper
;
...
...
@@ -13,18 +19,11 @@ describe('Corpus table', () => {
corpuses
,
};
const
defaultMocks
=
{
$apollo
:
{
mutate
:
jest
.
fn
().
mockResolvedValue
(),
},
};
wrapper
=
mount
(
CorpusTable
,
{
propsData
:
defaultProps
,
provide
:
{
projectFullPath
:
TEST_PROJECT_FULL_PATH
,
},
mocks
:
defaultMocks
,
...
options
,
});
};
...
...
@@ -49,16 +48,11 @@ describe('Corpus table', () => {
expect
(
columnHeaders
.
element
).
toMatchSnapshot
();
});
it
(
'
triggers the corpus deletion mutation
'
,
()
=>
{
const
{
$apollo
:
{
mutate
},
}
=
wrapper
.
vm
;
it
(
'
emits the delete event
'
,
()
=>
{
const
actionComponent
=
wrapper
.
findComponent
(
Actions
);
expect
(
mutate
).
not
.
toHaveBeenCalled
();
actionComponent
.
vm
.
$emit
(
'
delete
'
,
'
corpus-name
'
);
expect
(
mutate
).
toHaveBeenCalledTimes
(
1
);
actionComponent
.
vm
.
$emit
(
'
delete
'
,
CORPUS
);
expect
(
wrapper
.
emitted
(
'
delete
'
)).
toBeTruthy
();
expect
(
wrapper
.
emitted
(
'
delete
'
)[
0
][
0
]).
toEqual
(
CORPUS
.
package
.
id
);
});
describe
(
'
with no corpuses
'
,
()
=>
{
...
...
ee/spec/frontend/security_configuration/corpus_management/mock_data.js
View file @
3c907b53
...
...
@@ -113,3 +113,11 @@ export const getCorpusesQueryResponse = {
},
},
};
export
const
deleteCorpusMutationResponse
=
{
data
:
{
destroyPackage
:
{
errors
:
{},
},
},
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment