2021-02-25 17:40:14 +01:00
|
|
|
'use strict';
|
|
|
|
|
2021-03-11 10:41:35 +01:00
|
|
|
const { after } = require('../field');
|
2021-02-25 17:40:14 +01:00
|
|
|
|
|
|
|
describe('i18n - Migration - disable localization on a field', () => {
|
2021-03-11 10:41:35 +01:00
|
|
|
describe('after', () => {
|
2021-02-25 17:40:14 +01:00
|
|
|
describe('Should not migrate', () => {
|
|
|
|
test("Doesn't migrate if model isn't localized", async () => {
|
|
|
|
const find = jest.fn();
|
|
|
|
global.strapi = {
|
|
|
|
query: () => {
|
|
|
|
find;
|
|
|
|
},
|
2021-03-11 10:41:35 +01:00
|
|
|
plugins: {
|
|
|
|
i18n: {
|
|
|
|
services: {
|
|
|
|
'content-types': {
|
2021-04-07 11:43:46 +02:00
|
|
|
isLocalizedContentType: () => false,
|
2021-03-11 10:41:35 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-02-25 17:40:14 +01:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-03-11 10:41:35 +01:00
|
|
|
const model = {};
|
|
|
|
const previousDefinition = {};
|
2021-02-25 17:40:14 +01:00
|
|
|
|
2021-03-11 10:41:35 +01:00
|
|
|
await after({ model, definition: model, previousDefinition });
|
2021-02-25 17:40:14 +01:00
|
|
|
expect(find).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Doesn't migrate if no attribute changed (without i18n)", async () => {
|
|
|
|
const find = jest.fn();
|
2021-03-19 12:12:51 +01:00
|
|
|
const getLocalizedAttributes = jest.fn(() => []);
|
2021-03-11 10:41:35 +01:00
|
|
|
|
2021-02-25 17:40:14 +01:00
|
|
|
global.strapi = {
|
|
|
|
query: () => {
|
|
|
|
find;
|
|
|
|
},
|
2021-03-11 10:41:35 +01:00
|
|
|
plugins: {
|
|
|
|
i18n: {
|
|
|
|
services: {
|
|
|
|
'content-types': {
|
2021-04-07 11:43:46 +02:00
|
|
|
isLocalizedContentType: () => true,
|
2021-03-18 18:53:29 +01:00
|
|
|
getLocalizedAttributes,
|
2021-03-11 10:41:35 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-02-25 17:40:14 +01:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-03-11 10:41:35 +01:00
|
|
|
const model = { attributes: { name: {} } };
|
|
|
|
const previousDefinition = { attributes: { name: {} } };
|
2021-02-25 17:40:14 +01:00
|
|
|
|
2021-03-11 10:41:35 +01:00
|
|
|
await after({ model, definition: model, previousDefinition });
|
2021-03-18 18:53:29 +01:00
|
|
|
expect(getLocalizedAttributes).toHaveBeenCalledTimes(2);
|
2021-02-25 17:40:14 +01:00
|
|
|
expect(find).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Doesn't migrate if no attribute changed (with i18n)", async () => {
|
|
|
|
const find = jest.fn();
|
2021-03-19 12:12:51 +01:00
|
|
|
const getLocalizedAttributes = jest.fn(() => ['name']);
|
2021-02-25 17:40:14 +01:00
|
|
|
global.strapi = {
|
|
|
|
query: () => {
|
|
|
|
find;
|
|
|
|
},
|
2021-03-11 10:41:35 +01:00
|
|
|
plugins: {
|
|
|
|
i18n: {
|
|
|
|
services: {
|
|
|
|
'content-types': {
|
2021-04-07 11:43:46 +02:00
|
|
|
isLocalizedContentType: () => true,
|
2021-03-18 18:53:29 +01:00
|
|
|
getLocalizedAttributes,
|
2021-03-11 10:41:35 +01:00
|
|
|
},
|
|
|
|
},
|
2021-02-25 17:40:14 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-03-11 10:41:35 +01:00
|
|
|
const model = { attributes: { name: {} } };
|
|
|
|
const previousDefinition = { attributes: { name: {} } };
|
2021-02-25 17:40:14 +01:00
|
|
|
|
2021-03-11 10:41:35 +01:00
|
|
|
await after({ model, definition: model, previousDefinition });
|
2021-03-18 18:53:29 +01:00
|
|
|
expect(getLocalizedAttributes).toHaveBeenCalledTimes(2);
|
2021-02-25 17:40:14 +01:00
|
|
|
expect(find).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2021-03-11 10:41:35 +01:00
|
|
|
test("Doesn't migrate if field become localized", async () => {
|
2021-02-25 17:40:14 +01:00
|
|
|
const find = jest.fn();
|
2021-03-18 18:53:29 +01:00
|
|
|
const getLocalizedAttributes = jest
|
2021-03-11 10:41:35 +01:00
|
|
|
.fn()
|
|
|
|
.mockReturnValueOnce(['name'])
|
|
|
|
.mockReturnValueOnce([]);
|
|
|
|
|
2021-02-25 17:40:14 +01:00
|
|
|
global.strapi = {
|
|
|
|
query: () => {
|
|
|
|
find;
|
|
|
|
},
|
2021-03-11 10:41:35 +01:00
|
|
|
plugins: {
|
|
|
|
i18n: {
|
|
|
|
services: {
|
|
|
|
'content-types': {
|
2021-04-07 11:43:46 +02:00
|
|
|
isLocalizedContentType: () => true,
|
2021-03-18 18:53:29 +01:00
|
|
|
getLocalizedAttributes,
|
2021-03-11 10:41:35 +01:00
|
|
|
},
|
|
|
|
},
|
2021-02-25 17:40:14 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-03-11 10:41:35 +01:00
|
|
|
const model = { attributes: { name: {} } };
|
|
|
|
const previousDefinition = { attributes: { name: {} } };
|
2021-02-25 17:40:14 +01:00
|
|
|
|
2021-03-11 10:41:35 +01:00
|
|
|
await after({ model, definition: model, previousDefinition });
|
2021-03-18 18:53:29 +01:00
|
|
|
expect(getLocalizedAttributes).toHaveBeenCalledTimes(2);
|
2021-02-25 17:40:14 +01:00
|
|
|
expect(find).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2021-03-11 10:41:35 +01:00
|
|
|
test("Doesn't migrate if field is deleted", async () => {
|
2021-02-25 17:40:14 +01:00
|
|
|
const find = jest.fn();
|
2021-03-18 18:53:29 +01:00
|
|
|
const getLocalizedAttributes = jest
|
2021-03-11 10:41:35 +01:00
|
|
|
.fn()
|
|
|
|
.mockReturnValueOnce([])
|
|
|
|
.mockReturnValueOnce(['name']);
|
|
|
|
|
2021-02-25 17:40:14 +01:00
|
|
|
global.strapi = {
|
|
|
|
query: () => {
|
|
|
|
find;
|
|
|
|
},
|
2021-03-11 10:41:35 +01:00
|
|
|
plugins: {
|
|
|
|
i18n: {
|
|
|
|
services: {
|
|
|
|
'content-types': {
|
2021-04-07 11:43:46 +02:00
|
|
|
isLocalizedContentType: () => true,
|
2021-03-18 18:53:29 +01:00
|
|
|
getLocalizedAttributes,
|
2021-03-11 10:41:35 +01:00
|
|
|
},
|
|
|
|
},
|
2021-02-25 17:40:14 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-03-11 10:41:35 +01:00
|
|
|
const model = { attributes: {} };
|
|
|
|
const previousDefinition = { attributes: { name: {} } };
|
2021-02-25 17:40:14 +01:00
|
|
|
|
2021-03-11 10:41:35 +01:00
|
|
|
await after({ model, definition: model, previousDefinition });
|
2021-03-18 18:53:29 +01:00
|
|
|
expect(getLocalizedAttributes).toHaveBeenCalledTimes(2);
|
2021-02-25 17:40:14 +01:00
|
|
|
expect(find).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|