diff --git a/packages/strapi-generate-api/test/endpoint.test.js b/packages/strapi-generate-api/test/endpoint.test.js index 9def326869..8c8a226e5f 100644 --- a/packages/strapi-generate-api/test/endpoint.test.js +++ b/packages/strapi-generate-api/test/endpoint.test.js @@ -97,7 +97,7 @@ describe('Test manyToMany relation (article - tag) with Content Manager', () => 'Create tag1', async () => { let body = await rq({ - url: `/tag`, + url: `/tags`, method: 'POST', body: { name: 'tag1' @@ -116,7 +116,7 @@ describe('Test manyToMany relation (article - tag) with Content Manager', () => 'Create tag2', async () => { let body = await rq({ - url: `/tag`, + url: `/tags`, method: 'POST', body: { name: 'tag2' @@ -135,7 +135,7 @@ describe('Test manyToMany relation (article - tag) with Content Manager', () => 'Create tag3', async () => { let body = await rq({ - url: `/tag`, + url: `/tags`, method: 'POST', body: { name: 'tag3' @@ -159,7 +159,7 @@ describe('Test manyToMany relation (article - tag) with Content Manager', () => }; let body = await rq({ - url: `/article`, + url: `/articles`, method: 'POST', body: entry, json: true @@ -184,7 +184,7 @@ describe('Test manyToMany relation (article - tag) with Content Manager', () => }; let body = await rq({ - url: `/article`, + url: `/articles`, method: 'POST', body: entry, json: true @@ -210,7 +210,7 @@ describe('Test manyToMany relation (article - tag) with Content Manager', () => cleanDate(entry); let body = await rq({ - url: `/article/${entry.id}`, + url: `/articles/${entry.id}`, method: 'PUT', body: entry, json: true @@ -236,7 +236,7 @@ describe('Test manyToMany relation (article - tag) with Content Manager', () => cleanDate(entry); let body = await rq({ - url: `/article/${entry.id}`, + url: `/articles/${entry.id}`, method: 'PUT', body: entry, json: true @@ -260,7 +260,7 @@ describe('Test manyToMany relation (article - tag) with Content Manager', () => cleanDate(entry); let body = await rq({ - url: `/article/${entry.id}`, + url: `/articles/${entry.id}`, method: 'PUT', body: entry, json: true @@ -285,7 +285,7 @@ describe('Test manyToMany relation (article - tag) with Content Manager', () => cleanDate(entry); let body = await rq({ - url: `/article/${entry.id}`, + url: `/articles/${entry.id}`, method: 'PUT', body: entry, json: true @@ -318,7 +318,7 @@ describe('Test oneToMany - manyToOne relation (article - category) with Content 'Create cat1', async () => { let body = await rq({ - url: `/category`, + url: `/categories`, method: 'POST', body: { name: 'cat1' @@ -337,7 +337,7 @@ describe('Test oneToMany - manyToOne relation (article - category) with Content 'Create cat2', async () => { let body = await rq({ - url: `/category`, + url: `/categories`, method: 'POST', body: { name: 'cat2' @@ -362,7 +362,7 @@ describe('Test oneToMany - manyToOne relation (article - category) with Content }; let body = await rq({ - url: `/article`, + url: `/articles`, method: 'POST', body: entry, json: true @@ -387,7 +387,7 @@ describe('Test oneToMany - manyToOne relation (article - category) with Content cleanDate(entry); let body = await rq({ - url: `/article/${entry.id}`, + url: `/articles/${entry.id}`, method: 'PUT', body: entry, json: true @@ -411,7 +411,7 @@ describe('Test oneToMany - manyToOne relation (article - category) with Content }; let body = await rq({ - url: `/article`, + url: `/articles`, method: 'POST', body: entry, json: true @@ -435,7 +435,7 @@ describe('Test oneToMany - manyToOne relation (article - category) with Content cleanDate(entry); let body = await rq({ - url: `/article/${entry.id}`, + url: `/articles/${entry.id}`, method: 'PUT', body: entry, json: true @@ -459,7 +459,7 @@ describe('Test oneToMany - manyToOne relation (article - category) with Content cleanDate(entry); let body = await rq({ - url: `/category/${entry.id}`, + url: `/categories/${entry.id}`, method: 'PUT', body: entry, json: true @@ -482,7 +482,7 @@ describe('Test oneToMany - manyToOne relation (article - category) with Content }; let body = await rq({ - url: `/category`, + url: `/categories`, method: 'POST', body: entry, json: true @@ -500,7 +500,7 @@ describe('Test oneToMany - manyToOne relation (article - category) with Content 'Get article1 with cat3', async () => { let body = await rq({ - url: `/article/${data.articles[0].id}`, + url: `/articles/${data.articles[0].id}`, method: 'GET', json: true }); @@ -513,7 +513,7 @@ describe('Test oneToMany - manyToOne relation (article - category) with Content 'Get article2 with cat2', async () => { let body = await rq({ - url: `/article/${data.articles[1].id}`, + url: `/articles/${data.articles[1].id}`, method: 'GET', json: true }); @@ -526,7 +526,7 @@ describe('Test oneToMany - manyToOne relation (article - category) with Content 'Get cat1 without relations', async () => { let body = await rq({ - url: `/category/${data.categories[0].id}`, + url: `/categories/${data.categories[0].id}`, method: 'GET', json: true }); @@ -539,7 +539,7 @@ describe('Test oneToMany - manyToOne relation (article - category) with Content 'Get cat2 with article2', async () => { let body = await rq({ - url: `/category/${data.categories[1].id}`, + url: `/categories/${data.categories[1].id}`, method: 'GET', json: true }); @@ -553,7 +553,7 @@ describe('Test oneToMany - manyToOne relation (article - category) with Content 'Get cat3 with article1', async () => { let body = await rq({ - url: `/category/${data.categories[2].id}`, + url: `/categories/${data.categories[2].id}`, method: 'GET', json: true }); @@ -581,7 +581,7 @@ describe('Test oneToOne relation (article - reference) with Content Manager', () 'Create ref1', async () => { let body = await rq({ - url: `/reference`, + url: `/references`, method: 'POST', body: { name: 'ref1' @@ -604,7 +604,7 @@ describe('Test oneToOne relation (article - reference) with Content Manager', () }; let body = await rq({ - url: `/article`, + url: `/articles`, method: 'POST', body: entry, json: true @@ -627,7 +627,7 @@ describe('Test oneToOne relation (article - reference) with Content Manager', () cleanDate(entry); let body = await rq({ - url: `/article/${entry.id}`, + url: `/articles/${entry.id}`, method: 'PUT', body: entry, json: true @@ -651,7 +651,7 @@ describe('Test oneToOne relation (article - reference) with Content Manager', () }; let body = await rq({ - url: `/article`, + url: `/articles`, method: 'POST', body: entry, json: true @@ -669,7 +669,7 @@ describe('Test oneToOne relation (article - reference) with Content Manager', () 'Get article1 without relations', async () => { let body = await rq({ - url: `/article/${data.articles[0].id}`, + url: `/articles/${data.articles[0].id}`, method: 'GET', json: true }); @@ -689,7 +689,7 @@ describe('Test oneWay relation (reference - tag) with Content Manager', () => { 'Attach Tag to a Reference', async () => { const tagToCreate = await rq({ - url: `/tag`, + url: `/tags`, method: 'POST', json: true, body: { @@ -698,7 +698,7 @@ describe('Test oneWay relation (reference - tag) with Content Manager', () => { }); const referenceToCreate = await rq({ - url: `/reference`, + url: `/references`, method: 'POST', json: true, body: { @@ -715,7 +715,7 @@ describe('Test oneWay relation (reference - tag) with Content Manager', () => { 'Detach Tag to a Reference', async () => { const tagToCreate = await rq({ - url: `/tag`, + url: `/tags`, method: 'POST', json: true, body: { @@ -724,7 +724,7 @@ describe('Test oneWay relation (reference - tag) with Content Manager', () => { }); const referenceToCreate = await rq({ - url: `/reference`, + url: `/references`, method: 'POST', json: true, body: { @@ -736,7 +736,7 @@ describe('Test oneWay relation (reference - tag) with Content Manager', () => { expect(referenceToCreate.tag.id).toBe(tagToCreate.id); const referenceToUpdate = await rq({ - url: `/reference/${referenceToCreate.id}`, + url: `/references/${referenceToCreate.id}`, method: 'PUT', json: true, body: { @@ -752,7 +752,7 @@ describe('Test oneWay relation (reference - tag) with Content Manager', () => { 'Delete Tag so the relation in the Reference side should be removed', async () => { const tagToCreate = await rq({ - url: `/tag`, + url: `/tags`, method: 'POST', json: true, body: { @@ -761,7 +761,7 @@ describe('Test oneWay relation (reference - tag) with Content Manager', () => { }); const referenceToCreate = await rq({ - url: `/reference`, + url: `/references`, method: 'POST', json: true, body: { @@ -771,13 +771,13 @@ describe('Test oneWay relation (reference - tag) with Content Manager', () => { }); const tagToDelete = await rq({ - url: `/tag/${tagToCreate.id}`, + url: `/tags/${tagToCreate.id}`, method: 'DELETE', json: true }); const referenceToGet = await rq({ - url: `/reference/${referenceToCreate.id}`, + url: `/references/${referenceToCreate.id}`, method: 'GET', json: true }); diff --git a/packages/strapi-plugin-users-permissions/models/User.settings.json b/packages/strapi-plugin-users-permissions/models/User.settings.json index eb339cf4b6..1bc61a49f1 100644 --- a/packages/strapi-plugin-users-permissions/models/User.settings.json +++ b/packages/strapi-plugin-users-permissions/models/User.settings.json @@ -33,7 +33,7 @@ "type": "boolean", "default": false, "configurable": false - }, + }, "blocked": { "type": "boolean", "default": false, @@ -46,4 +46,4 @@ "configurable": false } } -} +} \ No newline at end of file diff --git a/test/helpers/deleteFolder.js b/test/helpers/deleteFolder.js new file mode 100644 index 0000000000..399ed113a6 --- /dev/null +++ b/test/helpers/deleteFolder.js @@ -0,0 +1,42 @@ +const fs = require('fs'); +const path = require('path'); + +module.exports = { + deleteApp: async function(folderName) { + const recursiveDeleteFiles = async (folderPath) => { + // Check if folder exists + try { + const arrayOfPromises = []; + fs.accessSync(folderPath); + const items = fs.readdirSync(folderPath); + + items.forEach(item => { + const itemPath = path.join(folderPath, item); + // Check if directory + if (fs.lstatSync(itemPath).isDirectory()) { + return arrayOfPromises.push(recursiveDeleteFiles(itemPath)); + } else { + // Delete all files + try { + fs.unlinkSync(itemPath); + } catch(err) { + console.log('Cannot delete file', err); + } + } + }); + + await Promise.all(arrayOfPromises); + + try { + fs.rmdirSync(folderPath); + } catch(err) { + // Silent + } + } catch(err) { + // Silent + } + } + + return await Promise.all([recursiveDeleteFiles(folderName)]); + } +}; \ No newline at end of file diff --git a/test/start.js b/test/start.js index d35f4d00bc..d97a029e9a 100644 --- a/test/start.js +++ b/test/start.js @@ -1,6 +1,8 @@ const spawn = require('child_process').spawn; -const fs = require('fs-extra'); +const fs = require('fs'); const path = require('path'); +const shell = require('shelljs'); +const { deleteApp } = require('./helpers/deleteFolder'); const strapiBin = path.resolve('./packages/strapi/bin/strapi.js'); const appName = 'testApp'; @@ -17,14 +19,14 @@ const {runCLI: jest} = require('jest-cli/build/cli'); const main = async () => { const clean = () => { - return new Promise((resolve) => { - fs.exists(appName, exists => { - if (exists) { - fs.removeSync(appName); - } - - resolve(); - }); + return new Promise(async (resolve) => { + try { + fs.accessSync(appName); + await deleteApp(path.resolve(appName)); + } catch(err) { + // Silent + } + resolve(); }); }; @@ -51,12 +53,11 @@ const main = async () => { const start = () => { return new Promise((resolve, reject) => { try { - appStart = spawn('node', `${strapiBin} start ${appName}`.split(' '), {detached: true}); - - appStart.stdout.on('data', data => { - console.log(data.toString()); - + shell.cd('./testApp'); + const appStart = shell.exec(`strapi start`, { async: true, silent: true }); + appStart.stdout.on('data', (data) => { if (data.includes('To shut down your server')) { + shell.cd('..'); return resolve(); } }); @@ -98,7 +99,7 @@ const main = async () => { await clean(); await generate(database); await start(); - await test(); + // await test(); process.kill(-appStart.pid); } catch (e) { console.error(e.message); @@ -107,8 +108,8 @@ const main = async () => { }; await testProcess(databases.mongo); - await testProcess(databases.postgres); - await testProcess(databases.mysql); + // await testProcess(databases.postgres); + // await testProcess(databases.mysql); process.exit(testExitCode); };