Skip to content

Commit c1b82f3

Browse files
Merge pull request #655 from VirtusLab-Open-Source/fix/wrapper-element-related
fix: wrapper element related
2 parents 3442c52 + bb78140 commit c1b82f3

5 files changed

Lines changed: 24 additions & 3 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "strapi-plugin-navigation",
3-
"version": "3.3.4",
3+
"version": "3.3.5",
44
"description": "Strapi - Navigation plugin",
55
"strapi": {
66
"name": "navigation",

server/src/content-types/navigation-item/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export default {
7575
related: {
7676
type: 'relation',
7777
relation: 'morphToMany',
78-
required: true,
78+
required: false,
7979
configurable: false,
8080
},
8181
parent: {

server/src/utils/migration.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ export const removeNavigationsWithoutDefaultLocale = async (context: { strapi: C
77
limit: Number.MAX_SAFE_INTEGER,
88
});
99
const defaultLocale = await context.strapi.plugin('i18n').service('locales').getDefaultLocale();
10+
if (!defaultLocale) {
11+
return;
12+
}
1013
await Promise.all(
1114
allNavigations.map(async (navigation) => {
1215
const root = allNavigations.find(

server/tests/content-types/navigation-item.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe('Navigation', () => {
6666
"related": {
6767
"configurable": false,
6868
"relation": "morphToMany",
69-
"required": true,
69+
"required": false,
7070
"type": "relation",
7171
},
7272
"title": {

server/tests/utils/migration.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,24 @@ describe('Navigation', () => {
272272
);
273273
expect(mockRepository.remove).not.toHaveBeenCalled();
274274
});
275+
276+
it('should return early without removing when defaultLocale is not defined', async () => {
277+
// Given
278+
const otherLocale = 'fr';
279+
const documentId = faker.string.uuid();
280+
const navigations = [getMockNavigation({ documentId, locale: otherLocale })];
281+
282+
mockI18nService.getDefaultLocale.mockResolvedValue(null);
283+
mockRepository.find.mockResolvedValue(navigations);
284+
285+
// When
286+
await removeNavigationsWithoutDefaultLocale({ strapi: mockStrapi });
287+
288+
// Then
289+
expect(mockRepository.find).toHaveBeenCalled();
290+
expect(mockI18nService.getDefaultLocale).toHaveBeenCalled();
291+
expect(mockRepository.remove).not.toHaveBeenCalled();
292+
});
275293
});
276294
});
277295
});

0 commit comments

Comments
 (0)