mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 00:39:49 +00:00
refacto
This commit is contained in:
parent
113f2b093b
commit
9d50d97706
@ -31,10 +31,7 @@ describe('i18n - Migration - disable localization on a field', () => {
|
|||||||
|
|
||||||
test("Doesn't migrate if no attribute changed (without i18n)", async () => {
|
test("Doesn't migrate if no attribute changed (without i18n)", async () => {
|
||||||
const find = jest.fn();
|
const find = jest.fn();
|
||||||
const getLocalizedAttributes = jest
|
const getLocalizedAttributes = jest.fn(() => []);
|
||||||
.fn()
|
|
||||||
.mockReturnValueOnce([])
|
|
||||||
.mockReturnValueOnce([]);
|
|
||||||
|
|
||||||
global.strapi = {
|
global.strapi = {
|
||||||
query: () => {
|
query: () => {
|
||||||
@ -62,10 +59,7 @@ describe('i18n - Migration - disable localization on a field', () => {
|
|||||||
|
|
||||||
test("Doesn't migrate if no attribute changed (with i18n)", async () => {
|
test("Doesn't migrate if no attribute changed (with i18n)", async () => {
|
||||||
const find = jest.fn();
|
const find = jest.fn();
|
||||||
const getLocalizedAttributes = jest
|
const getLocalizedAttributes = jest.fn(() => ['name']);
|
||||||
.fn()
|
|
||||||
.mockReturnValueOnce(['name'])
|
|
||||||
.mockReturnValueOnce(['name']);
|
|
||||||
global.strapi = {
|
global.strapi = {
|
||||||
query: () => {
|
query: () => {
|
||||||
find;
|
find;
|
||||||
|
@ -48,7 +48,7 @@ const updateFromTmpTable = async ({ model, trx, attributesToMigrate }) => {
|
|||||||
|
|
||||||
const createTmpTable = async ({ ORM, attributesToMigrate, model }) => {
|
const createTmpTable = async ({ ORM, attributesToMigrate, model }) => {
|
||||||
const columnsToCopy = ['id', ...attributesToMigrate];
|
const columnsToCopy = ['id', ...attributesToMigrate];
|
||||||
await ORM.knex.schema.dropTableIfExists(TMP_TABLE_NAME);
|
await deleteTmpTable({ ORM });
|
||||||
await ORM.knex.raw(`CREATE TABLE ?? AS ??`, [
|
await ORM.knex.raw(`CREATE TABLE ?? AS ??`, [
|
||||||
TMP_TABLE_NAME,
|
TMP_TABLE_NAME,
|
||||||
ORM.knex
|
ORM.knex
|
||||||
@ -65,8 +65,9 @@ const getSortedLocales = async trx => {
|
|||||||
try {
|
try {
|
||||||
const defaultLocaleRow = await trx('core_store')
|
const defaultLocaleRow = await trx('core_store')
|
||||||
.select('value')
|
.select('value')
|
||||||
.where({ key: 'plugin_i18n_default_locale' });
|
.where({ key: 'plugin_i18n_default_locale' })
|
||||||
defaultLocale = defaultLocaleRow[0].value;
|
.first();
|
||||||
|
defaultLocale = JSON.parse(defaultLocaleRow.value);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error("Could not migrate because the default locale doesn't exist");
|
throw new Error("Could not migrate because the default locale doesn't exist");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user