Skip to content

Commit 893e70c

Browse files
authoredJan 16, 2025··
Merge pull request #128 from preludeorg/fix-skipped-tests
fix: prevent duplicated conditions & restore skipped tests
2 parents be2b050 + 8dde413 commit 893e70c

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed
 

‎src/index.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export default function <T>({
111111
// key is not (null, undefined)
112112
if (key != undefined) {
113113
path += `(${handleValue(key as Value, aliases)})`;
114-
}
114+
}
115115

116116
if (filter || typeof count === 'object')
117117
params.$filter = buildFilter(typeof count === 'object' ? count : filter, aliases);
@@ -195,7 +195,7 @@ function buildFilter<T>(filters: Filter<T> = {}, aliases: Alias[] = [], propPref
195195
const value = (filter as any)[filterKey];
196196
if (value === undefined) {
197197
return result;
198-
}
198+
}
199199

200200
let propName = '';
201201
if (propPrefix) {
@@ -214,7 +214,7 @@ function buildFilter<T>(filters: Filter<T> = {}, aliases: Alias[] = [], propPref
214214

215215
if (filterKey === ITEM_ROOT && Array.isArray(value)) {
216216
return result.concat(
217-
value.map((arrayValue: any) => renderPrimitiveValue(propName, arrayValue))
217+
value.map((arrayValue: any) => renderPrimitiveValue(propName, arrayValue))
218218
)
219219
}
220220

@@ -299,7 +299,7 @@ function buildFilter<T>(filters: Filter<T> = {}, aliases: Alias[] = [], propPref
299299
result.push(`${op}(${propName},${handleValue(value[op], aliases)})`);
300300
} else {
301301
// Nested property
302-
const filter = buildFilterCore(value, aliases, propName);
302+
const filter = buildFilterCore({ [op]: value[op] }, aliases, propName);
303303
if (filter) {
304304
result.push(filter);
305305
}
@@ -350,11 +350,11 @@ function buildFilter<T>(filters: Filter<T> = {}, aliases: Alias[] = [], propPref
350350
}
351351

352352
function getStringCollectionClause(lambdaParameter: string, value: any, collectionOperator: string, propName: string) {
353-
let clause = '';
354-
const conditionOperator = collectionOperator == 'all' ? 'ne' : 'eq';
355-
clause = `${propName}/${collectionOperator}(${lambdaParameter}: ${lambdaParameter} ${conditionOperator} '${value}')`
353+
let clause = '';
354+
const conditionOperator = collectionOperator == 'all' ? 'ne' : 'eq';
355+
clause = `${propName}/${collectionOperator}(${lambdaParameter}: ${lambdaParameter} ${conditionOperator} '${value}')`
356356

357-
return clause;
357+
return clause;
358358
}
359359

360360
function escapeIllegalChars(string: string) {

‎test/index.test.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,15 @@ describe('filter', () => {
132132
expect(actual).toEqual(expected);
133133
});
134134

135-
it.skip('should handle nested properties on the same property (implicit "and")', () => {
135+
it('should handle nested properties on the same property (implicit "and")', () => {
136136
const filter = {
137137
SomeProp: {
138138
NestedProp1: 1,
139139
NestedProp2: 2,
140140
},
141141
};
142142
const expected =
143-
'?$filter=(SomeProp/NestedProp1 eq 1 and SomeProp/NestedProp2 eq 2)';
143+
'?$filter=SomeProp/NestedProp1 eq 1 and SomeProp/NestedProp2 eq 2';
144144
const actual = buildQuery({ filter });
145145
expect(actual).toEqual(expected);
146146
});
@@ -466,8 +466,7 @@ describe('filter', () => {
466466
expect(actual).toEqual(expected);
467467
});
468468

469-
// TODO: duplicating filter clauses `(Prop2/NestedProp2/DeeplyNestedProp2 eq 2 and Prop2/NestedProp3 ne null)`. Still logically the same result
470-
it.skip('should handle nested logical operators and deeply nested properties on same property using objects (shorthand)', () => {
469+
it('should handle nested logical operators and deeply nested properties on same property using objects (shorthand)', () => {
471470
const filter = {
472471
Prop1: {
473472
NestedProp1: 1,

0 commit comments

Comments
 (0)
Please sign in to comment.