Files
klz-cables.com/.pnpm-store/v10/files/9b/54833963fc94256e83e28acc85fbf865e6b04b78d1c240ae37aa6b7c6590572dc97172e22cdbf3a6d57b1ee7a99034157feedb4776d0f13b3d9a4394e65821
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

131 lines
3.5 KiB
Plaintext

import { describe, it, expect } from 'vitest';
import { combineWhereConstraints } from './combineWhereConstraints.js';
describe('combineWhereConstraints', ()=>{
it('should merge matching constraint keys', async ()=>{
const constraint = {
test: {
equals: 'value'
}
};
// should merge and queries
const andConstraint = {
and: [
constraint
]
};
expect(combineWhereConstraints([
andConstraint
], 'and')).toEqual(andConstraint);
// should merge multiple and queries
expect(combineWhereConstraints([
andConstraint,
andConstraint
], 'and')).toEqual({
and: [
constraint,
constraint
]
});
// should merge or queries
const orConstraint = {
or: [
constraint
]
};
expect(combineWhereConstraints([
orConstraint
], 'or')).toEqual(orConstraint);
// should merge multiple or queries
expect(combineWhereConstraints([
orConstraint,
orConstraint
], 'or')).toEqual({
or: [
constraint,
constraint
]
});
});
it('should push mismatching constraints keys into `as` key', async ()=>{
const constraint = {
test: {
equals: 'value'
}
};
// should push `and` into `or` key
const andConstraint = {
and: [
constraint
]
};
expect(combineWhereConstraints([
andConstraint
], 'or')).toEqual({
or: [
andConstraint
]
});
// should push `or` into `and` key
const orConstraint = {
or: [
constraint
]
};
expect(combineWhereConstraints([
orConstraint
], 'and')).toEqual({
and: [
orConstraint
]
});
// should merge `and` but push `or` into `and` key
expect(combineWhereConstraints([
andConstraint,
orConstraint
], 'and')).toEqual({
and: [
constraint,
orConstraint
]
});
});
it('should push non and/or constraint key into `as` key', async ()=>{
const basicConstraint = {
test: {
equals: 'value'
}
};
expect(combineWhereConstraints([
basicConstraint
], 'and')).toEqual({
and: [
basicConstraint
]
});
expect(combineWhereConstraints([
basicConstraint
], 'or')).toEqual({
or: [
basicConstraint
]
});
});
it('should return an empty object when no constraints are provided', async ()=>{
expect(combineWhereConstraints([], 'and')).toEqual({});
expect(combineWhereConstraints([], 'or')).toEqual({});
});
it('should return an empty object when all constraints are empty', async ()=>{
expect(combineWhereConstraints([
{},
{},
undefined
], 'and')).toEqual({});
expect(combineWhereConstraints([
{},
{},
undefined
], 'or')).toEqual({});
});
});
//# sourceMappingURL=combineWhereConstraints.spec.js.map