mirror of
https://github.com/strapi/strapi.git
synced 2025-12-26 14:44:31 +00:00
update tests
This commit is contained in:
parent
291aeb07bc
commit
24e1d979a7
@ -1,287 +0,0 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`Role CRUD End to End Can get the existing permissions 1`] = `
|
||||
Object {
|
||||
"conditions": Array [
|
||||
Object {
|
||||
"category": "default",
|
||||
"displayName": "Is creator",
|
||||
"id": "admin::is-creator",
|
||||
},
|
||||
Object {
|
||||
"category": "default",
|
||||
"displayName": "Has same role as creator",
|
||||
"id": "admin::has-same-role-as-creator",
|
||||
},
|
||||
],
|
||||
"sections": Object {
|
||||
"contentTypes": Array [
|
||||
Object {
|
||||
"action": "plugins::content-manager.explorer.create",
|
||||
"displayName": "Create",
|
||||
"subjects": Array [
|
||||
"plugins::users-permissions.user",
|
||||
],
|
||||
},
|
||||
Object {
|
||||
"action": "plugins::content-manager.explorer.delete",
|
||||
"displayName": "Delete",
|
||||
"subjects": Array [
|
||||
"plugins::users-permissions.user",
|
||||
],
|
||||
},
|
||||
Object {
|
||||
"action": "plugins::content-manager.explorer.publish",
|
||||
"displayName": "Publish",
|
||||
"subjects": Array [],
|
||||
},
|
||||
Object {
|
||||
"action": "plugins::content-manager.explorer.read",
|
||||
"displayName": "Read",
|
||||
"subjects": Array [
|
||||
"plugins::users-permissions.user",
|
||||
],
|
||||
},
|
||||
Object {
|
||||
"action": "plugins::content-manager.explorer.update",
|
||||
"displayName": "Update",
|
||||
"subjects": Array [
|
||||
"plugins::users-permissions.user",
|
||||
],
|
||||
},
|
||||
],
|
||||
"plugins": Array [
|
||||
Object {
|
||||
"action": "plugins::content-manager.collection-types.configure-view",
|
||||
"displayName": "Configure view",
|
||||
"plugin": "plugin::content-manager",
|
||||
"subCategory": "collection types",
|
||||
},
|
||||
Object {
|
||||
"action": "plugins::content-manager.components.configure-layout",
|
||||
"displayName": "Configure Layout",
|
||||
"plugin": "plugin::content-manager",
|
||||
"subCategory": "components",
|
||||
},
|
||||
Object {
|
||||
"action": "plugins::content-manager.single-types.configure-view",
|
||||
"displayName": "Configure view",
|
||||
"plugin": "plugin::content-manager",
|
||||
"subCategory": "single types",
|
||||
},
|
||||
Object {
|
||||
"action": "plugins::content-type-builder.read",
|
||||
"displayName": "Read",
|
||||
"plugin": "plugin::content-type-builder",
|
||||
"subCategory": "general",
|
||||
},
|
||||
Object {
|
||||
"action": "plugins::documentation.read",
|
||||
"displayName": "Access the Documentation",
|
||||
"plugin": "plugin::documentation",
|
||||
"subCategory": "general",
|
||||
},
|
||||
Object {
|
||||
"action": "plugins::documentation.settings.regenerate",
|
||||
"displayName": "Regenerate",
|
||||
"plugin": "plugin::documentation",
|
||||
"subCategory": "settings",
|
||||
},
|
||||
Object {
|
||||
"action": "plugins::documentation.settings.update",
|
||||
"displayName": "Update and delete",
|
||||
"plugin": "plugin::documentation",
|
||||
"subCategory": "settings",
|
||||
},
|
||||
Object {
|
||||
"action": "plugins::upload.assets.copy-link",
|
||||
"displayName": "Copy link",
|
||||
"plugin": "plugin::upload",
|
||||
"subCategory": "assets",
|
||||
},
|
||||
Object {
|
||||
"action": "plugins::upload.assets.create",
|
||||
"displayName": "Create (upload)",
|
||||
"plugin": "plugin::upload",
|
||||
"subCategory": "assets",
|
||||
},
|
||||
Object {
|
||||
"action": "plugins::upload.assets.download",
|
||||
"displayName": "Download",
|
||||
"plugin": "plugin::upload",
|
||||
"subCategory": "assets",
|
||||
},
|
||||
Object {
|
||||
"action": "plugins::upload.assets.update",
|
||||
"displayName": "Update (crop, details, replace) + delete",
|
||||
"plugin": "plugin::upload",
|
||||
"subCategory": "assets",
|
||||
},
|
||||
Object {
|
||||
"action": "plugins::upload.read",
|
||||
"displayName": "Access the Media Library",
|
||||
"plugin": "plugin::upload",
|
||||
"subCategory": "general",
|
||||
},
|
||||
Object {
|
||||
"action": "plugins::users-permissions.advanced-settings.read",
|
||||
"displayName": "Read",
|
||||
"plugin": "plugin::users-permissions",
|
||||
"subCategory": "advancedSettings",
|
||||
},
|
||||
Object {
|
||||
"action": "plugins::users-permissions.advanced-settings.update",
|
||||
"displayName": "Edit",
|
||||
"plugin": "plugin::users-permissions",
|
||||
"subCategory": "advancedSettings",
|
||||
},
|
||||
Object {
|
||||
"action": "plugins::users-permissions.email-templates.read",
|
||||
"displayName": "Read",
|
||||
"plugin": "plugin::users-permissions",
|
||||
"subCategory": "emailTemplates",
|
||||
},
|
||||
Object {
|
||||
"action": "plugins::users-permissions.email-templates.update",
|
||||
"displayName": "Edit",
|
||||
"plugin": "plugin::users-permissions",
|
||||
"subCategory": "emailTemplates",
|
||||
},
|
||||
Object {
|
||||
"action": "plugins::users-permissions.providers.read",
|
||||
"displayName": "Read",
|
||||
"plugin": "plugin::users-permissions",
|
||||
"subCategory": "providers",
|
||||
},
|
||||
Object {
|
||||
"action": "plugins::users-permissions.providers.update",
|
||||
"displayName": "Edit",
|
||||
"plugin": "plugin::users-permissions",
|
||||
"subCategory": "providers",
|
||||
},
|
||||
Object {
|
||||
"action": "plugins::users-permissions.roles.create",
|
||||
"displayName": "Create",
|
||||
"plugin": "plugin::users-permissions",
|
||||
"subCategory": "roles",
|
||||
},
|
||||
Object {
|
||||
"action": "plugins::users-permissions.roles.delete",
|
||||
"displayName": "Delete",
|
||||
"plugin": "plugin::users-permissions",
|
||||
"subCategory": "roles",
|
||||
},
|
||||
Object {
|
||||
"action": "plugins::users-permissions.roles.read",
|
||||
"displayName": "Read",
|
||||
"plugin": "plugin::users-permissions",
|
||||
"subCategory": "roles",
|
||||
},
|
||||
Object {
|
||||
"action": "plugins::users-permissions.roles.update",
|
||||
"displayName": "Update",
|
||||
"plugin": "plugin::users-permissions",
|
||||
"subCategory": "roles",
|
||||
},
|
||||
],
|
||||
"settings": Array [
|
||||
Object {
|
||||
"action": "admin::marketplace.plugins.install",
|
||||
"category": "plugins and marketplace",
|
||||
"displayName": "Install (only for dev env)",
|
||||
"subCategory": "plugins",
|
||||
},
|
||||
Object {
|
||||
"action": "admin::marketplace.plugins.uninstall",
|
||||
"category": "plugins and marketplace",
|
||||
"displayName": "Uninstall (only for dev env)",
|
||||
"subCategory": "plugins",
|
||||
},
|
||||
Object {
|
||||
"action": "admin::marketplace.read",
|
||||
"category": "plugins and marketplace",
|
||||
"displayName": "Access the marketplace",
|
||||
"subCategory": "marketplace",
|
||||
},
|
||||
Object {
|
||||
"action": "admin::roles.create",
|
||||
"category": "users and roles",
|
||||
"displayName": "Create",
|
||||
"subCategory": "roles",
|
||||
},
|
||||
Object {
|
||||
"action": "admin::roles.delete",
|
||||
"category": "users and roles",
|
||||
"displayName": "Delete",
|
||||
"subCategory": "roles",
|
||||
},
|
||||
Object {
|
||||
"action": "admin::roles.read",
|
||||
"category": "users and roles",
|
||||
"displayName": "Read",
|
||||
"subCategory": "roles",
|
||||
},
|
||||
Object {
|
||||
"action": "admin::roles.update",
|
||||
"category": "users and roles",
|
||||
"displayName": "Update",
|
||||
"subCategory": "roles",
|
||||
},
|
||||
Object {
|
||||
"action": "admin::users.create",
|
||||
"category": "users and roles",
|
||||
"displayName": "Create (invite)",
|
||||
"subCategory": "users",
|
||||
},
|
||||
Object {
|
||||
"action": "admin::users.delete",
|
||||
"category": "users and roles",
|
||||
"displayName": "Delete",
|
||||
"subCategory": "users",
|
||||
},
|
||||
Object {
|
||||
"action": "admin::users.read",
|
||||
"category": "users and roles",
|
||||
"displayName": "Read",
|
||||
"subCategory": "users",
|
||||
},
|
||||
Object {
|
||||
"action": "admin::users.update",
|
||||
"category": "users and roles",
|
||||
"displayName": "Update",
|
||||
"subCategory": "users",
|
||||
},
|
||||
Object {
|
||||
"action": "admin::webhooks.create",
|
||||
"category": "webhooks",
|
||||
"displayName": "Create",
|
||||
"subCategory": "general",
|
||||
},
|
||||
Object {
|
||||
"action": "admin::webhooks.delete",
|
||||
"category": "webhooks",
|
||||
"displayName": "Delete",
|
||||
"subCategory": "general",
|
||||
},
|
||||
Object {
|
||||
"action": "admin::webhooks.read",
|
||||
"category": "webhooks",
|
||||
"displayName": "Read",
|
||||
"subCategory": "general",
|
||||
},
|
||||
Object {
|
||||
"action": "admin::webhooks.update",
|
||||
"category": "webhooks",
|
||||
"displayName": "Update",
|
||||
"subCategory": "general",
|
||||
},
|
||||
Object {
|
||||
"action": "plugins::upload.settings.read",
|
||||
"category": "media library",
|
||||
"displayName": "Access the Media Library settings page",
|
||||
"subCategory": "general",
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
`;
|
||||
@ -1,7 +1,8 @@
|
||||
'use strict';
|
||||
|
||||
const { has, pipe, prop, pick } = require('lodash/fp');
|
||||
const { MANY_RELATIONS, setCreatorFields } = require('strapi-utils').relations.constants;
|
||||
const { MANY_RELATIONS } = require('strapi-utils').relations.constants;
|
||||
const { setCreatorFields } = require('strapi-utils');
|
||||
|
||||
const { getService, wrapBadRequest, pickWritableAttributes } = require('../utils');
|
||||
const { validateBulkDeleteInput, validatePagination } = require('./validation');
|
||||
|
||||
@ -5,13 +5,18 @@ const { getService } = require('../utils');
|
||||
const { validateCreateLocaleInput, validateUpdateLocaleInput } = require('../validation/locales');
|
||||
const { formatLocale } = require('../domain/locale');
|
||||
|
||||
const sanitizeLocale = locale => {
|
||||
const model = strapi.getModel('locale', 'i18n');
|
||||
|
||||
return sanitizeEntity(locale, { model });
|
||||
};
|
||||
|
||||
const listLocales = async ctx => {
|
||||
const localesService = getService('locales');
|
||||
|
||||
const locales = await localesService.find();
|
||||
|
||||
const model = strapi.getModel('locale', 'i18n');
|
||||
ctx.body = sanitizeEntity(locales, { model });
|
||||
ctx.body = sanitizeLocale(locales);
|
||||
};
|
||||
|
||||
const createLocale = async ctx => {
|
||||
@ -25,7 +30,6 @@ const createLocale = async ctx => {
|
||||
}
|
||||
|
||||
const localesService = getService('locales');
|
||||
const model = strapi.getModel('locale', 'i18n');
|
||||
|
||||
const existingLocale = await localesService.findByCode(body.code);
|
||||
if (existingLocale) {
|
||||
@ -37,7 +41,7 @@ const createLocale = async ctx => {
|
||||
|
||||
const locale = await localesService.create(localeToCreate);
|
||||
|
||||
ctx.body = sanitizeEntity(locale, { model });
|
||||
ctx.body = sanitizeLocale(locale);
|
||||
};
|
||||
|
||||
const updateLocale = async ctx => {
|
||||
@ -52,7 +56,6 @@ const updateLocale = async ctx => {
|
||||
}
|
||||
|
||||
const localesService = getService('locales');
|
||||
const model = strapi.getModel('locale', 'i18n');
|
||||
|
||||
const existingLocale = await localesService.findById(id);
|
||||
if (!existingLocale) {
|
||||
@ -64,7 +67,7 @@ const updateLocale = async ctx => {
|
||||
|
||||
const updatedLocale = await localesService.update({ id }, updates);
|
||||
|
||||
ctx.body = sanitizeEntity(updatedLocale, { model });
|
||||
ctx.body = sanitizeLocale(updatedLocale);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
||||
@ -1,34 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
const find = async (...args) => {
|
||||
const locales = await strapi.query('locale', 'i18n').find(...args);
|
||||
const find = (...args) => strapi.query('locale', 'i18n').find(...args);
|
||||
|
||||
return locales;
|
||||
};
|
||||
const findById = id => strapi.query('locale', 'i18n').findOne({ id });
|
||||
|
||||
const findById = async id => {
|
||||
const locales = await strapi.query('locale', 'i18n').findOne({ id });
|
||||
const findByCode = code => strapi.query('locale', 'i18n').findOne({ code });
|
||||
|
||||
return locales;
|
||||
};
|
||||
const create = locale => strapi.query('locale', 'i18n').create(locale);
|
||||
|
||||
const findByCode = async code => {
|
||||
const locales = await strapi.query('locale', 'i18n').findOne({ code });
|
||||
|
||||
return locales;
|
||||
};
|
||||
|
||||
const create = async locale => {
|
||||
const locales = await strapi.query('locale', 'i18n').create(locale);
|
||||
|
||||
return locales;
|
||||
};
|
||||
|
||||
const update = async (params, updates) => {
|
||||
const locales = await strapi.query('locale', 'i18n').update(params, updates);
|
||||
|
||||
return locales;
|
||||
};
|
||||
const update = (params, updates) => strapi.query('locale', 'i18n').update(params, updates);
|
||||
|
||||
module.exports = {
|
||||
find,
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const { omit } = require('lodash/fp');
|
||||
|
||||
const { createStrapiInstance } = require('../../../test/helpers/strapi');
|
||||
const { createAuthRequest } = require('../../../test/helpers/request');
|
||||
|
||||
@ -7,6 +9,9 @@ const data = {
|
||||
locales: [],
|
||||
};
|
||||
|
||||
const omitTimestamps = omit(['updatedAt', 'createdAt', 'updated_at', 'created_at']);
|
||||
const compareLocales = (a, b) => (a.code < b.code ? -1 : 1);
|
||||
|
||||
describe('CRUD locales', () => {
|
||||
let rq;
|
||||
let strapi;
|
||||
@ -97,11 +102,6 @@ describe('CRUD locales', () => {
|
||||
expect(res.body).toMatchObject({ message: 'This locale already exists' });
|
||||
});
|
||||
|
||||
// - Faire documentation
|
||||
// - Finir tests
|
||||
// - voir comment stocker la locale par defaut
|
||||
// -
|
||||
|
||||
test('Can create a locale even if name already exists', async () => {
|
||||
const locale = {
|
||||
name: 'French',
|
||||
@ -137,7 +137,7 @@ describe('CRUD locales', () => {
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(res.body).toMatchObject({
|
||||
...data.locales[0],
|
||||
...omitTimestamps(data.locales[0]),
|
||||
...localeUpdate,
|
||||
});
|
||||
data.locales[0] = res.body;
|
||||
@ -199,7 +199,7 @@ describe('CRUD locales', () => {
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(res.body).toHaveLength(data.locales.length);
|
||||
expect(res.body.sort()).toMatchObject(data.locales.sort());
|
||||
expect(res.body.sort(compareLocales)).toMatchObject(data.locales.sort(compareLocales));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -275,6 +275,30 @@ Object {
|
||||
"displayName": "Update",
|
||||
"subCategory": "general",
|
||||
},
|
||||
Object {
|
||||
"action": "plugins::i18n.locale.create",
|
||||
"category": "Internationalization",
|
||||
"displayName": "Create",
|
||||
"subCategory": "Locales",
|
||||
},
|
||||
Object {
|
||||
"action": "plugins::i18n.locale.delete",
|
||||
"category": "Internationalization",
|
||||
"displayName": "Delete",
|
||||
"subCategory": "Locales",
|
||||
},
|
||||
Object {
|
||||
"action": "plugins::i18n.locale.read",
|
||||
"category": "Internationalization",
|
||||
"displayName": "Read",
|
||||
"subCategory": "Locales",
|
||||
},
|
||||
Object {
|
||||
"action": "plugins::i18n.locale.update",
|
||||
"category": "Internationalization",
|
||||
"displayName": "Update",
|
||||
"subCategory": "Locales",
|
||||
},
|
||||
Object {
|
||||
"action": "plugins::upload.settings.read",
|
||||
"category": "media library",
|
||||
|
||||
@ -52,7 +52,6 @@ const generateTestApp = async ({ appName, database }) => {
|
||||
'strapi-plugin-email',
|
||||
'strapi-plugin-upload',
|
||||
'strapi-plugin-graphql',
|
||||
'strapi-plugin-i18n',
|
||||
'strapi-plugin-documentation',
|
||||
'strapi-plugin-i18n',
|
||||
],
|
||||
|
||||
12
yarn.lock
12
yarn.lock
@ -18172,18 +18172,6 @@ stealthy-require@^1.1.1:
|
||||
resolved "https://registry.yarnpkg.com/stealthy-require/-/stealthy-require-1.1.1.tgz#35b09875b4ff49f26a777e509b3090a3226bf24b"
|
||||
integrity sha1-NbCYdbT/SfJqd35QmzCQoyJr8ks=
|
||||
|
||||
strapi-utils@3.4.5:
|
||||
version "3.4.5"
|
||||
resolved "https://registry.yarnpkg.com/strapi-utils/-/strapi-utils-3.4.5.tgz#138665a4852c9c7c618bc537b2d65c70aaff3926"
|
||||
integrity sha512-sRkCtnIt6BWc7rKJsg3e0bGFwS09phLYFU2qFEvMLuhGmPremjt+VyBn57cdung7bsMkJ5yQF5JA0e9w4LYYPQ==
|
||||
dependencies:
|
||||
"@sindresorhus/slugify" "1.1.0"
|
||||
date-fns "^2.8.1"
|
||||
lodash "4.17.20"
|
||||
pino "^4.7.1"
|
||||
pluralize "^8.0.0"
|
||||
yup "0.29.3"
|
||||
|
||||
stream-browserify@^2.0.1:
|
||||
version "2.0.2"
|
||||
resolved "https://registry.yarnpkg.com/stream-browserify/-/stream-browserify-2.0.2.tgz#87521d38a44aa7ee91ce1cd2a47df0cb49dd660b"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user