Skip to content

Commit

Permalink
fix(core): Fix filtering on list queries of tree entities
Browse files Browse the repository at this point in the history
Fixes #3107. This reinstates the correct use of the joiner string
which was accidentally lost in commit bcfcf7d.
  • Loading branch information
michaelbromley committed Oct 14, 2024
1 parent e57cc1b commit 227da05
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 18 deletions.
30 changes: 30 additions & 0 deletions packages/core/e2e/collection.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,21 @@ describe('Collection resolver', () => {
139900, 219900, 229900,
]);
});

// https://github.com/vendure-ecommerce/vendure/issues/3107
it('collection list with translations, filtered by name', async () => {
const { collections } = await adminClient.query(GET_COLLECTION_LIST_WITH_TRANSLATIONS, {
options: {
filter: {
name: {
eq: 'Electronics',
},
},
},
});

expect(collections.items.length).toBeDefined();
});
});

describe('moveCollection', () => {
Expand Down Expand Up @@ -2413,6 +2428,21 @@ export const GET_COLLECTION_LIST = gql`
${COLLECTION_FRAGMENT}
`;

export const GET_COLLECTION_LIST_WITH_TRANSLATIONS = gql`
query GetCollectionListWithTranslations($options: CollectionListOptions) {
collections(options: $options) {
items {
id
name
translations {
id
name
}
}
}
}
`;

export const MOVE_COLLECTION = gql`
mutation MoveCollection($input: MoveCollectionInput!) {
moveCollection(input: $input) {
Expand Down
55 changes: 38 additions & 17 deletions packages/core/e2e/list-query-builder.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,16 @@ describe('ListQueryBuilder', () => {

expect(testEntities.totalItems).toBe(6);
expect(getItemLabels(testEntities.items)).toEqual(['A', 'B', 'C', 'D', 'E', 'F']);
expect(testEntities.items.map((i: any) => i.name)).toEqual(expect.arrayContaining([
'apple',
'bike',
'cake',
'dog',
'egg',
'baum', // if default en lang does not exist, use next available lang
]));
expect(testEntities.items.map((i: any) => i.name)).toEqual(
expect.arrayContaining([
'apple',
'bike',
'cake',
'dog',
'egg',
'baum', // if default en lang does not exist, use next available lang
]),
);
});

it('all de', async () => {
Expand All @@ -77,14 +79,16 @@ describe('ListQueryBuilder', () => {

expect(testEntities.totalItems).toBe(6);
expect(getItemLabels(testEntities.items)).toEqual(['A', 'B', 'C', 'D', 'E', 'F']);
expect(testEntities.items.map((i: any) => i.name)).toEqual(expect.arrayContaining([
'apfel',
'fahrrad',
'kuchen',
'hund',
'egg', // falls back to en translation when de doesn't exist
'baum',
]));
expect(testEntities.items.map((i: any) => i.name)).toEqual(
expect.arrayContaining([
'apfel',
'fahrrad',
'kuchen',
'hund',
'egg', // falls back to en translation when de doesn't exist
'baum',
]),
);
});

it('take', async () => {
Expand Down Expand Up @@ -278,6 +282,20 @@ describe('ListQueryBuilder', () => {
expect(getItemLabels(testEntities.items)).toEqual(['A', 'C', 'E']);
});

it('filtering on translatable string', async () => {
const { testEntities } = await adminClient.query(GET_LIST_WITH_TRANSLATIONS, {
options: {
filter: {
name: {
contains: 'g',
},
},
},
});

expect(getItemLabels(testEntities.items)).toEqual(['D', 'E']);
});

describe('regex', () => {
it('simple substring', async () => {
const { testEntities } = await adminClient.query(GET_LIST, {
Expand Down Expand Up @@ -1208,7 +1226,10 @@ describe('ListQueryBuilder', () => {
// https://github.com/vendure-ecommerce/vendure/issues/1586
it('using the getMany() of the resulting QueryBuilder', async () => {
const { testEntitiesGetMany } = await adminClient.query(GET_ARRAY_LIST, {});
const actualPrices = testEntitiesGetMany.sort(sortById).map((x: any) => x.price).sort((a: number, b: number) => a - b);
const actualPrices = testEntitiesGetMany
.sort(sortById)
.map((x: any) => x.price)
.sort((a: number, b: number) => a - b);
const expectedPrices = [11, 9, 22, 14, 13, 33].sort((a, b) => a - b);
expect(actualPrices).toEqual(expectedPrices);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export function joinTreeRelationsDynamically<T extends VendureEntity>(
}
const nextAlias = DriverUtils.buildAlias(
qb.connection.driver,
{ shorten: false },
{ shorten: false, joiner: joinConnector },
currentAlias,
part.replace(/\./g, '_'),
);
Expand Down

0 comments on commit 227da05

Please sign in to comment.