diff --git a/src/Utils/querySearch.js b/src/Utils/querySearch.js index c9638dd3..3a0de039 100644 --- a/src/Utils/querySearch.js +++ b/src/Utils/querySearch.js @@ -2,9 +2,10 @@ const jsonata = require('jsonata'); const OPERATORS = ['<', '>', '=']; -const parseQuery = (query) => { +export const parseQuery = (query) => { query = query.replace('memory', 'memory_mib'); query = query.replace('storage', 'storage_gb'); + query = query.replace(/vcpu(\W|$)/i, 'vcpus$1'); if (OPERATORS.every((operator) => !query.includes(operator))) { query = `name ~> /${query}/i`; } diff --git a/src/Utils/querySearch.test.js b/src/Utils/querySearch.test.js new file mode 100644 index 00000000..f46eff9d --- /dev/null +++ b/src/Utils/querySearch.test.js @@ -0,0 +1,9 @@ +import { parseQuery } from './querySearch'; + +describe('parseQuery', () => { + test('replaces vcpu by vcpus', async () => { + expect(parseQuery('vcpu > 2')).toBe('types[vcpus > 2]'); + expect(parseQuery('vcpu> 2')).toBe('types[vcpus> 2]'); + expect(parseQuery('vCPU > 2')).toBe('types[vcpus > 2]'); + }); +});