Commit 8949b9dd authored by Brandon Labuschagne's avatar Brandon Labuschagne

Merge branch '331401-convert-filter-to-lowercase' into 'master'

Normalize reportType filter for graphql query

See merge request gitlab-org/gitlab!68546
parents 773509d1 46a716d0
......@@ -54,12 +54,8 @@ export default {
pipelineId: this.pipeline.iid,
fullPath: this.projectFullPath,
first: VULNERABILITIES_PER_PAGE,
// Two issues here:
// 1. Severity filter, unlike vulnerabilities, need to be lower case.
// 2. Empty array returns an empty result, therefore we need to pass undefined in that case.
severity: this.filters?.severity?.length
? this.filters.severity.map((s) => s.toLowerCase())
: undefined,
reportType: this.normalizeForGraphQLQuery('reportType'),
severity: this.normalizeForGraphQLQuery('severity'),
};
},
update: ({ project }) =>
......@@ -93,6 +89,14 @@ export default {
},
},
methods: {
// Two issues here:
// 1. Severity and reportType filters, unlike in vulnerabilities, need to be lower case.
// 2. Empty array returns an empty result, therefore we need to pass undefined in that case.
normalizeForGraphQLQuery(filterName) {
return this.filters?.[filterName]?.length
? this.filters[filterName].map((s) => s.toLowerCase())
: undefined;
},
dismissError() {
this.errorLoadingFindings = false;
},
......
......@@ -41,8 +41,9 @@ describe('Pipeline findings', () => {
});
};
const createWrapperWithApollo = (resolver) => {
const createWrapperWithApollo = (resolver, data) => {
return createWrapper({
...data,
apolloProvider: createMockApollo([[pipelineFindingsQuery, resolver]]),
});
};
......@@ -136,4 +137,21 @@ describe('Pipeline findings', () => {
expect(findAlert().exists()).toBe(true);
});
});
describe('filtering', () => {
it.each(['reportType', 'severity'])(
`normalizes the GraphQL's query variable for the "%s" filter`,
(filterName) => {
const filterValues = ['FOO', 'BAR', 'FOO_BAR'];
const normalizedFilterValues = ['foo', 'bar', 'foo_bar'];
const queryMock = jest.fn().mockResolvedValue();
createWrapperWithApollo(queryMock, { props: { filters: { [filterName]: filterValues } } });
expect(queryMock.mock.calls[0][0]).toMatchObject({
[filterName]: normalizedFilterValues,
});
},
);
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment