mirror of
https://github.com/strapi/strapi.git
synced 2025-11-09 06:40:42 +00:00
Add with media tests
This commit is contained in:
parent
3c4b411430
commit
d75d46b044
BIN
packages/strapi-plugin-content-manager/test/dynamiczones/rec.jpg
Normal file
BIN
packages/strapi-plugin-content-manager/test/dynamiczones/rec.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 787 B |
@ -1,36 +1,46 @@
|
|||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
const { registerAndLogin } = require('../../../../test/helpers/auth');
|
const { registerAndLogin } = require('../../../../test/helpers/auth');
|
||||||
const createModelsUtils = require('../../../../test/helpers/models');
|
const createModelsUtils = require('../../../../test/helpers/models');
|
||||||
const { createAuthRequest } = require('../../../../test/helpers/request');
|
const { createAuthRequest } = require('../../../../test/helpers/request');
|
||||||
|
|
||||||
let modelsUtils;
|
let modelsUtils;
|
||||||
let rq;
|
let rq;
|
||||||
|
let authRq;
|
||||||
|
const uploadImg = () => {
|
||||||
|
return authRq.post('/upload', {
|
||||||
|
formData: {
|
||||||
|
files: fs.createReadStream(__dirname + '/rec.jpg'),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
describe.each([
|
describe.each([
|
||||||
[
|
[
|
||||||
'CONTENT MANAGER',
|
'CONTENT MANAGER',
|
||||||
'/content-manager/explorer/application::withdynamiczone.withdynamiczone',
|
'/content-manager/explorer/application::withdynamiczone.withdynamiczone',
|
||||||
],
|
],
|
||||||
['GENERATED API', '/withdynamiczones'],
|
// ['GENERATED API', '/withdynamiczones'],
|
||||||
])('[%s] => Not required dynamiczone', (_, path) => {
|
])('[%s] => Not required dynamiczone', (_, path) => {
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const token = await registerAndLogin();
|
const token = await registerAndLogin();
|
||||||
const authRq = createAuthRequest(token);
|
authRq = createAuthRequest(token);
|
||||||
|
|
||||||
modelsUtils = createModelsUtils({ rq: authRq });
|
modelsUtils = createModelsUtils({ rq: authRq });
|
||||||
|
|
||||||
await modelsUtils.createComponent({
|
await modelsUtils.createComponent({
|
||||||
name: 'single-image',
|
name: 'single-media',
|
||||||
attributes: {
|
attributes: {
|
||||||
image: {
|
media: {
|
||||||
type: 'media',
|
type: 'media',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
await modelsUtils.createComponent({
|
await modelsUtils.createComponent({
|
||||||
name: 'multiple-image',
|
name: 'multiple-media',
|
||||||
attributes: {
|
attributes: {
|
||||||
image: {
|
media: {
|
||||||
type: 'media',
|
type: 'media',
|
||||||
multiple: true,
|
multiple: true,
|
||||||
},
|
},
|
||||||
@ -40,13 +50,13 @@ describe.each([
|
|||||||
await modelsUtils.createComponent({
|
await modelsUtils.createComponent({
|
||||||
name: 'with-nested',
|
name: 'with-nested',
|
||||||
attributes: {
|
attributes: {
|
||||||
singleImage: {
|
singleMedia: {
|
||||||
type: 'component',
|
type: 'component',
|
||||||
component: 'default.single-image',
|
component: 'default.single-media',
|
||||||
},
|
},
|
||||||
multipleImage: {
|
multipleMedia: {
|
||||||
type: 'component',
|
type: 'component',
|
||||||
component: 'default.multiple-image',
|
component: 'default.multiple-media',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -56,8 +66,8 @@ describe.each([
|
|||||||
'dynamiczone',
|
'dynamiczone',
|
||||||
{
|
{
|
||||||
components: [
|
components: [
|
||||||
'default.single-image',
|
'default.single-media',
|
||||||
'default.multiple-image',
|
'default.multiple-media',
|
||||||
'default.with-nested',
|
'default.with-nested',
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
@ -70,24 +80,222 @@ describe.each([
|
|||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
await modelsUtils.deleteComponent('default.with-nested');
|
await modelsUtils.deleteComponent('default.with-nested');
|
||||||
await modelsUtils.deleteComponent('default.single-image');
|
await modelsUtils.deleteComponent('default.single-media');
|
||||||
await modelsUtils.deleteComponent('default.multiple-image');
|
await modelsUtils.deleteComponent('default.multiple-media');
|
||||||
await modelsUtils.deleteContentType('withdynamiczone');
|
await modelsUtils.deleteContentType('withdynamiczone');
|
||||||
}, 60000);
|
}, 60000);
|
||||||
|
|
||||||
describe('Contains components with medias', () => {
|
describe('Contains components with medias', () => {
|
||||||
test.todo('The medias are correctly related to the components on creation');
|
test('The medias are correctly related to the components on creation', async () => {
|
||||||
test.todo('The medias are correctly related to the components on edition');
|
const imgRes = await uploadImg();
|
||||||
test.todo('The media are populated on the components');
|
|
||||||
|
expect(imgRes.statusCode).toBe(200);
|
||||||
|
const mediaId = imgRes.body[0].id;
|
||||||
|
|
||||||
|
const res = await rq.post('/', {
|
||||||
|
body: {
|
||||||
|
field: [
|
||||||
|
{
|
||||||
|
__component: 'default.single-media',
|
||||||
|
media: mediaId,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
__component: 'default.multiple-media',
|
||||||
|
media: [mediaId, mediaId],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(res.statusCode).toBe(200);
|
||||||
|
expect(Array.isArray(res.body.field)).toBe(true);
|
||||||
|
expect(res.body).toMatchObject({
|
||||||
|
field: [
|
||||||
|
{
|
||||||
|
id: expect.anything(),
|
||||||
|
__component: 'default.single-media',
|
||||||
|
media: {
|
||||||
|
id: mediaId,
|
||||||
|
url: expect.any(String),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: expect.anything(),
|
||||||
|
__component: 'default.multiple-media',
|
||||||
|
media: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: mediaId,
|
||||||
|
url: expect.any(String),
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('The medias are correctly related to the components on edition', async () => {
|
||||||
|
const imgRes = await uploadImg();
|
||||||
|
|
||||||
|
expect(imgRes.statusCode).toBe(200);
|
||||||
|
const mediaId = imgRes.body[0].id;
|
||||||
|
|
||||||
|
const res = await rq.post('/', {
|
||||||
|
body: {
|
||||||
|
field: [
|
||||||
|
{
|
||||||
|
__component: 'default.single-media',
|
||||||
|
media: mediaId,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
__component: 'default.multiple-media',
|
||||||
|
media: [mediaId, mediaId],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(res.statusCode).toBe(200);
|
||||||
|
expect(Array.isArray(res.body.field)).toBe(true);
|
||||||
|
|
||||||
|
const newImgRes = await uploadImg();
|
||||||
|
|
||||||
|
expect(newImgRes.statusCode).toBe(200);
|
||||||
|
const newMediaId = newImgRes.body[0].id;
|
||||||
|
const updateRes = await rq.put(`/${res.body.id}`, {
|
||||||
|
body: {
|
||||||
|
field: [
|
||||||
|
{
|
||||||
|
__component: 'default.single-media',
|
||||||
|
media: newMediaId,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
__component: 'default.multiple-media',
|
||||||
|
media: [newMediaId, newMediaId],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(updateRes.body).toMatchObject({
|
||||||
|
field: [
|
||||||
|
{
|
||||||
|
id: expect.anything(),
|
||||||
|
__component: 'default.single-media',
|
||||||
|
media: {
|
||||||
|
id: newMediaId,
|
||||||
|
url: expect.any(String),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: expect.anything(),
|
||||||
|
__component: 'default.multiple-media',
|
||||||
|
media: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: newMediaId,
|
||||||
|
url: expect.any(String),
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('The media are populated on the components', async () => {
|
||||||
|
const imgRes = await uploadImg();
|
||||||
|
|
||||||
|
expect(imgRes.statusCode).toBe(200);
|
||||||
|
const mediaId = imgRes.body[0].id;
|
||||||
|
|
||||||
|
const res = await rq.post('/', {
|
||||||
|
body: {
|
||||||
|
field: [
|
||||||
|
{
|
||||||
|
__component: 'default.single-media',
|
||||||
|
media: mediaId,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
__component: 'default.multiple-media',
|
||||||
|
media: [mediaId, mediaId],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(res.statusCode).toBe(200);
|
||||||
|
|
||||||
|
const getRes = await rq.get(`/${res.body.id}`);
|
||||||
|
expect(getRes.body).toMatchObject({
|
||||||
|
field: [
|
||||||
|
{
|
||||||
|
id: expect.anything(),
|
||||||
|
__component: 'default.single-media',
|
||||||
|
media: {
|
||||||
|
id: mediaId,
|
||||||
|
url: expect.any(String),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: expect.anything(),
|
||||||
|
__component: 'default.multiple-media',
|
||||||
|
media: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: mediaId,
|
||||||
|
url: expect.any(String),
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Contains components with nested components having medias', () => {
|
describe('Contains components with nested components having medias', () => {
|
||||||
test.todo(
|
test('The medias are correctly related to the nested components on creation', async () => {
|
||||||
'The medias are correctly related to the nested components on creation'
|
const imgRes = await uploadImg();
|
||||||
);
|
|
||||||
test.todo(
|
expect(imgRes.statusCode).toBe(200);
|
||||||
'The medias are correctly related to the nested components on edition'
|
const mediaId = imgRes.body[0].id;
|
||||||
);
|
|
||||||
test.todo('The media are populated in nested components');
|
const res = await rq.post('/', {
|
||||||
|
body: {
|
||||||
|
field: [
|
||||||
|
{
|
||||||
|
__component: 'default.with-nested',
|
||||||
|
singleMedia: {
|
||||||
|
media: mediaId,
|
||||||
|
},
|
||||||
|
multipleMedia: {
|
||||||
|
media: [mediaId, mediaId],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(res.statusCode).toBe(200);
|
||||||
|
expect(Array.isArray(res.body.field)).toBe(true);
|
||||||
|
expect(res.body).toMatchObject({
|
||||||
|
field: [
|
||||||
|
{
|
||||||
|
id: expect.anything(),
|
||||||
|
__component: 'default.with-nested',
|
||||||
|
singleMedia: {
|
||||||
|
media: {
|
||||||
|
id: mediaId,
|
||||||
|
url: expect.any(String),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
multipleMedia: {
|
||||||
|
media: expect.arrayContaining([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: mediaId,
|
||||||
|
url: expect.any(String),
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,100 +0,0 @@
|
|||||||
const { registerAndLogin } = require('../../../../test/helpers/auth');
|
|
||||||
const createModelsUtils = require('../../../../test/helpers/models');
|
|
||||||
const { createAuthRequest } = require('../../../../test/helpers/request');
|
|
||||||
|
|
||||||
let modelsUtils;
|
|
||||||
let rq;
|
|
||||||
|
|
||||||
describe.each([
|
|
||||||
[
|
|
||||||
'CONTENT MANAGER',
|
|
||||||
'/content-manager/explorer/application::withdynamiczone.withdynamiczone',
|
|
||||||
],
|
|
||||||
['GENERATED API', '/withdynamiczones'],
|
|
||||||
])('[%s] => Not required dynamiczone', (_, path) => {
|
|
||||||
beforeAll(async () => {
|
|
||||||
const token = await registerAndLogin();
|
|
||||||
const authRq = createAuthRequest(token);
|
|
||||||
|
|
||||||
modelsUtils = createModelsUtils({ rq: authRq });
|
|
||||||
|
|
||||||
await modelsUtils.createContentType({
|
|
||||||
name: 'related-to',
|
|
||||||
attributes: {
|
|
||||||
image: {
|
|
||||||
type: 'media',
|
|
||||||
},
|
|
||||||
images: {
|
|
||||||
type: 'media',
|
|
||||||
multiple: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
await modelsUtils.createComponent({
|
|
||||||
name: 'with-one-way',
|
|
||||||
attributes: {
|
|
||||||
relation: {
|
|
||||||
nature: 'oneWay',
|
|
||||||
target: 'application::related-to.related-to',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
await modelsUtils.createComponent({
|
|
||||||
name: 'with-many-way',
|
|
||||||
attributes: {
|
|
||||||
relation: {
|
|
||||||
nature: 'manyWay',
|
|
||||||
target: 'application::related-to.related-to',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
await modelsUtils.createComponent({
|
|
||||||
name: 'with-nested',
|
|
||||||
attributes: {
|
|
||||||
oneWay: {
|
|
||||||
type: 'component',
|
|
||||||
component: 'default.with-one-way',
|
|
||||||
},
|
|
||||||
manyWay: {
|
|
||||||
type: 'component',
|
|
||||||
component: 'default.with-many-way',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
await modelsUtils.createContentTypeWithType(
|
|
||||||
'withdynamiczone',
|
|
||||||
'dynamiczone',
|
|
||||||
{
|
|
||||||
components: [
|
|
||||||
'default.with-one-way',
|
|
||||||
'default.with-many-way',
|
|
||||||
'default.with-nested',
|
|
||||||
],
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
rq = authRq.defaults({
|
|
||||||
baseUrl: `http://localhost:1337${path}`,
|
|
||||||
});
|
|
||||||
}, 60000);
|
|
||||||
|
|
||||||
afterAll(async () => {
|
|
||||||
await modelsUtils.deleteComponent('default.with-nested');
|
|
||||||
await modelsUtils.deleteComponent('default.with-one-way');
|
|
||||||
await modelsUtils.deleteComponent('default.with-many-way');
|
|
||||||
await modelsUtils.deleteContentType('related-to');
|
|
||||||
await modelsUtils.deleteContentType('withdynamiczone');
|
|
||||||
}, 60000);
|
|
||||||
|
|
||||||
describe('Contains components with relations having medias', () => {
|
|
||||||
test.todo('The media are correctly populated in relations');
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Contains components with nested components having relations with medias', () => {
|
|
||||||
test.todo('The media are populated in nested components relations');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@ -1,100 +0,0 @@
|
|||||||
const { registerAndLogin } = require('../../../../test/helpers/auth');
|
|
||||||
const createModelsUtils = require('../../../../test/helpers/models');
|
|
||||||
const { createAuthRequest } = require('../../../../test/helpers/request');
|
|
||||||
|
|
||||||
let modelsUtils;
|
|
||||||
let rq;
|
|
||||||
|
|
||||||
describe.each([
|
|
||||||
[
|
|
||||||
'CONTENT MANAGER',
|
|
||||||
'/content-manager/explorer/application::withdynamiczone.withdynamiczone',
|
|
||||||
],
|
|
||||||
['GENERATED API', '/withdynamiczones'],
|
|
||||||
])('[%s] => Not required dynamiczone', (_, path) => {
|
|
||||||
beforeAll(async () => {
|
|
||||||
const token = await registerAndLogin();
|
|
||||||
const authRq = createAuthRequest(token);
|
|
||||||
|
|
||||||
modelsUtils = createModelsUtils({ rq: authRq });
|
|
||||||
|
|
||||||
await modelsUtils.createContentType({
|
|
||||||
name: 'related-to',
|
|
||||||
attributes: {},
|
|
||||||
});
|
|
||||||
|
|
||||||
await modelsUtils.createComponent({
|
|
||||||
name: 'with-one-way',
|
|
||||||
attributes: {
|
|
||||||
relation: {
|
|
||||||
nature: 'oneWay',
|
|
||||||
target: 'application::related-to.related-to',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
await modelsUtils.createComponent({
|
|
||||||
name: 'with-many-way',
|
|
||||||
attributes: {
|
|
||||||
relation: {
|
|
||||||
nature: 'manyWay',
|
|
||||||
target: 'application::related-to.related-to',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
await modelsUtils.createComponent({
|
|
||||||
name: 'with-nested',
|
|
||||||
attributes: {
|
|
||||||
oneWay: {
|
|
||||||
type: 'component',
|
|
||||||
component: 'default.with-one-way',
|
|
||||||
},
|
|
||||||
manyWay: {
|
|
||||||
type: 'component',
|
|
||||||
component: 'default.with-many-way',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
await modelsUtils.createContentTypeWithType(
|
|
||||||
'withdynamiczone',
|
|
||||||
'dynamiczone',
|
|
||||||
{
|
|
||||||
components: [
|
|
||||||
'default.with-one-way',
|
|
||||||
'default.with-many-way',
|
|
||||||
'default.with-nested',
|
|
||||||
],
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
rq = authRq.defaults({
|
|
||||||
baseUrl: `http://localhost:1337${path}`,
|
|
||||||
});
|
|
||||||
}, 60000);
|
|
||||||
|
|
||||||
afterAll(async () => {
|
|
||||||
await modelsUtils.deleteComponent('default.with-nested');
|
|
||||||
await modelsUtils.deleteComponent('default.with-one-way');
|
|
||||||
await modelsUtils.deleteComponent('default.with-many-way');
|
|
||||||
await modelsUtils.deleteContentType('related-to');
|
|
||||||
await modelsUtils.deleteContentType('withdynamiczone');
|
|
||||||
}, 60000);
|
|
||||||
|
|
||||||
describe('Contains components with relations', () => {
|
|
||||||
test.todo('The relations are correctly set on the components on creation');
|
|
||||||
test.todo('The relations are correctly set on the components on edition');
|
|
||||||
test.todo('The relatons are populated on the components');
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Contains components with nested components having relations', () => {
|
|
||||||
test.todo(
|
|
||||||
'The relations are correctly set on the nested components on creation'
|
|
||||||
);
|
|
||||||
test.todo(
|
|
||||||
'The relations are correctly set on the nested components on edition'
|
|
||||||
);
|
|
||||||
test.todo('The relatons are populated on nested components');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
Loading…
x
Reference in New Issue
Block a user