mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 00:39:49 +00:00
add tests
This commit is contained in:
parent
34c7162ae7
commit
a8e5be2d67
@ -7,6 +7,7 @@
|
|||||||
const { createStrapiInstance } = require('api-tests/strapi');
|
const { createStrapiInstance } = require('api-tests/strapi');
|
||||||
const { createAuthRequest } = require('api-tests/request');
|
const { createAuthRequest } = require('api-tests/request');
|
||||||
const modelsUtils = require('api-tests/models');
|
const modelsUtils = require('api-tests/models');
|
||||||
|
const { createTestBuilder } = require('api-tests/builder');
|
||||||
|
|
||||||
let strapi;
|
let strapi;
|
||||||
let rq;
|
let rq;
|
||||||
@ -17,8 +18,28 @@ const restart = async () => {
|
|||||||
rq = await createAuthRequest({ strapi });
|
rq = await createAuthRequest({ strapi });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const builder = createTestBuilder();
|
||||||
|
|
||||||
|
const localTestData = {
|
||||||
|
models: {
|
||||||
|
dog: {
|
||||||
|
singularName: 'dog',
|
||||||
|
pluralName: 'dogs',
|
||||||
|
collectionName: 'dogs-collection',
|
||||||
|
displayName: 'Dog Display',
|
||||||
|
kind: 'collectionType',
|
||||||
|
attributes: {
|
||||||
|
name: {
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
describe('Content Type Builder - Content types', () => {
|
describe('Content Type Builder - Content types', () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
|
await builder.addContentType(localTestData.models.dog).build();
|
||||||
strapi = await createStrapiInstance();
|
strapi = await createStrapiInstance();
|
||||||
rq = await createAuthRequest({ strapi });
|
rq = await createAuthRequest({ strapi });
|
||||||
});
|
});
|
||||||
@ -129,6 +150,54 @@ describe('Content Type Builder - Content types', () => {
|
|||||||
expect(res.body).toMatchSnapshot();
|
expect(res.body).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test.each([
|
||||||
|
['singularName', 'singularName'],
|
||||||
|
['singularName', 'pluralName'],
|
||||||
|
['pluralName', 'singularName'],
|
||||||
|
['pluralName', 'pluralName'],
|
||||||
|
['pluralName', 'collectionName'],
|
||||||
|
])(`Cannot use %p that exists as another type's %p`, async (sourceField, matchField) => {
|
||||||
|
const body = {
|
||||||
|
contentType: {
|
||||||
|
displayName: 'Dog2',
|
||||||
|
pluralName: 'safe-plural-name',
|
||||||
|
singularName: 'safe-singular-name',
|
||||||
|
collectionName: 'safe-collection-name',
|
||||||
|
attributes: {
|
||||||
|
name: {
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// set the conflicting name in the given field
|
||||||
|
body.contentType[sourceField] = localTestData.models.dog[matchField];
|
||||||
|
|
||||||
|
const res = await rq({
|
||||||
|
method: 'POST',
|
||||||
|
url: '/content-type-builder/content-types',
|
||||||
|
body,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(res.statusCode).toBe(400);
|
||||||
|
expect(res.body).toEqual({
|
||||||
|
error: {
|
||||||
|
details: {
|
||||||
|
errors: [
|
||||||
|
{
|
||||||
|
message: `contentType: name \`${body.contentType[sourceField]}\` is already being used by another content type.`,
|
||||||
|
name: 'ValidationError',
|
||||||
|
path: ['contentType', sourceField],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
message: `contentType: name \`${body.contentType[sourceField]}\` is already being used by another content type.`,
|
||||||
|
name: 'ValidationError',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('Cannot use same string for singularName and pluralName', async () => {
|
test('Cannot use same string for singularName and pluralName', async () => {
|
||||||
const res = await rq({
|
const res = await rq({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
@ -138,7 +138,7 @@ const nameIsAvailable = (isEdition) => {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
name: 'nameAlreadyUsed',
|
name: 'nameAlreadyUsed',
|
||||||
message: 'Content Type name `${value}` is already being used.',
|
message: 'contentType: name `${value}` is already being used by another content type.',
|
||||||
test(value) {
|
test(value) {
|
||||||
// don't check on edition
|
// don't check on edition
|
||||||
if (isEdition) return true;
|
if (isEdition) return true;
|
||||||
@ -158,7 +158,7 @@ const nameIsNotExistingCollectionName = (isEdition) => {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
name: 'nameAlreadyUsed',
|
name: 'nameAlreadyUsed',
|
||||||
message: 'Content Type name `${value}` is already being used by another content type.',
|
message: 'contentType: name `${value}` is already being used by another content type.',
|
||||||
test(value) {
|
test(value) {
|
||||||
// don't check on edition
|
// don't check on edition
|
||||||
if (isEdition) return true;
|
if (isEdition) return true;
|
||||||
|
@ -101,7 +101,7 @@ module.exports = function createComponentBuilder() {
|
|||||||
contentType
|
contentType
|
||||||
.setUID(uid)
|
.setUID(uid)
|
||||||
.set('kind', infos.kind || typeKinds.COLLECTION_TYPE)
|
.set('kind', infos.kind || typeKinds.COLLECTION_TYPE)
|
||||||
.set('collectionName', nameToCollectionName(infos.pluralName))
|
.set('collectionName', infos.collectionName || nameToCollectionName(infos.pluralName))
|
||||||
.set('info', {
|
.set('info', {
|
||||||
singularName: infos.singularName,
|
singularName: infos.singularName,
|
||||||
pluralName: infos.pluralName,
|
pluralName: infos.pluralName,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user