From 1c11b5b7cd6e6a3d5d65d840e5d6ba024dd90f55 Mon Sep 17 00:00:00 2001 From: Leos Stejskal Date: Wed, 4 Oct 2023 12:31:56 +0200 Subject: [PATCH] fix: Replace 'vCPU' with 'vcpus' GCE shows vCPU in the description of the machine, not the vcpus. Refs: HMS-2301 --- src/Utils/querySearch.js | 3 ++- src/Utils/querySearch.test.js | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 src/Utils/querySearch.test.js 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]'); + }); +});