11import { describe , it , expect } from 'vitest'
22import { validateStringFilter , checkStringFilterMatch } from './filter.js'
3- import { StringFilter } from './filter.pb.js'
43
54describe ( 'validateStringFilter' , ( ) => {
65 it ( 'should return null for null/undefined filter' , ( ) => {
@@ -70,12 +69,18 @@ describe('checkStringFilterMatch', () => {
7069
7170 describe ( 'values filter' , ( ) => {
7271 it ( 'should match when value is in values array' , ( ) => {
73- expect ( checkStringFilterMatch ( { values : [ 'test1' , 'test2' ] } , 'test1' ) ) . toBe ( true )
74- expect ( checkStringFilterMatch ( { values : [ 'test1' , 'test2' ] } , 'test2' ) ) . toBe ( true )
72+ expect (
73+ checkStringFilterMatch ( { values : [ 'test1' , 'test2' ] } , 'test1' ) ,
74+ ) . toBe ( true )
75+ expect (
76+ checkStringFilterMatch ( { values : [ 'test1' , 'test2' ] } , 'test2' ) ,
77+ ) . toBe ( true )
7578 } )
7679
7780 it ( 'should not match when value is not in values array' , ( ) => {
78- expect ( checkStringFilterMatch ( { values : [ 'test1' , 'test2' ] } , 'test3' ) ) . toBe ( false )
81+ expect (
82+ checkStringFilterMatch ( { values : [ 'test1' , 'test2' ] } , 'test3' ) ,
83+ ) . toBe ( false )
7984 } )
8085
8186 it ( 'should return true when values array is empty' , ( ) => {
@@ -101,11 +106,15 @@ describe('checkStringFilterMatch', () => {
101106
102107 describe ( 'hasPrefix filter' , ( ) => {
103108 it ( 'should match when string has prefix' , ( ) => {
104- expect ( checkStringFilterMatch ( { hasPrefix : 'test' } , 'test123' ) ) . toBe ( true )
109+ expect ( checkStringFilterMatch ( { hasPrefix : 'test' } , 'test123' ) ) . toBe (
110+ true ,
111+ )
105112 } )
106113
107114 it ( 'should not match when string does not have prefix' , ( ) => {
108- expect ( checkStringFilterMatch ( { hasPrefix : 'test' } , 'abc123' ) ) . toBe ( false )
115+ expect ( checkStringFilterMatch ( { hasPrefix : 'test' } , 'abc123' ) ) . toBe (
116+ false ,
117+ )
109118 } )
110119 } )
111120
@@ -115,7 +124,9 @@ describe('checkStringFilterMatch', () => {
115124 } )
116125
117126 it ( 'should not match when string does not have suffix' , ( ) => {
118- expect ( checkStringFilterMatch ( { hasSuffix : '123' } , 'test456' ) ) . toBe ( false )
127+ expect ( checkStringFilterMatch ( { hasSuffix : '123' } , 'test456' ) ) . toBe (
128+ false ,
129+ )
119130 } )
120131 } )
121132
@@ -131,27 +142,42 @@ describe('checkStringFilterMatch', () => {
131142
132143 describe ( 'combined filters' , ( ) => {
133144 it ( 'should match when all filters match' , ( ) => {
134- expect ( checkStringFilterMatch ( {
135- notEmpty : true ,
136- hasPrefix : 'test' ,
137- hasSuffix : '123'
138- } , 'test123' ) ) . toBe ( true )
145+ expect (
146+ checkStringFilterMatch (
147+ {
148+ notEmpty : true ,
149+ hasPrefix : 'test' ,
150+ hasSuffix : '123' ,
151+ } ,
152+ 'test123' ,
153+ ) ,
154+ ) . toBe ( true )
139155 } )
140156
141157 it ( 'should not match when any filter fails' , ( ) => {
142- expect ( checkStringFilterMatch ( {
143- notEmpty : true ,
144- hasPrefix : 'test' ,
145- hasSuffix : '456'
146- } , 'test123' ) ) . toBe ( false )
158+ expect (
159+ checkStringFilterMatch (
160+ {
161+ notEmpty : true ,
162+ hasPrefix : 'test' ,
163+ hasSuffix : '456' ,
164+ } ,
165+ 'test123' ,
166+ ) ,
167+ ) . toBe ( false )
147168 } )
148169
149170 it ( 'should handle complex combination' , ( ) => {
150- expect ( checkStringFilterMatch ( {
151- re : '^test' ,
152- contains : '12' ,
153- hasSuffix : '3'
154- } , 'test123' ) ) . toBe ( true )
171+ expect (
172+ checkStringFilterMatch (
173+ {
174+ re : '^test' ,
175+ contains : '12' ,
176+ hasSuffix : '3' ,
177+ } ,
178+ 'test123' ,
179+ ) ,
180+ ) . toBe ( true )
155181 } )
156182 } )
157183} )
0 commit comments