Skip to content

Commit 40fedef

Browse files
fix(core): Improve ManyToOne filters E2E coverage and assert Plants collection exists
1 parent c33b881 commit 40fedef

1 file changed

Lines changed: 14 additions & 26 deletions

File tree

packages/core/e2e/many-to-one-filters.e2e-spec.ts

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DefaultJobQueuePlugin, LanguageCode } from '@vendure/core';
1+
import { CollectionService, DefaultJobQueuePlugin, LanguageCode, RequestContextService } from '@vendure/core';
22
import { createTestEnvironment } from '@vendure/testing';
33
import { gql } from 'graphql-tag';
44
import path from 'path';
@@ -85,7 +85,9 @@ describe('Collection Batch Loading Correctness', () => {
8585
`;
8686
const collectionsResult: any = await adminClient.query(GET_COLLECTIONS);
8787
const plants = collectionsResult.collections.items.find((c: any) => c.name === 'Plants');
88-
plantsCollectionId = plants?.id;
88+
expect(plants).toBeDefined();
89+
expect(plants?.id).toBeTruthy();
90+
plantsCollectionId = plants.id;
8991

9092
// Create Electronics collection
9193
const CREATE_COLLECTION = gql`
@@ -141,30 +143,16 @@ describe('Collection Batch Loading Correctness', () => {
141143
it('returns empty map for empty input', async () => {
142144
// This test verifies that the batch loading service method handles
143145
// empty collection ID arrays gracefully by returning an empty Map.
144-
const GET_COLLECTIONS_WITH_VARIANTS = gql`
145-
query GetCollectionsWithVariants {
146-
collections(options: { take: 10 }) {
147-
items {
148-
id
149-
name
150-
productVariants {
151-
items {
152-
id
153-
}
154-
totalItems
155-
}
156-
}
157-
}
158-
}
159-
`;
160-
const result: any = await adminClient.query(GET_COLLECTIONS_WITH_VARIANTS);
161-
const collections = result.collections.items;
162-
// Verify we get valid collections without errors when the query includes productVariants
163-
expect(Array.isArray(collections)).toBe(true);
164-
for (const collection of collections) {
165-
expect(Array.isArray(collection.productVariants.items)).toBe(true);
166-
expect(typeof collection.productVariants.totalItems).toBe('number');
167-
}
146+
const collectionService = server.app.get(CollectionService);
147+
const requestContextService = server.app.get(RequestContextService);
148+
const ctx = await requestContextService.create({ apiType: 'admin' });
149+
150+
const variantsMap = await collectionService.getProductVariantsForCollections(ctx, [], {
151+
take: 10,
152+
});
153+
154+
expect(variantsMap).toBeInstanceOf(Map);
155+
expect(variantsMap.size).toBe(0);
168156
});
169157

170158
it('returns variants grouped by collection', async () => {

0 commit comments

Comments
 (0)