mirror of
https://github.com/strapi/strapi.git
synced 2025-07-15 04:53:17 +00:00

* feat: use document service in content manager * feat: locale and status filtering * feat: refactor single type controllers to use documents * feat: get locale param from in cm endpoints * feat: get locale param from cm endpoints * feat: prevent empty string locale filtering * fix(content-manager): access to non default locale documents * chore(content-manager): revert route construction * test(content-manager): counting number of draft relations for non default locales * chore(content-manager): remove default locale from entity manager countDraftRelations --------- Co-authored-by: Ben Irvin <ben@innerdvations.com> Co-authored-by: Jamie Howard <48524071+jhoward1994@users.noreply.github.com> Co-authored-by: Josh <37798644+joshuaellis@users.noreply.github.com>
164 lines
3.9 KiB
JavaScript
164 lines
3.9 KiB
JavaScript
'use strict';
|
|
|
|
const { createStrapiInstance } = require('api-tests/strapi');
|
|
const { createAuthRequest } = require('api-tests/request');
|
|
const { createTestBuilder } = require('api-tests/builder');
|
|
|
|
let strapi;
|
|
let rq;
|
|
|
|
const categoryModel = {
|
|
kind: 'collectionType',
|
|
collectionName: 'categories',
|
|
displayName: 'Category',
|
|
singularName: 'category',
|
|
pluralName: 'categories',
|
|
description: '',
|
|
name: 'Category',
|
|
options: {},
|
|
pluginOptions: {
|
|
i18n: {
|
|
localized: true,
|
|
},
|
|
},
|
|
attributes: {
|
|
name: {
|
|
type: 'string',
|
|
pluginOptions: {
|
|
i18n: {
|
|
localized: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
const data = {
|
|
categories: [],
|
|
};
|
|
|
|
describe('i18n - Content API', () => {
|
|
const builder = createTestBuilder();
|
|
|
|
beforeAll(async () => {
|
|
await builder
|
|
.addContentTypes([categoryModel])
|
|
.addFixtures('plugin::i18n.locale', [
|
|
{ name: 'Korean', code: 'ko' },
|
|
{ name: 'Italian', code: 'it' },
|
|
{ name: 'French', code: 'fr' },
|
|
{ name: 'Spanish (Argentina)', code: 'es-AR' },
|
|
])
|
|
.build();
|
|
|
|
strapi = await createStrapiInstance();
|
|
rq = await createAuthRequest({ strapi });
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await strapi.destroy();
|
|
await builder.cleanup();
|
|
});
|
|
|
|
describe('Create', () => {
|
|
test('default locale', async () => {
|
|
const res = await rq({
|
|
method: 'POST',
|
|
url: '/content-manager/collection-types/api::category.category',
|
|
body: {
|
|
name: 'category in english',
|
|
},
|
|
});
|
|
|
|
const { statusCode, body } = res;
|
|
|
|
expect(statusCode).toBe(200);
|
|
expect(body).toMatchObject({
|
|
locale: 'en',
|
|
localizations: [],
|
|
name: 'category in english',
|
|
});
|
|
data.categories.push(res.body);
|
|
});
|
|
|
|
test('non-default locale', async () => {
|
|
const res = await rq({
|
|
method: 'POST',
|
|
url: '/content-manager/collection-types/api::category.category',
|
|
body: {
|
|
locale: 'ko',
|
|
name: 'category in korean',
|
|
},
|
|
});
|
|
|
|
const { statusCode, body } = res;
|
|
|
|
expect(statusCode).toBe(200);
|
|
expect(body).toMatchObject({
|
|
locale: 'ko',
|
|
name: 'category in korean',
|
|
});
|
|
data.categories.push(res.body);
|
|
});
|
|
|
|
// This tests is sensible to foreign keys deadlocks
|
|
// foreign keys deadlock example: https://gist.github.com/roustem/db2398aa38be0cc88364
|
|
test('all related locales', async () => {
|
|
let res;
|
|
|
|
for (const locale of ['ko', 'it', 'fr', 'es-AR']) {
|
|
res = await rq({
|
|
method: 'PUT',
|
|
url: `/content-manager/collection-types/api::category.category/${data.categories[0].id}`,
|
|
body: {
|
|
name: `category in ${locale}`,
|
|
locale: locale,
|
|
},
|
|
});
|
|
expect(res.statusCode).toBe(200);
|
|
expect(res.body.locale).toBe(locale);
|
|
}
|
|
|
|
const { statusCode, body } = res;
|
|
|
|
expect(statusCode).toBe(200);
|
|
data.categories.push(res.body);
|
|
});
|
|
});
|
|
|
|
// V5: Fix bulk actions
|
|
describe.skip('Bulk Delete', () => {
|
|
test('default locale', async () => {
|
|
const res = await rq({
|
|
method: 'POST',
|
|
url: '/content-manager/collection-types/api::category.category/actions/bulkDelete',
|
|
body: {
|
|
ids: [data.categories[0].id],
|
|
},
|
|
});
|
|
|
|
const { statusCode, body } = res;
|
|
|
|
expect(statusCode).toBe(200);
|
|
expect(body).toMatchObject({ count: 1 });
|
|
data.categories.shift();
|
|
});
|
|
|
|
test('non-default locale', async () => {
|
|
const res = await rq({
|
|
method: 'POST',
|
|
url: '/content-manager/collection-types/api::category.category/actions/bulkDelete',
|
|
body: {
|
|
ids: [data.categories[0].id],
|
|
},
|
|
});
|
|
|
|
const { statusCode, body } = res;
|
|
|
|
expect(statusCode).toBe(200);
|
|
expect(body).toMatchObject({ count: 1 });
|
|
data.categories.shift();
|
|
});
|
|
});
|
|
});
|