-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from boazpoolman/feature/fix-import-on-bootstrap
Feature/fix import on bootstrap
- Loading branch information
Showing
9 changed files
with
1,239 additions
and
945 deletions.
There are no files selected for viewing
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
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,34 @@ | ||
const fs = require('fs'); | ||
const Strapi = require('@strapi/strapi'); | ||
|
||
let instance; | ||
|
||
async function setupStrapi() { | ||
if (!instance) { | ||
await Strapi().load(); | ||
instance = strapi; | ||
|
||
await instance.server.mount(); | ||
} | ||
return instance; | ||
} | ||
|
||
async function cleanupStrapi() { | ||
const dbSettings = strapi.config.get('database.connection'); | ||
|
||
// close server to release the db-file. | ||
await strapi.server.httpServer.close(); | ||
|
||
// close the connection to the database before deletion. | ||
await strapi.db.connection.destroy(); | ||
|
||
// delete test database after all tests have completed. | ||
if (dbSettings && dbSettings.connection && dbSettings.connection.filename) { | ||
const tmpDbFile = dbSettings.connection.filename; | ||
if (fs.existsSync(tmpDbFile)) { | ||
fs.unlinkSync(tmpDbFile); | ||
} | ||
} | ||
} | ||
|
||
module.exports = { setupStrapi, cleanupStrapi }; |
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,48 @@ | ||
const util = require('util'); | ||
const exec = util.promisify(require('child_process').exec); | ||
|
||
const { setupStrapi, cleanupStrapi } = require('./helpers'); | ||
|
||
jest.setTimeout(20000); | ||
|
||
afterEach(async () => { | ||
// Disable importOnBootstrap | ||
await exec('sed -i "s/importOnBootstrap: true/importOnBootstrap: false/g" config/plugins.js'); | ||
|
||
await cleanupStrapi(); | ||
await exec('rm -rf config/sync'); | ||
}); | ||
|
||
describe('Test the importOnBootstrap feature', () => { | ||
test('Without a database', async () => { | ||
// Do the initial export and remove the database. | ||
await exec('yarn cs export -y'); | ||
await exec('rm -rf .tmp'); | ||
|
||
// Manually change the plugins.js to enable importOnBoostrap. | ||
await exec('sed -i "s/importOnBootstrap: false/importOnBootstrap: true/g" config/plugins.js'); | ||
|
||
// Start up Strapi to initiate the importOnBootstrap function. | ||
await setupStrapi(); | ||
|
||
expect(strapi).toBeDefined(); | ||
}); | ||
|
||
test('With a database', async () => { | ||
// Delete any existing database and do an export. | ||
await exec('rm -rf .tmp'); | ||
await exec('yarn cs export -y'); | ||
|
||
// Manually change the plugins.js to enable importOnBoostrap. | ||
await exec('sed -i "s/importOnBootstrap: false/importOnBootstrap: true/g" config/plugins.js'); | ||
|
||
// Remove a config file to make sure the importOnBoostrap | ||
// function actually attempts to import. | ||
await exec('rm -rf config/sync/admin-role.strapi-editor.json'); | ||
|
||
// Start up Strapi to initiate the importOnBootstrap function. | ||
await setupStrapi(); | ||
|
||
expect(strapi).toBeDefined(); | ||
}); | ||
}); |
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,8 @@ | ||
module.exports = { | ||
'config-sync': { | ||
enabled: true, | ||
config: { | ||
importOnBootstrap: false, | ||
}, | ||
}, | ||
}; |
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
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,32 @@ | ||
const queryFallBack = { | ||
create: async (queryString, options) => { | ||
try { | ||
const newEntity = await strapi.entityService.create(queryString, options); | ||
|
||
return newEntity; | ||
} catch (e) { | ||
return strapi.query(queryString).create(options); | ||
} | ||
}, | ||
update: async (queryString, options) => { | ||
try { | ||
const entity = await strapi.query(queryString).findOne(options.where); | ||
const updatedEntity = await strapi.entityService.update(queryString, entity.id); | ||
|
||
return updatedEntity; | ||
} catch (e) { | ||
return strapi.query(queryString).update(options); | ||
} | ||
}, | ||
delete: async (queryString, id) => { | ||
try { | ||
await strapi.entityService.delete(queryString, id); | ||
} catch (e) { | ||
await strapi.query(queryString).delete({ | ||
where: { id }, | ||
}); | ||
} | ||
}, | ||
}; | ||
|
||
module.exports = queryFallBack; |
Oops, something went wrong.