This commit is contained in:
Pierre Noël 2021-03-19 12:12:51 +01:00
parent 113f2b093b
commit 9d50d97706
2 changed files with 6 additions and 11 deletions

View File

@ -31,10 +31,7 @@ describe('i18n - Migration - disable localization on a field', () => {
test("Doesn't migrate if no attribute changed (without i18n)", async () => {
const find = jest.fn();
const getLocalizedAttributes = jest
.fn()
.mockReturnValueOnce([])
.mockReturnValueOnce([]);
const getLocalizedAttributes = jest.fn(() => []);
global.strapi = {
query: () => {
@ -62,10 +59,7 @@ describe('i18n - Migration - disable localization on a field', () => {
test("Doesn't migrate if no attribute changed (with i18n)", async () => {
const find = jest.fn();
const getLocalizedAttributes = jest
.fn()
.mockReturnValueOnce(['name'])
.mockReturnValueOnce(['name']);
const getLocalizedAttributes = jest.fn(() => ['name']);
global.strapi = {
query: () => {
find;

View File

@ -48,7 +48,7 @@ const updateFromTmpTable = async ({ model, trx, attributesToMigrate }) => {
const createTmpTable = async ({ ORM, attributesToMigrate, model }) => {
const columnsToCopy = ['id', ...attributesToMigrate];
await ORM.knex.schema.dropTableIfExists(TMP_TABLE_NAME);
await deleteTmpTable({ ORM });
await ORM.knex.raw(`CREATE TABLE ?? AS ??`, [
TMP_TABLE_NAME,
ORM.knex
@ -65,8 +65,9 @@ const getSortedLocales = async trx => {
try {
const defaultLocaleRow = await trx('core_store')
.select('value')
.where({ key: 'plugin_i18n_default_locale' });
defaultLocale = defaultLocaleRow[0].value;
.where({ key: 'plugin_i18n_default_locale' })
.first();
defaultLocale = JSON.parse(defaultLocaleRow.value);
} catch (e) {
throw new Error("Could not migrate because the default locale doesn't exist");
}