mirror of
https://github.com/strapi/strapi.git
synced 2025-11-19 03:29:47 +00:00
Split init route to init & information endpoints (#8160)
* Split init to init & information endpoints Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu> * Add unit tests / Rename controller Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu> * Remove unnecessary comment Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu>
This commit is contained in:
parent
8a407ccee8
commit
46314a4054
@ -3,7 +3,7 @@
|
|||||||
{
|
{
|
||||||
"method": "GET",
|
"method": "GET",
|
||||||
"path": "/plugins",
|
"path": "/plugins",
|
||||||
"handler": "Admin.plugins",
|
"handler": "admin.plugins",
|
||||||
"config": {
|
"config": {
|
||||||
"policies": [
|
"policies": [
|
||||||
"admin::isAuthenticatedAdmin",
|
"admin::isAuthenticatedAdmin",
|
||||||
@ -14,12 +14,22 @@
|
|||||||
{
|
{
|
||||||
"method": "GET",
|
"method": "GET",
|
||||||
"path": "/init",
|
"path": "/init",
|
||||||
"handler": "Admin.init"
|
"handler": "admin.init"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"method": "GET",
|
||||||
|
"path": "/information",
|
||||||
|
"handler": "admin.information",
|
||||||
|
"config": {
|
||||||
|
"policies": [
|
||||||
|
"admin::isAuthenticatedAdmin"
|
||||||
|
]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"method": "POST",
|
"method": "POST",
|
||||||
"path": "/plugins/install",
|
"path": "/plugins/install",
|
||||||
"handler": "Admin.installPlugin",
|
"handler": "admin.installPlugin",
|
||||||
"config": {
|
"config": {
|
||||||
"policies": [
|
"policies": [
|
||||||
"admin::isAuthenticatedAdmin",
|
"admin::isAuthenticatedAdmin",
|
||||||
@ -30,7 +40,7 @@
|
|||||||
{
|
{
|
||||||
"method": "DELETE",
|
"method": "DELETE",
|
||||||
"path": "/plugins/uninstall/:plugin",
|
"path": "/plugins/uninstall/:plugin",
|
||||||
"handler": "Admin.uninstallPlugin",
|
"handler": "admin.uninstallPlugin",
|
||||||
"config": {
|
"config": {
|
||||||
"policies": [
|
"policies": [
|
||||||
"admin::isAuthenticatedAdmin",
|
"admin::isAuthenticatedAdmin",
|
||||||
|
|||||||
68
packages/strapi-admin/controllers/__tests__/admin.test.js
Normal file
68
packages/strapi-admin/controllers/__tests__/admin.test.js
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const adminController = require('../admin');
|
||||||
|
|
||||||
|
describe('Admin Controller', () => {
|
||||||
|
describe('init', () => {
|
||||||
|
beforeAll(() => {
|
||||||
|
global.strapi = {
|
||||||
|
config: {
|
||||||
|
get: jest.fn(() => 'foo'),
|
||||||
|
},
|
||||||
|
admin: {
|
||||||
|
services: {
|
||||||
|
user: {
|
||||||
|
exists: jest.fn(() => true),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Returns the uuid and if the app has admins', async () => {
|
||||||
|
const result = await adminController.init();
|
||||||
|
|
||||||
|
expect(global.strapi.config.get).toHaveBeenCalledWith('uuid', false);
|
||||||
|
expect(global.strapi.admin.services.user.exists).toHaveBeenCalled();
|
||||||
|
expect(result.data).toBeDefined();
|
||||||
|
expect(result.data).toStrictEqual({
|
||||||
|
uuid: 'foo',
|
||||||
|
hasAdmin: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('information', () => {
|
||||||
|
beforeAll(() => {
|
||||||
|
global.strapi = {
|
||||||
|
app: {
|
||||||
|
env: 'development',
|
||||||
|
},
|
||||||
|
config: {
|
||||||
|
get: jest.fn(
|
||||||
|
(key, value) =>
|
||||||
|
({
|
||||||
|
autoReload: undefined,
|
||||||
|
'info.strapi': '1.0.0',
|
||||||
|
}[key] || value)
|
||||||
|
),
|
||||||
|
},
|
||||||
|
EE: true,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Returns application information', async () => {
|
||||||
|
const result = await adminController.information();
|
||||||
|
|
||||||
|
expect(global.strapi.config.get).toHaveBeenCalledTimes(2);
|
||||||
|
expect(result.data).toBeDefined();
|
||||||
|
expect(result.data).toStrictEqual({
|
||||||
|
currentEnvironment: 'development',
|
||||||
|
autoReload: false,
|
||||||
|
strapiVersion: '1.0.0',
|
||||||
|
nodeVersion: process.version,
|
||||||
|
communityEdition: false,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@ -17,17 +17,23 @@ const isValidPluginName = plugin => {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
async init(ctx) {
|
async init() {
|
||||||
const currentEnvironment = strapi.app.env;
|
|
||||||
const uuid = strapi.config.get('uuid', false);
|
const uuid = strapi.config.get('uuid', false);
|
||||||
const autoReload = strapi.config.get('autoReload', false);
|
|
||||||
const strapiVersion = strapi.config.get('info.strapi', null);
|
|
||||||
|
|
||||||
const hasAdmin = await strapi.admin.services.user.exists();
|
const hasAdmin = await strapi.admin.services.user.exists();
|
||||||
|
|
||||||
return ctx.send({
|
return { data: { uuid, hasAdmin } };
|
||||||
data: { uuid, currentEnvironment, autoReload, strapiVersion, hasAdmin },
|
},
|
||||||
});
|
|
||||||
|
async information() {
|
||||||
|
const currentEnvironment = strapi.app.env;
|
||||||
|
const autoReload = strapi.config.get('autoReload', false);
|
||||||
|
const strapiVersion = strapi.config.get('info.strapi', null);
|
||||||
|
const nodeVersion = process.version;
|
||||||
|
const communityEdition = !strapi.EE;
|
||||||
|
|
||||||
|
return {
|
||||||
|
data: { currentEnvironment, autoReload, strapiVersion, nodeVersion, communityEdition },
|
||||||
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
async installPlugin(ctx) {
|
async installPlugin(ctx) {
|
||||||
Loading…
x
Reference in New Issue
Block a user