@@ -29,34 +29,49 @@ const schema = {
2929 required : [ "id" ] ,
3030} ;
3131
32+ const keepNull = { nullMeansUnset : false } ;
33+ const dropNull = { nullMeansUnset : true } ;
34+
3235describe ( "stripPlaceholderArguments" , ( ) => {
3336 test ( "forwards empty and whitespace strings the property schema permits" , ( ) => {
3437 const args = { query : "" , note : "" , team : " " , suffix : "" , stage : "" } ;
35- expect ( stripPlaceholderArguments ( args , schema ) ) . toEqual ( args ) ;
38+ expect ( stripPlaceholderArguments ( args , schema , keepNull ) ) . toEqual ( args ) ;
3639 } ) ;
3740
3841 test ( "drops an empty or whitespace string where minLength is at least 1" , ( ) => {
3942 expect (
40- stripPlaceholderArguments ( { customView : " " , query : "x" } , schema ) ,
43+ stripPlaceholderArguments (
44+ { customView : " " , query : "x" } ,
45+ schema ,
46+ keepNull ,
47+ ) ,
4148 ) . toEqual ( { query : "x" } ) ;
42- expect ( stripPlaceholderArguments ( { customView : "" } , schema ) ) . toEqual ( { } ) ;
49+ expect (
50+ stripPlaceholderArguments ( { customView : "" } , schema , keepNull ) ,
51+ ) . toEqual ( { } ) ;
4352 } ) ;
4453
4554 test ( "drops an empty string that an enum, const, or pattern rejects" , ( ) => {
4655 expect (
47- stripPlaceholderArguments ( { state : "" , scope : " " , slug : "" } , schema ) ,
56+ stripPlaceholderArguments (
57+ { state : "" , scope : " " , slug : "" } ,
58+ schema ,
59+ keepNull ,
60+ ) ,
4861 ) . toEqual ( { } ) ;
4962 } ) ;
5063
5164 test ( "forwards an empty string when the pattern does not compile" , ( ) => {
52- expect ( stripPlaceholderArguments ( { malformed : "" } , schema ) ) . toEqual ( {
65+ expect (
66+ stripPlaceholderArguments ( { malformed : "" } , schema , keepNull ) ,
67+ ) . toEqual ( {
5368 malformed : "" ,
5469 } ) ;
5570 } ) ;
5671
5772 test ( "drops an empty array only where minItems is at least 1" , ( ) => {
5873 expect (
59- stripPlaceholderArguments ( { fields : [ ] , labels : [ ] } , schema ) ,
74+ stripPlaceholderArguments ( { fields : [ ] , labels : [ ] } , schema , keepNull ) ,
6075 ) . toEqual ( { fields : [ ] } ) ;
6176 } ) ;
6277
@@ -65,48 +80,61 @@ describe("stripPlaceholderArguments", () => {
6580 stripPlaceholderArguments (
6681 { priority : "" , includeArchived : " " , query : [ ] } ,
6782 schema ,
83+ keepNull ,
6884 ) ,
6985 ) . toEqual ( { } ) ;
7086 } ) ;
7187
7288 test ( "drops null only where the property schema disallows it" , ( ) => {
7389 expect (
74- stripPlaceholderArguments ( { team : null , priority : null } , schema ) ,
90+ stripPlaceholderArguments (
91+ { team : null , priority : null } ,
92+ schema ,
93+ keepNull ,
94+ ) ,
7595 ) . toEqual ( { } ) ;
7696 const nullable = {
7797 assignee : null ,
7898 parentId : null ,
7999 cycle : null ,
80100 anything : null ,
81101 } ;
82- expect ( stripPlaceholderArguments ( nullable , schema ) ) . toEqual ( nullable ) ;
102+ expect ( stripPlaceholderArguments ( nullable , schema , keepNull ) ) . toEqual (
103+ nullable ,
104+ ) ;
83105 } ) ;
84106
85107 test ( "drops a composite value only when every branch rejects it" , ( ) => {
86- expect ( stripPlaceholderArguments ( { view : " " } , schema ) ) . toEqual ( { } ) ;
87- expect ( stripPlaceholderArguments ( { view : null } , schema ) ) . toEqual ( {
88- view : null ,
89- } ) ;
90- expect ( stripPlaceholderArguments ( { label : "" } , schema ) ) . toEqual ( {
108+ expect ( stripPlaceholderArguments ( { view : " " } , schema , keepNull ) ) . toEqual (
109+ { } ,
110+ ) ;
111+ expect ( stripPlaceholderArguments ( { view : null } , schema , keepNull ) ) . toEqual (
112+ {
113+ view : null ,
114+ } ,
115+ ) ;
116+ expect ( stripPlaceholderArguments ( { label : "" } , schema , keepNull ) ) . toEqual ( {
91117 label : "" ,
92118 } ) ;
93119 } ) ;
94120
95121 test ( "never changes required arguments" , ( ) => {
96- expect ( stripPlaceholderArguments ( { id : "" } , schema ) ) . toEqual ( { id : "" } ) ;
97- expect ( stripPlaceholderArguments ( { id : null } , schema ) ) . toEqual ( {
122+ expect ( stripPlaceholderArguments ( { id : "" } , schema , keepNull ) ) . toEqual ( {
123+ id : "" ,
124+ } ) ;
125+ expect ( stripPlaceholderArguments ( { id : null } , schema , keepNull ) ) . toEqual ( {
98126 id : null ,
99127 } ) ;
100128 } ) ;
101129
102130 test ( "keeps zero and false" , ( ) => {
103131 const args = { priority : 0 , includeArchived : false } ;
104- expect ( stripPlaceholderArguments ( args , schema ) ) . toEqual ( args ) ;
132+ expect ( stripPlaceholderArguments ( args , schema , keepNull ) ) . toEqual ( args ) ;
105133 } ) ;
106134
107135 test ( "keeps meaningful values and leaves the caller's object intact" , ( ) => {
108136 const args = { query : "release" , fields : [ "title" ] , customView : "" } ;
109- expect ( stripPlaceholderArguments ( args , schema ) ) . toEqual ( {
137+ expect ( stripPlaceholderArguments ( args , schema , keepNull ) ) . toEqual ( {
110138 query : "release" ,
111139 fields : [ "title" ] ,
112140 } ) ;
@@ -119,22 +147,69 @@ describe("stripPlaceholderArguments", () => {
119147
120148 test ( "forwards a key the schema does not declare" , ( ) => {
121149 expect (
122- stripPlaceholderArguments ( { id : "CL-1" , extra : "" } , schema ) ,
150+ stripPlaceholderArguments ( { id : "CL-1" , extra : "" } , schema , keepNull ) ,
123151 ) . toEqual ( { id : "CL-1" , extra : "" } ) ;
124152 } ) ;
125153
126154 test ( "returns missing or non-object arguments as-is" , ( ) => {
127- expect ( stripPlaceholderArguments ( null , schema ) ) . toBeNull ( ) ;
128- expect ( stripPlaceholderArguments ( undefined , schema ) ) . toBeUndefined ( ) ;
129- expect ( stripPlaceholderArguments ( "query" , schema ) ) . toBe ( "query" ) ;
155+ expect ( stripPlaceholderArguments ( null , schema , keepNull ) ) . toBeNull ( ) ;
156+ expect (
157+ stripPlaceholderArguments ( undefined , schema , keepNull ) ,
158+ ) . toBeUndefined ( ) ;
159+ expect ( stripPlaceholderArguments ( "query" , schema , keepNull ) ) . toBe ( "query" ) ;
130160 const list = [ "" ] ;
131- expect ( stripPlaceholderArguments ( list , schema ) ) . toBe ( list ) ;
161+ expect ( stripPlaceholderArguments ( list , schema , keepNull ) ) . toBe ( list ) ;
132162 } ) ;
133163
134164 test ( "forwards arguments unchanged when the schema shape is unusable" , ( ) => {
135165 const args = { query : "" } ;
136166 expect (
137- stripPlaceholderArguments ( args , { type : "object" , required : "query" } ) ,
167+ stripPlaceholderArguments (
168+ args ,
169+ { type : "object" , required : "query" } ,
170+ keepNull ,
171+ ) ,
138172 ) . toEqual ( args ) ;
139173 } ) ;
140174} ) ;
175+
176+ describe ( "stripPlaceholderArguments with nullMeansUnset" , ( ) => {
177+ test ( "drops null on optional properties whose schema permits it" , ( ) => {
178+ expect (
179+ stripPlaceholderArguments (
180+ {
181+ assignee : null ,
182+ parentId : null ,
183+ cycle : null ,
184+ view : null ,
185+ anything : null ,
186+ query : "release" ,
187+ } ,
188+ schema ,
189+ dropNull ,
190+ ) ,
191+ ) . toEqual ( { query : "release" } ) ;
192+ } ) ;
193+
194+ test ( "still applies the rejected-placeholder rule to other values" , ( ) => {
195+ expect (
196+ stripPlaceholderArguments (
197+ { customView : " " , fields : [ ] , priority : 0 , team : null } ,
198+ schema ,
199+ dropNull ,
200+ ) ,
201+ ) . toEqual ( { fields : [ ] , priority : 0 } ) ;
202+ } ) ;
203+
204+ test ( "never changes required arguments" , ( ) => {
205+ expect ( stripPlaceholderArguments ( { id : null } , schema , dropNull ) ) . toEqual ( {
206+ id : null ,
207+ } ) ;
208+ } ) ;
209+
210+ test ( "forwards null on a key the schema does not declare" , ( ) => {
211+ expect (
212+ stripPlaceholderArguments ( { extra : null } , schema , dropNull ) ,
213+ ) . toEqual ( { extra : null } ) ;
214+ } ) ;
215+ } ) ;
0 commit comments