-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
87 changed files
with
3,837 additions
and
3,035 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
app/api/migrations/migrations/152-update_translations/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const newKeys = [{ key: 'Updated' }, { key: 'No Group' }, { key: 'Using URLs' }]; | ||
|
||
const deletedKeys = []; | ||
|
||
export default { | ||
delta: 152, | ||
|
||
reindex: false, | ||
|
||
name: 'update_translations', | ||
|
||
description: 'Updates some translations for new Menu UI in settings', | ||
|
||
async up(db) { | ||
const settings = await db.collection('settings').findOne(); | ||
const languages = settings.languages | ||
.map(l => l.key) | ||
.filter((value, index, array) => array.indexOf(value) === index); | ||
|
||
await db.collection('translationsV2').deleteMany({ | ||
key: { $in: deletedKeys.concat(newKeys).map(k => k.key) }, | ||
'context.id': 'System', | ||
}); | ||
|
||
const insertMany = languages.map(l => | ||
db.collection('translationsV2').insertMany( | ||
newKeys.map(k => ({ | ||
key: k.key, | ||
value: k.key, | ||
language: l, | ||
context: { id: 'System', type: 'Uwazi UI', label: 'User Interface' }, | ||
})) | ||
) | ||
); | ||
await Promise.all(insertMany); | ||
|
||
process.stdout.write(`${this.name}...\r\n`); | ||
}, | ||
}; | ||
|
||
export { newKeys, deletedKeys }; |
50 changes: 50 additions & 0 deletions
50
app/api/migrations/migrations/152-update_translations/specs/152-update_translations.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import testingDB from 'api/utils/testing_db'; | ||
import migration, { newKeys, deletedKeys } from '../index.js'; | ||
import fixtures from './fixtures.js'; | ||
|
||
describe('migration update translations of settings new Users/Groups UI', () => { | ||
beforeAll(async () => { | ||
jest.spyOn(process.stdout, 'write').mockImplementation(() => {}); | ||
await testingDB.setupFixturesAndContext(fixtures); | ||
await migration.up(testingDB.mongodb); | ||
}); | ||
|
||
afterAll(async () => { | ||
await testingDB.disconnect(); | ||
}); | ||
|
||
it('should have a delta number', () => { | ||
expect(migration.delta).toBe(152); | ||
}); | ||
|
||
it('should delete old translations', async () => { | ||
const translations = await testingDB.mongodb | ||
.collection('translationsV2') | ||
.find({ key: { $in: deletedKeys.map(k => k.key) } }) | ||
.toArray(); | ||
|
||
expect(translations).toEqual([]); | ||
}); | ||
|
||
it('should NOT delete other translations', async () => { | ||
const translations = await testingDB.mongodb | ||
.collection('translationsV2') | ||
.find({ key: 'Im cool' }) | ||
.toArray(); | ||
|
||
expect(translations.length).toBe(2); | ||
}); | ||
|
||
it('should add new translations per language', async () => { | ||
const translations = await testingDB.mongodb | ||
.collection('translationsV2') | ||
.find({ key: { $in: newKeys.map(k => k.key) } }) | ||
.toArray(); | ||
|
||
expect(translations.length).toBe(6); | ||
}); | ||
|
||
it('should be idempotent (do not throw an error on multiple runs)', async () => { | ||
await expect(migration.up(testingDB.mongodb)).resolves.toBe(undefined); | ||
}); | ||
}); |
51 changes: 51 additions & 0 deletions
51
app/api/migrations/migrations/152-update_translations/specs/fixtures.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import db from 'api/utils/testing_db'; | ||
|
||
const fixturesDB = { | ||
settings: [{ _id: db.id(), languages: [{ key: 'en' }, { key: 'es' }] }], | ||
translationsV2: [ | ||
{ | ||
_id: db.id(), | ||
language: 'en', | ||
context: { id: 'System', label: 'User Interface', type: 'Uwazi UI' }, | ||
key: 'Match / Label', | ||
value: 'Match / Label', | ||
}, | ||
{ | ||
_id: db.id(), | ||
language: 'en', | ||
context: { id: 'System', label: 'User Interface', type: 'Uwazi UI' }, | ||
key: 'Reviewing', | ||
value: 'Reviewing', | ||
}, | ||
{ | ||
_id: db.id(), | ||
language: 'es', | ||
context: { id: 'System', label: 'User Interface', type: 'Uwazi UI' }, | ||
key: 'Match / Label', | ||
value: 'Match / Label', | ||
}, | ||
{ | ||
_id: db.id(), | ||
language: 'es', | ||
context: { id: 'System', label: 'User Interface', type: 'Uwazi UI' }, | ||
key: 'Reviewing', | ||
value: 'Reviewing', | ||
}, | ||
{ | ||
_id: db.id(), | ||
language: 'en', | ||
context: { id: 'System', label: 'User Interface', type: 'Uwazi UI' }, | ||
key: 'Im cool', | ||
value: 'Im cool', | ||
}, | ||
{ | ||
_id: db.id(), | ||
language: 'es', | ||
context: { id: 'System', label: 'User Interface', type: 'Uwazi UI' }, | ||
key: 'Im cool', | ||
value: 'Im cool', | ||
}, | ||
], | ||
}; | ||
|
||
export default fixturesDB; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.