Skip to content

Commit 20fbc88

Browse files
committed
Adding initial end to end testing for the advanced search manager
1 parent 184f42e commit 20fbc88

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// For a more comprehensive set of test cases, see the tests
2+
// in test_cases/search_*
3+
4+
import { AdvancedSearchManager, SearchAPIOptions } from "./AdvancedSearchManager.js";
5+
import { SearchProviderSpec } from '../adapters/search/SearchAdapter.js';
6+
7+
describe(`AdvancedSearchManager (e2e)`, () => {
8+
// because e2e testing is very specific to a dataset, we need to make sure we use the same opensearch dataset in cve-fixtures
9+
// as was designed for this test.
10+
const searchProviderSpec = SearchProviderSpec.getDefaultSearchProviderSpec()
11+
const filters = [
12+
{
13+
match_phrase: {
14+
'containers.cna.metrics.cvssV3_1.baseSeverity': 'MEDIUM'
15+
}
16+
}
17+
];
18+
19+
const rangeObject = {
20+
range: {
21+
'cveMetadata.dateUpdated': {
22+
"gte": new Date('2024-09-09T00:17:27.585Z').toISOString(),
23+
"lte": new Date('2024-12-09T00:17:27.585Z').toISOString(),
24+
}
25+
}
26+
};
27+
28+
const rangeObjects = []
29+
rangeObjects.push(rangeObject);
30+
31+
const options: Partial<SearchAPIOptions> = {
32+
filters,
33+
resultsPerPage: 10,
34+
rangeObjects,
35+
};
36+
37+
const searchText = 'data';
38+
39+
const queryStrings = [
40+
{
41+
query_string: {
42+
query: 'data',
43+
fields: ['containers.cna.descriptions.value'],
44+
default_operator: 'AND'
45+
}
46+
},
47+
];
48+
49+
it('builds queryObj with searchText, filters, and rangeObjects', async () => {
50+
const searchManager = new AdvancedSearchManager(searchProviderSpec);
51+
52+
const resp = await searchManager.apiSearch(searchText, options);
53+
54+
expect(resp.isOk()).toBeTruthy();
55+
const hits = resp['data']['hits'];
56+
expect(hits.total.value).toBe(6);
57+
expect(hits.hits[0]._source.cveMetadata.cveId).toBe('CVE-2024-10451');
58+
});
59+
60+
it('builds queryObj using queryStrings when searchText is null', async () => {
61+
const searchManager = new AdvancedSearchManager(searchProviderSpec);
62+
63+
const resp = await searchManager.apiSearch(null, options, queryStrings);
64+
65+
expect(resp.isOk()).toBeTruthy();
66+
const hits = resp['data']['hits'];
67+
expect(hits.total.value).toBe(6);
68+
expect(hits.hits[0]._source.cveMetadata.cveId).toBe('CVE-2024-10451');
69+
});
70+
71+
it('builds queryObj without must when neither searchText nor queryStrings are provided', async () => {
72+
const searchManager = new AdvancedSearchManager(searchProviderSpec);
73+
74+
const resp = await searchManager.apiSearch(null, options);
75+
76+
expect(resp.isOk()).toBeTruthy();
77+
const hits = resp['data']['hits'];
78+
expect(hits.total.value).toBe(49);
79+
expect(hits.hits[0]._source.cveMetadata.cveId).toBe('CVE-2022-39024');
80+
});
81+
});

0 commit comments

Comments
 (0)