183 lines
4.4 KiB
JavaScript
Raw Normal View History

2022-04-08 18:04:35 +02:00
'use strict';
const { createStrapiInstance } = require('api-tests/strapi');
const { createAuthRequest } = require('api-tests/request');
const { createTestBuilder } = require('api-tests/builder');
2022-04-08 18:04:35 +02:00
let strapi;
let rq;
const categoryModel = {
kind: 'collectionType',
collectionName: 'categories',
displayName: 'Category',
singularName: 'category',
pluralName: 'categories',
description: '',
name: 'Category',
options: {},
2022-04-08 18:04:35 +02:00
pluginOptions: {
i18n: {
localized: true,
},
},
attributes: {
name: {
type: 'string',
[core] document unique field validation per content type and locale (#19153) * feat: use document service in content manager * feat: update contracts with meta information * chore: group metadata types into a single type * feat: metadata information in single types * chore: change meta contract to return documents instead of strings * fix: remove unused type * fix: ignore doc id if entry is null * fix: update contract metadata * feat: document metadata service * feat: locale and status filtering * chore: add comment * chore: refactor metadata service * chore: refactor entity manager exists to handle single types * feat: refactor single type controllers to use documents * feat: get locale param from in cm endpoints * Revert "feat: get locale param from in cm endpoints" This reverts commit 856c38588b8f8521cadd85c8c933f42a36a2178a. * feat: get locale param from cm endpoints * Update packages/plugins/i18n/server/src/controllers/validate-locale-creation.ts Co-authored-by: Ben Irvin <ben@innerdvations.com> * fix: entity manager unit tests * chore: unit test document metadata * feat: prevent empty string locale filtering * feat(core): document unique field validation per content type and locale * feat(e2e): test document unique fields * fix(admin): ts build * fix: cm contract import * chore: test new d&p cm features * feat(core): validate document unique fields within one publication state chore: remove build:ts * fix: search content manager api test * fix: cm tests * fix: cm tests * fix: cm tests * fix(content-manager): access to non default locale documents (#19190) * fix(content-manager): access to non default locale documents * chore(content-manager): revert route construction * fix(content-manager): api tests for number of draft relations * test(content-manager): counting number of draft relations for non default locales * chore(content-manager): remove default locale from entity manager countDraftRelations * test(document-service): api tests for unique document fields per publication state * test(i18n): api tests for unique document fields per locale * chore(api-tests): adjust author schema * chore(e2e): disable edit view tests (#19235) * fix(core): unique validation on publish * fix(api-tests): un-localise author * fix(e2e): incorrect path * fix(admin): tidy up * fix(admin): pass correct locale query params fix(core): pass locale outside of filters * chore(api-tests): wip comment for relatedEntityId logic * fix(core): entity validator tests * chore(api-tests): wip skip failing relations i18n test * chore(e2e): clean up editview spec * fix(content-manager): pass locale to publish and unpublish * fix(content-manager): fix test:ts:back * fix(e2e): update edit view expected path * fix(entity-validator): default to null locale fix(api-tests): wip i18n test changes * fix(e2e): wip UID fields * chore(content-type-builder): temporarily disable component unique field checkboxes (#19253) * fix(admin): wip correctly pass params feat(e2e): reintroduce uniqueness e2e tests * Refactor UID validation for V5 (#19285) * fix(database): wip remove UID unique DB constraint * feat(content-manager): update uid checking endpoints to look at locale * chore(admin): clean up * fix(content-manager): single type unit tests * fix(content-manager): send all params to uid endpoints * feat(e2e): update tar backup to support unique CT * fix(e2e): uniqueness spec * chore(e2e): remove only * fix(content-manager): only check UID availability against drafts feat(api-tests): test case for UID validation across locales * fix(content-manager): uid unit tests * chore(api-tests): clean up * chore(content-manager): clean up * chore(i18n): remove relatedEntityId reference --------- Co-authored-by: Marc-Roig <marc12info@gmail.com> Co-authored-by: Ben Irvin <ben@innerdvations.com> Co-authored-by: Josh <37798644+joshuaellis@users.noreply.github.com>
2024-01-29 15:35:20 +00:00
unique: true,
2022-04-08 18:04:35 +02:00
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' },
])
2022-04-08 18:04:35 +02:00
.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',
2022-04-08 18:04:35 +02:00
body: {
name: 'category in korean',
},
[core] document unique field validation per content type and locale (#19153) * feat: use document service in content manager * feat: update contracts with meta information * chore: group metadata types into a single type * feat: metadata information in single types * chore: change meta contract to return documents instead of strings * fix: remove unused type * fix: ignore doc id if entry is null * fix: update contract metadata * feat: document metadata service * feat: locale and status filtering * chore: add comment * chore: refactor metadata service * chore: refactor entity manager exists to handle single types * feat: refactor single type controllers to use documents * feat: get locale param from in cm endpoints * Revert "feat: get locale param from in cm endpoints" This reverts commit 856c38588b8f8521cadd85c8c933f42a36a2178a. * feat: get locale param from cm endpoints * Update packages/plugins/i18n/server/src/controllers/validate-locale-creation.ts Co-authored-by: Ben Irvin <ben@innerdvations.com> * fix: entity manager unit tests * chore: unit test document metadata * feat: prevent empty string locale filtering * feat(core): document unique field validation per content type and locale * feat(e2e): test document unique fields * fix(admin): ts build * fix: cm contract import * chore: test new d&p cm features * feat(core): validate document unique fields within one publication state chore: remove build:ts * fix: search content manager api test * fix: cm tests * fix: cm tests * fix: cm tests * fix(content-manager): access to non default locale documents (#19190) * fix(content-manager): access to non default locale documents * chore(content-manager): revert route construction * fix(content-manager): api tests for number of draft relations * test(content-manager): counting number of draft relations for non default locales * chore(content-manager): remove default locale from entity manager countDraftRelations * test(document-service): api tests for unique document fields per publication state * test(i18n): api tests for unique document fields per locale * chore(api-tests): adjust author schema * chore(e2e): disable edit view tests (#19235) * fix(core): unique validation on publish * fix(api-tests): un-localise author * fix(e2e): incorrect path * fix(admin): tidy up * fix(admin): pass correct locale query params fix(core): pass locale outside of filters * chore(api-tests): wip comment for relatedEntityId logic * fix(core): entity validator tests * chore(api-tests): wip skip failing relations i18n test * chore(e2e): clean up editview spec * fix(content-manager): pass locale to publish and unpublish * fix(content-manager): fix test:ts:back * fix(e2e): update edit view expected path * fix(entity-validator): default to null locale fix(api-tests): wip i18n test changes * fix(e2e): wip UID fields * chore(content-type-builder): temporarily disable component unique field checkboxes (#19253) * fix(admin): wip correctly pass params feat(e2e): reintroduce uniqueness e2e tests * Refactor UID validation for V5 (#19285) * fix(database): wip remove UID unique DB constraint * feat(content-manager): update uid checking endpoints to look at locale * chore(admin): clean up * fix(content-manager): single type unit tests * fix(content-manager): send all params to uid endpoints * feat(e2e): update tar backup to support unique CT * fix(e2e): uniqueness spec * chore(e2e): remove only * fix(content-manager): only check UID availability against drafts feat(api-tests): test case for UID validation across locales * fix(content-manager): uid unit tests * chore(api-tests): clean up * chore(content-manager): clean up * chore(i18n): remove relatedEntityId reference --------- Co-authored-by: Marc-Roig <marc12info@gmail.com> Co-authored-by: Ben Irvin <ben@innerdvations.com> Co-authored-by: Josh <37798644+joshuaellis@users.noreply.github.com>
2024-01-29 15:35:20 +00:00
qs: {
locale: 'ko',
},
2022-04-08 18:04:35 +02:00
});
const { statusCode, body } = res;
expect(statusCode).toBe(200);
expect(body).toMatchObject({
locale: 'ko',
name: 'category in korean',
});
data.categories.push(res.body);
});
2022-12-02 16:51:09 +01:00
// 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: 'POST',
url: `/content-manager/collection-types/api::category.category`,
qs: {
locale,
relatedEntityId: data.categories[0].id,
},
body: {
name: `category in ${locale}`,
[core] document unique field validation per content type and locale (#19153) * feat: use document service in content manager * feat: update contracts with meta information * chore: group metadata types into a single type * feat: metadata information in single types * chore: change meta contract to return documents instead of strings * fix: remove unused type * fix: ignore doc id if entry is null * fix: update contract metadata * feat: document metadata service * feat: locale and status filtering * chore: add comment * chore: refactor metadata service * chore: refactor entity manager exists to handle single types * feat: refactor single type controllers to use documents * feat: get locale param from in cm endpoints * Revert "feat: get locale param from in cm endpoints" This reverts commit 856c38588b8f8521cadd85c8c933f42a36a2178a. * feat: get locale param from cm endpoints * Update packages/plugins/i18n/server/src/controllers/validate-locale-creation.ts Co-authored-by: Ben Irvin <ben@innerdvations.com> * fix: entity manager unit tests * chore: unit test document metadata * feat: prevent empty string locale filtering * feat(core): document unique field validation per content type and locale * feat(e2e): test document unique fields * fix(admin): ts build * fix: cm contract import * chore: test new d&p cm features * feat(core): validate document unique fields within one publication state chore: remove build:ts * fix: search content manager api test * fix: cm tests * fix: cm tests * fix: cm tests * fix(content-manager): access to non default locale documents (#19190) * fix(content-manager): access to non default locale documents * chore(content-manager): revert route construction * fix(content-manager): api tests for number of draft relations * test(content-manager): counting number of draft relations for non default locales * chore(content-manager): remove default locale from entity manager countDraftRelations * test(document-service): api tests for unique document fields per publication state * test(i18n): api tests for unique document fields per locale * chore(api-tests): adjust author schema * chore(e2e): disable edit view tests (#19235) * fix(core): unique validation on publish * fix(api-tests): un-localise author * fix(e2e): incorrect path * fix(admin): tidy up * fix(admin): pass correct locale query params fix(core): pass locale outside of filters * chore(api-tests): wip comment for relatedEntityId logic * fix(core): entity validator tests * chore(api-tests): wip skip failing relations i18n test * chore(e2e): clean up editview spec * fix(content-manager): pass locale to publish and unpublish * fix(content-manager): fix test:ts:back * fix(e2e): update edit view expected path * fix(entity-validator): default to null locale fix(api-tests): wip i18n test changes * fix(e2e): wip UID fields * chore(content-type-builder): temporarily disable component unique field checkboxes (#19253) * fix(admin): wip correctly pass params feat(e2e): reintroduce uniqueness e2e tests * Refactor UID validation for V5 (#19285) * fix(database): wip remove UID unique DB constraint * feat(content-manager): update uid checking endpoints to look at locale * chore(admin): clean up * fix(content-manager): single type unit tests * fix(content-manager): send all params to uid endpoints * feat(e2e): update tar backup to support unique CT * fix(e2e): uniqueness spec * chore(e2e): remove only * fix(content-manager): only check UID availability against drafts feat(api-tests): test case for UID validation across locales * fix(content-manager): uid unit tests * chore(api-tests): clean up * chore(content-manager): clean up * chore(i18n): remove relatedEntityId reference --------- Co-authored-by: Marc-Roig <marc12info@gmail.com> Co-authored-by: Ben Irvin <ben@innerdvations.com> Co-authored-by: Josh <37798644+joshuaellis@users.noreply.github.com>
2024-01-29 15:35:20 +00:00
locale,
},
});
[core] document unique field validation per content type and locale (#19153) * feat: use document service in content manager * feat: update contracts with meta information * chore: group metadata types into a single type * feat: metadata information in single types * chore: change meta contract to return documents instead of strings * fix: remove unused type * fix: ignore doc id if entry is null * fix: update contract metadata * feat: document metadata service * feat: locale and status filtering * chore: add comment * chore: refactor metadata service * chore: refactor entity manager exists to handle single types * feat: refactor single type controllers to use documents * feat: get locale param from in cm endpoints * Revert "feat: get locale param from in cm endpoints" This reverts commit 856c38588b8f8521cadd85c8c933f42a36a2178a. * feat: get locale param from cm endpoints * Update packages/plugins/i18n/server/src/controllers/validate-locale-creation.ts Co-authored-by: Ben Irvin <ben@innerdvations.com> * fix: entity manager unit tests * chore: unit test document metadata * feat: prevent empty string locale filtering * feat(core): document unique field validation per content type and locale * feat(e2e): test document unique fields * fix(admin): ts build * fix: cm contract import * chore: test new d&p cm features * feat(core): validate document unique fields within one publication state chore: remove build:ts * fix: search content manager api test * fix: cm tests * fix: cm tests * fix: cm tests * fix(content-manager): access to non default locale documents (#19190) * fix(content-manager): access to non default locale documents * chore(content-manager): revert route construction * fix(content-manager): api tests for number of draft relations * test(content-manager): counting number of draft relations for non default locales * chore(content-manager): remove default locale from entity manager countDraftRelations * test(document-service): api tests for unique document fields per publication state * test(i18n): api tests for unique document fields per locale * chore(api-tests): adjust author schema * chore(e2e): disable edit view tests (#19235) * fix(core): unique validation on publish * fix(api-tests): un-localise author * fix(e2e): incorrect path * fix(admin): tidy up * fix(admin): pass correct locale query params fix(core): pass locale outside of filters * chore(api-tests): wip comment for relatedEntityId logic * fix(core): entity validator tests * chore(api-tests): wip skip failing relations i18n test * chore(e2e): clean up editview spec * fix(content-manager): pass locale to publish and unpublish * fix(content-manager): fix test:ts:back * fix(e2e): update edit view expected path * fix(entity-validator): default to null locale fix(api-tests): wip i18n test changes * fix(e2e): wip UID fields * chore(content-type-builder): temporarily disable component unique field checkboxes (#19253) * fix(admin): wip correctly pass params feat(e2e): reintroduce uniqueness e2e tests * Refactor UID validation for V5 (#19285) * fix(database): wip remove UID unique DB constraint * feat(content-manager): update uid checking endpoints to look at locale * chore(admin): clean up * fix(content-manager): single type unit tests * fix(content-manager): send all params to uid endpoints * feat(e2e): update tar backup to support unique CT * fix(e2e): uniqueness spec * chore(e2e): remove only * fix(content-manager): only check UID availability against drafts feat(api-tests): test case for UID validation across locales * fix(content-manager): uid unit tests * chore(api-tests): clean up * chore(content-manager): clean up * chore(i18n): remove relatedEntityId reference --------- Co-authored-by: Marc-Roig <marc12info@gmail.com> Co-authored-by: Ben Irvin <ben@innerdvations.com> Co-authored-by: Josh <37798644+joshuaellis@users.noreply.github.com>
2024-01-29 15:35:20 +00:00
expect(res.statusCode).toBe(200);
expect(res.body.locale).toBe(locale);
}
const { statusCode, body } = res;
expect(statusCode).toBe(200);
[core] document unique field validation per content type and locale (#19153) * feat: use document service in content manager * feat: update contracts with meta information * chore: group metadata types into a single type * feat: metadata information in single types * chore: change meta contract to return documents instead of strings * fix: remove unused type * fix: ignore doc id if entry is null * fix: update contract metadata * feat: document metadata service * feat: locale and status filtering * chore: add comment * chore: refactor metadata service * chore: refactor entity manager exists to handle single types * feat: refactor single type controllers to use documents * feat: get locale param from in cm endpoints * Revert "feat: get locale param from in cm endpoints" This reverts commit 856c38588b8f8521cadd85c8c933f42a36a2178a. * feat: get locale param from cm endpoints * Update packages/plugins/i18n/server/src/controllers/validate-locale-creation.ts Co-authored-by: Ben Irvin <ben@innerdvations.com> * fix: entity manager unit tests * chore: unit test document metadata * feat: prevent empty string locale filtering * feat(core): document unique field validation per content type and locale * feat(e2e): test document unique fields * fix(admin): ts build * fix: cm contract import * chore: test new d&p cm features * feat(core): validate document unique fields within one publication state chore: remove build:ts * fix: search content manager api test * fix: cm tests * fix: cm tests * fix: cm tests * fix(content-manager): access to non default locale documents (#19190) * fix(content-manager): access to non default locale documents * chore(content-manager): revert route construction * fix(content-manager): api tests for number of draft relations * test(content-manager): counting number of draft relations for non default locales * chore(content-manager): remove default locale from entity manager countDraftRelations * test(document-service): api tests for unique document fields per publication state * test(i18n): api tests for unique document fields per locale * chore(api-tests): adjust author schema * chore(e2e): disable edit view tests (#19235) * fix(core): unique validation on publish * fix(api-tests): un-localise author * fix(e2e): incorrect path * fix(admin): tidy up * fix(admin): pass correct locale query params fix(core): pass locale outside of filters * chore(api-tests): wip comment for relatedEntityId logic * fix(core): entity validator tests * chore(api-tests): wip skip failing relations i18n test * chore(e2e): clean up editview spec * fix(content-manager): pass locale to publish and unpublish * fix(content-manager): fix test:ts:back * fix(e2e): update edit view expected path * fix(entity-validator): default to null locale fix(api-tests): wip i18n test changes * fix(e2e): wip UID fields * chore(content-type-builder): temporarily disable component unique field checkboxes (#19253) * fix(admin): wip correctly pass params feat(e2e): reintroduce uniqueness e2e tests * Refactor UID validation for V5 (#19285) * fix(database): wip remove UID unique DB constraint * feat(content-manager): update uid checking endpoints to look at locale * chore(admin): clean up * fix(content-manager): single type unit tests * fix(content-manager): send all params to uid endpoints * feat(e2e): update tar backup to support unique CT * fix(e2e): uniqueness spec * chore(e2e): remove only * fix(content-manager): only check UID availability against drafts feat(api-tests): test case for UID validation across locales * fix(content-manager): uid unit tests * chore(api-tests): clean up * chore(content-manager): clean up * chore(i18n): remove relatedEntityId reference --------- Co-authored-by: Marc-Roig <marc12info@gmail.com> Co-authored-by: Ben Irvin <ben@innerdvations.com> Co-authored-by: Josh <37798644+joshuaellis@users.noreply.github.com>
2024-01-29 15:35:20 +00:00
data.categories.push(body);
});
test.skip('should not be able to duplicate unique field values within the same locale', async () => {
const res = await rq({
method: 'POST',
url: `/content-manager/collection-types/api::category.category`,
body: {
name: `category in english`,
},
});
expect(res.statusCode).toBe(400);
expect(res.body.error.message).toEqual('This attribute must be unique');
});
2022-04-08 18:04:35 +02:00
});
// V5: Fix bulk actions
describe.skip('Bulk Delete', () => {
2022-04-08 18:04:35 +02:00
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();
});
});
});