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
fcce1b08
Commit
fcce1b08
authored
Dec 03, 2020
by
Paul Gascou-Vaillancourt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add specs for the auto-select behavior
Test the new auto-select behavior by mocking the Apollo client
parent
c1ba5297
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
110 additions
and
20 deletions
+110
-20
ee/spec/frontend/on_demand_scans/components/on_demand_scans_form_spec.js
...d/on_demand_scans/components/on_demand_scans_form_spec.js
+63
-15
ee/spec/frontend/on_demand_scans/components/profile_selector/profile_selector_spec.js
...cans/components/profile_selector/profile_selector_spec.js
+1
-1
ee/spec/frontend/on_demand_scans/components/profile_selector/scanner_profile_selector_spec.js
...ponents/profile_selector/scanner_profile_selector_spec.js
+1
-1
ee/spec/frontend/on_demand_scans/components/profile_selector/site_profile_selector_spec.js
...components/profile_selector/site_profile_selector_spec.js
+1
-1
ee/spec/frontend/on_demand_scans/mocks/apollo_mocks.js
ee/spec/frontend/on_demand_scans/mocks/apollo_mocks.js
+38
-0
ee/spec/frontend/on_demand_scans/mocks/mock_data.js
ee/spec/frontend/on_demand_scans/mocks/mock_data.js
+4
-0
ee/spec/frontend/security_configuration/dast_scanner_profiles_form/components/dast_scanner_profiles_form_spec.js
...ofiles_form/components/dast_scanner_profiles_form_spec.js
+1
-1
ee/spec/frontend/security_configuration/dast_site_profiles_form/components/dast_site_profile_form_spec.js
...e_profiles_form/components/dast_site_profile_form_spec.js
+1
-1
No files found.
ee/spec/frontend/on_demand_scans/components/on_demand_scans_form_spec.js
View file @
fcce1b08
import
{
GlForm
,
GlSkeletonLoader
}
from
'
@gitlab/ui
'
;
import
{
shallowMount
,
mount
}
from
'
@vue/test-utils
'
;
import
{
shallowMount
,
mount
,
createLocalVue
}
from
'
@vue/test-utils
'
;
import
{
merge
}
from
'
lodash
'
;
import
VueApollo
from
'
vue-apollo
'
;
import
createApolloProvider
from
'
helpers/mock_apollo_helper
'
;
import
OnDemandScansForm
from
'
ee/on_demand_scans/components/on_demand_scans_form.vue
'
;
import
ScannerProfileSelector
from
'
ee/on_demand_scans/components/profile_selector/scanner_profile_selector.vue
'
;
import
SiteProfileSelector
from
'
ee/on_demand_scans/components/profile_selector/site_profile_selector.vue
'
;
import
dastOnDemandScanCreate
from
'
ee/on_demand_scans/graphql/dast_on_demand_scan_create.mutation.graphql
'
;
import
dastScannerProfilesQuery
from
'
ee/security_configuration/dast_profiles/graphql/dast_scanner_profiles.query.graphql
'
;
import
dastSiteProfilesQuery
from
'
ee/security_configuration/dast_profiles/graphql/dast_site_profiles.query.graphql
'
;
import
*
as
responses
from
'
../mocks/apollo_mocks
'
;
import
{
scannerProfiles
,
siteProfiles
}
from
'
../mocks/mock_data
'
;
import
{
redirectTo
}
from
'
~/lib/utils/url_utility
'
;
import
{
scannerProfiles
,
siteProfiles
}
from
'
../mock_data
'
;
const
helpPagePath
=
'
/application_security/dast/index#on-demand-scans
'
;
const
projectPath
=
'
group/project
'
;
...
...
@@ -22,17 +27,6 @@ const defaultProps = {
defaultBranch
,
};
const
defaultMocks
=
{
$apollo
:
{
mutate
:
jest
.
fn
(),
queries
:
{
scannerProfiles
:
{},
siteProfiles
:
{},
},
addSmartQuery
:
jest
.
fn
(),
},
};
const
pipelineUrl
=
`/
${
projectPath
}
/pipelines/123`
;
const
[
passiveScannerProfile
,
activeScannerProfile
]
=
scannerProfiles
;
const
[
nonValidatedSiteProfile
,
validatedSiteProfile
]
=
siteProfiles
;
...
...
@@ -43,7 +37,9 @@ jest.mock('~/lib/utils/url_utility', () => ({
}));
describe
(
'
OnDemandScansForm
'
,
()
=>
{
let
localVue
;
let
subject
;
let
requestHandlers
;
const
findForm
=
()
=>
subject
.
find
(
GlForm
);
const
findByTestId
=
testId
=>
subject
.
find
(
`[data-testid="
${
testId
}
"]`
);
...
...
@@ -58,7 +54,38 @@ describe('OnDemandScansForm', () => {
};
const
submitForm
=
()
=>
findForm
().
vm
.
$emit
(
'
submit
'
,
{
preventDefault
:
()
=>
{}
});
const
subjectMounterFactory
=
(
mountFn
=
shallowMount
)
=>
(
options
=
{})
=>
{
const
createMockApolloProvider
=
handlers
=>
{
localVue
.
use
(
VueApollo
);
requestHandlers
=
{
dastScannerProfiles
:
jest
.
fn
().
mockResolvedValue
(
responses
.
dastScannerProfiles
()),
dastSiteProfiles
:
jest
.
fn
().
mockResolvedValue
(
responses
.
dastSiteProfiles
()),
...
handlers
,
};
return
createApolloProvider
([
[
dastScannerProfilesQuery
,
requestHandlers
.
dastScannerProfiles
],
[
dastSiteProfilesQuery
,
requestHandlers
.
dastSiteProfiles
],
]);
};
const
subjectMounterFactory
=
(
mountFn
=
shallowMount
)
=>
(
options
=
{},
withHandlers
)
=>
{
localVue
=
createLocalVue
();
let
defaultMocks
=
{
$apollo
:
{
mutate
:
jest
.
fn
(),
queries
:
{
scannerProfiles
:
{},
siteProfiles
:
{},
},
addSmartQuery
:
jest
.
fn
(),
},
};
let
apolloProvider
;
if
(
withHandlers
)
{
apolloProvider
=
createMockApolloProvider
(
withHandlers
);
defaultMocks
=
{};
}
subject
=
mountFn
(
OnDemandScansForm
,
merge
(
...
...
@@ -76,7 +103,7 @@ describe('OnDemandScansForm', () => {
},
},
},
options
,
{
...
options
,
localVue
,
apolloProvider
}
,
{
data
()
{
return
{
...
options
.
data
};
...
...
@@ -289,4 +316,25 @@ describe('OnDemandScansForm', () => {
});
},
);
describe
.
each
`
profileType | query | field | profiles
${
'
scanner
'
}
|
${
'
dastScannerProfiles
'
}
|
${
'
selectedScannerProfileId
'
}
|
${
scannerProfiles
}
${
'
site
'
}
|
${
'
dastSiteProfiles
'
}
|
${
'
selectedSiteProfileId
'
}
|
${
siteProfiles
}
`
(
'
when there is a single $profileType profile
'
,
({
query
,
field
,
profiles
})
=>
{
const
[
profile
]
=
profiles
;
beforeEach
(()
=>
{
mountShallowSubject
(
{},
{
[
query
]:
jest
.
fn
().
mockResolvedValue
(
responses
[
query
]([
profile
])),
},
);
});
it
(
'
automatically selects the only available profile
'
,
()
=>
{
expect
(
subject
.
vm
[
field
]).
toBe
(
profile
.
id
);
});
});
});
ee/spec/frontend/on_demand_scans/components/profile_selector/profile_selector_spec.js
View file @
fcce1b08
...
...
@@ -2,7 +2,7 @@ import { GlDropdownItem } from '@gitlab/ui';
import
{
mount
}
from
'
@vue/test-utils
'
;
import
{
merge
}
from
'
lodash
'
;
import
OnDemandScansProfileSelector
from
'
ee/on_demand_scans/components/profile_selector/profile_selector.vue
'
;
import
{
scannerProfiles
}
from
'
../../mock_data
'
;
import
{
scannerProfiles
}
from
'
../../mock
s/mock
_data
'
;
describe
(
'
OnDemandScansProfileSelector
'
,
()
=>
{
let
wrapper
;
...
...
ee/spec/frontend/on_demand_scans/components/profile_selector/scanner_profile_selector_spec.js
View file @
fcce1b08
...
...
@@ -2,7 +2,7 @@ import { mount, shallowMount } from '@vue/test-utils';
import
{
merge
}
from
'
lodash
'
;
import
ProfileSelector
from
'
ee/on_demand_scans/components/profile_selector/profile_selector.vue
'
;
import
OnDemandScansScannerProfileSelector
from
'
ee/on_demand_scans/components/profile_selector/scanner_profile_selector.vue
'
;
import
{
scannerProfiles
}
from
'
../../mock_data
'
;
import
{
scannerProfiles
}
from
'
../../mock
s/mock
_data
'
;
const
TEST_LIBRARY_PATH
=
'
/test/scanner/profiles/library/path
'
;
const
TEST_NEW_PATH
=
'
/test/new/scanner/profile/path
'
;
...
...
ee/spec/frontend/on_demand_scans/components/profile_selector/site_profile_selector_spec.js
View file @
fcce1b08
...
...
@@ -2,7 +2,7 @@ import { mount, shallowMount } from '@vue/test-utils';
import
{
merge
}
from
'
lodash
'
;
import
ProfileSelector
from
'
ee/on_demand_scans/components/profile_selector/profile_selector.vue
'
;
import
OnDemandScansSiteProfileSelector
from
'
ee/on_demand_scans/components/profile_selector/site_profile_selector.vue
'
;
import
{
siteProfiles
}
from
'
../../mock_data
'
;
import
{
siteProfiles
}
from
'
../../mock
s/mock
_data
'
;
const
TEST_LIBRARY_PATH
=
'
/test/site/profiles/library/path
'
;
const
TEST_NEW_PATH
=
'
/test/new/site/profile/path
'
;
...
...
ee/spec/frontend/on_demand_scans/mocks/apollo_mocks.js
0 → 100644
View file @
fcce1b08
import
{
scannerProfiles
,
siteProfiles
}
from
'
./mock_data
'
;
const
defaults
=
{
pageInfo
:
{
hasNextPage
:
false
,
hasPreviousPage
:
false
,
startCursor
:
null
,
endCursor
:
null
,
},
};
export
const
dastScannerProfiles
=
(
profiles
=
scannerProfiles
)
=>
({
data
:
{
project
:
{
scannerProfiles
:
{
...
defaults
,
edges
:
profiles
.
map
(
profile
=>
({
cursor
:
''
,
node
:
profile
,
})),
},
},
},
});
export
const
dastSiteProfiles
=
(
profiles
=
siteProfiles
)
=>
({
data
:
{
project
:
{
siteProfiles
:
{
...
defaults
,
edges
:
profiles
.
map
(
profile
=>
({
cursor
:
''
,
node
:
profile
,
})),
},
},
},
});
ee/spec/frontend/on_demand_scans/mock_data.js
→
ee/spec/frontend/on_demand_scans/mock
s/mock
_data.js
View file @
fcce1b08
...
...
@@ -7,6 +7,7 @@ export const scannerProfiles = [
scanType
:
'
PASSIVE
'
,
useAjaxSpider
:
false
,
showDebugMessages
:
false
,
editPath
:
'
/scanner_profile/edit/1
'
,
},
{
id
:
'
gid://gitlab/DastScannerProfile/2
'
,
...
...
@@ -16,6 +17,7 @@ export const scannerProfiles = [
scanType
:
'
ACTIVE
'
,
useAjaxSpider
:
true
,
showDebugMessages
:
true
,
editPath
:
'
/scanner_profile/edit/2
'
,
},
];
...
...
@@ -24,12 +26,14 @@ export const siteProfiles = [
id
:
'
gid://gitlab/DastSiteProfile/1
'
,
profileName
:
'
Site profile #1
'
,
targetUrl
:
'
https://foo.com
'
,
editPath
:
'
/site_profiles/edit/1
'
,
validationStatus
:
'
PENDING_VALIDATION
'
,
},
{
id
:
'
gid://gitlab/DastSiteProfile/2
'
,
profileName
:
'
Site profile #2
'
,
targetUrl
:
'
https://bar.com
'
,
editPath
:
'
/site_profiles/edit/2
'
,
validationStatus
:
'
PASSED_VALIDATION
'
,
},
];
ee/spec/frontend/security_configuration/dast_scanner_profiles_form/components/dast_scanner_profiles_form_spec.js
View file @
fcce1b08
...
...
@@ -6,7 +6,7 @@ import DastScannerProfileForm from 'ee/security_configuration/dast_scanner_profi
import
{
SCAN_TYPE
}
from
'
ee/security_configuration/dast_scanner_profiles/constants
'
;
import
dastScannerProfileCreateMutation
from
'
ee/security_configuration/dast_scanner_profiles/graphql/dast_scanner_profile_create.mutation.graphql
'
;
import
dastScannerProfileUpdateMutation
from
'
ee/security_configuration/dast_scanner_profiles/graphql/dast_scanner_profile_update.mutation.graphql
'
;
import
{
scannerProfiles
}
from
'
ee_jest/on_demand_scans/mock_data
'
;
import
{
scannerProfiles
}
from
'
ee_jest/on_demand_scans/mock
s/mock
_data
'
;
import
{
TEST_HOST
}
from
'
helpers/test_constants
'
;
import
{
redirectTo
}
from
'
~/lib/utils/url_utility
'
;
...
...
ee/spec/frontend/security_configuration/dast_site_profiles_form/components/dast_site_profile_form_spec.js
View file @
fcce1b08
...
...
@@ -7,7 +7,7 @@ import VueApollo from 'vue-apollo';
import
DastSiteProfileForm
from
'
ee/security_configuration/dast_site_profiles_form/components/dast_site_profile_form.vue
'
;
import
dastSiteProfileCreateMutation
from
'
ee/security_configuration/dast_site_profiles_form/graphql/dast_site_profile_create.mutation.graphql
'
;
import
dastSiteProfileUpdateMutation
from
'
ee/security_configuration/dast_site_profiles_form/graphql/dast_site_profile_update.mutation.graphql
'
;
import
{
siteProfiles
}
from
'
ee_jest/on_demand_scans/mock_data
'
;
import
{
siteProfiles
}
from
'
ee_jest/on_demand_scans/mock
s/mock
_data
'
;
import
*
as
responses
from
'
ee_jest/security_configuration/dast_site_profiles_form/mock_data/apollo_mock
'
;
import
{
TEST_HOST
}
from
'
helpers/test_constants
'
;
import
waitForPromises
from
'
jest/helpers/wait_for_promises
'
;
...
...
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