mirror of
https://github.com/strapi/strapi.git
synced 2025-11-25 22:51:33 +00:00
Add appropriate tests
Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
parent
aff529d09e
commit
5e79e9c275
@ -45,6 +45,30 @@ describe('Content Manager End to End', () => {
|
|||||||
60000
|
60000
|
||||||
);
|
);
|
||||||
|
|
||||||
|
describe('Conent Types api', () => {
|
||||||
|
test('Label is pluralized', async () => {
|
||||||
|
const res = await rq({
|
||||||
|
url: `/content-manager/content-types`,
|
||||||
|
method: 'GET',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(res.statusCode).toBe(200);
|
||||||
|
expect(res.body.data).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
label: 'Articles',
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
label: 'Tags',
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
label: 'Categories',
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('Test manyToMany relation (article - tag) with Content Manager', () => {
|
describe('Test manyToMany relation (article - tag) with Content Manager', () => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
data = {
|
data = {
|
||||||
|
|||||||
@ -27,6 +27,22 @@ describe('Content Manager single types', () => {
|
|||||||
|
|
||||||
afterAll(() => modelsUtils.deleteContentType('single-type'), 60000);
|
afterAll(() => modelsUtils.deleteContentType('single-type'), 60000);
|
||||||
|
|
||||||
|
test('Label is not pluralized', async () => {
|
||||||
|
const res = await rq({
|
||||||
|
url: `/content-manager/content-types?kind=singleType`,
|
||||||
|
method: 'GET',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(res.statusCode).toBe(200);
|
||||||
|
expect(res.body.data).toEqual(
|
||||||
|
expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
label: 'Single-type-model',
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test('find single type content returns 404 when not created', async () => {
|
test('find single type content returns 404 when not created', async () => {
|
||||||
const res = await rq({
|
const res = await rq({
|
||||||
url: `/content-manager/explorer/${uid}`,
|
url: `/content-manager/explorer/${uid}`,
|
||||||
|
|||||||
@ -119,7 +119,7 @@ const editContentType = async (uid, { contentType, components = [] }) => {
|
|||||||
if (newKind !== previousKind && newKind === 'singleType') {
|
if (newKind !== previousKind && newKind === 'singleType') {
|
||||||
const entryCount = await strapi.query(uid).count();
|
const entryCount = await strapi.query(uid).count();
|
||||||
if (entryCount > 1) {
|
if (entryCount > 1) {
|
||||||
throw new Error(
|
throw strapi.errors.badRequest(
|
||||||
'You cannot convert a collectionType to a singleType when having multiple entries in DB'
|
'You cannot convert a collectionType to a singleType when having multiple entries in DB'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -124,5 +124,61 @@ describe('Content Type Builder - Content types', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Cannot switch collectionType to singleType when multiple entries in DB', async () => {
|
||||||
|
const createRes = await rq({
|
||||||
|
method: 'POST',
|
||||||
|
url: '/content-type-builder/content-types',
|
||||||
|
body: {
|
||||||
|
contentType: {
|
||||||
|
kind: 'collectionType',
|
||||||
|
name: 'test-collection',
|
||||||
|
attributes: {
|
||||||
|
title: {
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(createRes.statusCode).toBe(201);
|
||||||
|
|
||||||
|
await waitRestart();
|
||||||
|
|
||||||
|
const { uid } = createRes.body.data;
|
||||||
|
|
||||||
|
// create data
|
||||||
|
for (let i = 0; i < 2; i++) {
|
||||||
|
const res = await rq({
|
||||||
|
method: 'POST',
|
||||||
|
url: `/test-collections`,
|
||||||
|
body: {
|
||||||
|
title: 'Test',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(res.statusCode).toBe(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
const updateRes = await rq({
|
||||||
|
method: 'PUT',
|
||||||
|
url: `/content-type-builder/content-types/${uid}`,
|
||||||
|
body: {
|
||||||
|
contentType: {
|
||||||
|
kind: 'singleType',
|
||||||
|
name: 'test-collection',
|
||||||
|
attributes: {
|
||||||
|
title: {
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(updateRes.statusCode).toBe(400);
|
||||||
|
expect(updateRes.body.error).toMatch('multiple entries in DB');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user