|
1 | 1 | import { faker } from '@faker-js/faker'; |
2 | 2 | import { Core } from '@strapi/strapi'; |
3 | | -import { asProxy } from '../utils'; |
4 | 3 | import { getNavigationRepository } from '../../src/repositories'; |
5 | 4 | import { getPluginModels } from '../../src/utils'; |
| 5 | +import { asProxy } from '../utils'; |
6 | 6 |
|
7 | 7 | jest.mock('../../src/utils', () => ({ |
8 | 8 | ...jest.requireActual('../../src/utils'), |
@@ -159,6 +159,60 @@ describe('Navigation', () => { |
159 | 159 | expect(mockCreate).not.toHaveBeenCalled(); |
160 | 160 | expect(result).toBeDefined(); |
161 | 161 | }); |
| 162 | + it('should handle parent.related as array (bug reproduction)', async () => { |
| 163 | + // Given - Strapi returns parent.related as an array (morphToMany behavior) |
| 164 | + const mockData = [ |
| 165 | + getMockNavigationData({ |
| 166 | + items: [ |
| 167 | + { |
| 168 | + id: 1, |
| 169 | + documentId: 'item-1', |
| 170 | + title: 'Parent Item', |
| 171 | + type: 'INTERNAL', |
| 172 | + path: '/parent', |
| 173 | + uiRouterKey: 'parent', |
| 174 | + menuAttached: false, |
| 175 | + order: 0, |
| 176 | + collapsed: false, |
| 177 | + related: [{ documentId: 'rel-1', __type: 'api::author.author' }], |
| 178 | + parent: null, |
| 179 | + }, |
| 180 | + { |
| 181 | + id: 2, |
| 182 | + documentId: 'item-2', |
| 183 | + title: 'Child Item', |
| 184 | + type: 'INTERNAL', |
| 185 | + path: '/child', |
| 186 | + uiRouterKey: 'child', |
| 187 | + menuAttached: false, |
| 188 | + order: 0, |
| 189 | + collapsed: false, |
| 190 | + related: [{ documentId: 'rel-2', __type: 'api::author.author' }], |
| 191 | + parent: { |
| 192 | + id: 1, |
| 193 | + documentId: 'item-1', |
| 194 | + title: 'Parent Item', |
| 195 | + type: 'INTERNAL', |
| 196 | + path: '/parent', |
| 197 | + uiRouterKey: 'parent', |
| 198 | + menuAttached: false, |
| 199 | + order: 0, |
| 200 | + collapsed: false, |
| 201 | + // related as an array |
| 202 | + related: [{ documentId: 'rel-1', __type: 'api::author.author' }], |
| 203 | + }, |
| 204 | + }, |
| 205 | + ], |
| 206 | + }), |
| 207 | + ]; |
| 208 | + mockFindMany.mockResolvedValue(mockData); |
| 209 | + |
| 210 | + const repository = getNavigationRepository({ strapi: mockStrapi }); |
| 211 | + |
| 212 | + // When & Then - This should NOT throw, but currently does with: |
| 213 | + // "Expected object, received array" at items[1].parent.related |
| 214 | + await expect(repository.find({ filters: {}, locale: 'en' })).resolves.toBeDefined(); |
| 215 | + }); |
162 | 216 | }); |
163 | 217 | describe('remove()', () => { |
164 | 218 | it('should delete navigation with documentId and locale', async () => { |
|
0 commit comments