Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UBERF-4267: fix mergeQuery, provide a test case for it #3985

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/core/src/__tests__/memdb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,5 +430,18 @@ describe('memdb', () => {

expect(mergeQueries({ age: { $lt: 20 } } as any, { age: { $gt: 25 } } as any)).toEqual({ age: { $gt: 25 } })
expect(mergeQueries({ age: { $gt: 25 } } as any, { age: { $lt: 20 } } as any)).toEqual({ age: { $lt: 20 } })

const query4 = {
space: { $in: [id1] }
} as any
const query5 = {
space: { $in: [id2, id1] }
} as any
const resQuery45 = {
space: id1
} as any

expect(mergeQueries(query4, query5)).toEqual(resQuery45)
expect(mergeQueries(query5, query4)).toEqual(resQuery45)
})
})
2 changes: 1 addition & 1 deletion packages/core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ function getInNiN (query1: any, query2: any): Object {
aIn.length - bIn.length < 0 ? bIn.filter((c: any) => aIn.includes(c)) : aIn.filter((c: any) => bIn.includes(c))
const finalNin = Array.from(new Set([...aNIn, ...bNIn]))
if (finalIn.length === 1 && finalNin.length === 0) {
return aIn[0]
return finalIn[0]
}
if (finalIn.length === 0 && finalNin.length === 1) {
return { $ne: finalNin[0] }
Expand Down