|
1 | | -import { DefaultJobQueuePlugin, LanguageCode } from '@vendure/core'; |
| 1 | +import { CollectionService, DefaultJobQueuePlugin, LanguageCode, RequestContextService } from '@vendure/core'; |
2 | 2 | import { createTestEnvironment } from '@vendure/testing'; |
3 | 3 | import { gql } from 'graphql-tag'; |
4 | 4 | import path from 'path'; |
@@ -85,7 +85,9 @@ describe('Collection Batch Loading Correctness', () => { |
85 | 85 | `; |
86 | 86 | const collectionsResult: any = await adminClient.query(GET_COLLECTIONS); |
87 | 87 | 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; |
89 | 91 |
|
90 | 92 | // Create Electronics collection |
91 | 93 | const CREATE_COLLECTION = gql` |
@@ -141,30 +143,16 @@ describe('Collection Batch Loading Correctness', () => { |
141 | 143 | it('returns empty map for empty input', async () => { |
142 | 144 | // This test verifies that the batch loading service method handles |
143 | 145 | // 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); |
168 | 156 | }); |
169 | 157 |
|
170 | 158 | it('returns variants grouped by collection', async () => { |
|
0 commit comments