@@ -2,13 +2,13 @@ import { addAddHocFilter } from './modifyQuery';
22
33describe ( 'addAddHocFilter' , ( ) => {
44 describe ( 'array values' , ( ) => {
5- it ( 'unwraps single-element array into a term query' , ( ) => {
5+ it ( 'unwraps single-element array into a phrase query' , ( ) => {
66 const result = addAddHocFilter ( '' , {
77 key : 'attributes.tags' ,
88 operator : '=' ,
99 value : '["paperclip"]' ,
1010 } ) ;
11- expect ( result ) . toBe ( 'attributes.tags:paperclip' ) ;
11+ expect ( result ) . toBe ( 'attributes.tags:" paperclip" ' ) ;
1212 } ) ;
1313
1414 it ( 'unwraps multi-element array into IN set query' , ( ) => {
@@ -20,13 +20,13 @@ describe('addAddHocFilter', () => {
2020 expect ( result ) . toBe ( 'attributes.tags:IN ["paperclip" "stapler"]' ) ;
2121 } ) ;
2222
23- it ( 'negated single-element array produces negated term query' , ( ) => {
23+ it ( 'negated single-element array produces negated phrase query' , ( ) => {
2424 const result = addAddHocFilter ( '' , {
2525 key : 'attributes.tags' ,
2626 operator : '!=' ,
2727 value : '["paperclip"]' ,
2828 } ) ;
29- expect ( result ) . toBe ( '-attributes.tags:paperclip' ) ;
29+ expect ( result ) . toBe ( '-attributes.tags:" paperclip" ' ) ;
3030 } ) ;
3131
3232 it ( 'negated multi-element array produces negated IN set query' , ( ) => {
@@ -44,7 +44,43 @@ describe('addAddHocFilter', () => {
4444 operator : '=' ,
4545 value : '["paperclip"]' ,
4646 } ) ;
47- expect ( result ) . toBe ( 'status:200 AND attributes.tags:paperclip' ) ;
47+ expect ( result ) . toBe ( 'status:200 AND attributes.tags:"paperclip"' ) ;
48+ } ) ;
49+
50+ it ( 'handles single-element array with spaces in value' , ( ) => {
51+ const result = addAddHocFilter ( '' , {
52+ key : 'attributes.tags' ,
53+ operator : '=' ,
54+ value : '["foo bar"]' ,
55+ } ) ;
56+ expect ( result ) . toBe ( 'attributes.tags:"foo bar"' ) ;
57+ } ) ;
58+
59+ it ( 'handles single-element array with colons in value' , ( ) => {
60+ const result = addAddHocFilter ( '' , {
61+ key : 'attributes.tags' ,
62+ operator : '=' ,
63+ value : '["foo:bar"]' ,
64+ } ) ;
65+ expect ( result ) . toBe ( 'attributes.tags:"foo:bar"' ) ;
66+ } ) ;
67+
68+ it ( 'handles multi-element array with spaces in values' , ( ) => {
69+ const result = addAddHocFilter ( '' , {
70+ key : 'attributes.tags' ,
71+ operator : '=' ,
72+ value : '["foo bar","baz qux"]' ,
73+ } ) ;
74+ expect ( result ) . toBe ( 'attributes.tags:IN ["foo bar" "baz qux"]' ) ;
75+ } ) ;
76+
77+ it ( 'handles array values containing double quotes' , ( ) => {
78+ const result = addAddHocFilter ( '' , {
79+ key : 'attributes.tags' ,
80+ operator : '=' ,
81+ value : '["say \\"hello\\""]' ,
82+ } ) ;
83+ expect ( result ) . toBe ( 'attributes.tags:"say \\"hello\\""' ) ;
4884 } ) ;
4985
5086 it ( 'passes through non-array bracket strings unchanged' , ( ) => {
0 commit comments