mirror of
https://github.com/strapi/strapi.git
synced 2025-10-30 01:17:28 +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 createModelsUtils = require('../../../../test/helpers/models');
|
||||
const { createAuthRequest } = require('../../../../test/helpers/request');
|
||||
|
||||
let modelsUtils;
|
||||
let rq;
|
||||
let authRq;
|
||||
const uploadImg = () => {
|
||||
return authRq.post('/upload', {
|
||||
formData: {
|
||||
files: fs.createReadStream(__dirname + '/rec.jpg'),
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
describe.each([
|
||||
[
|
||||
'CONTENT MANAGER',
|
||||
'/content-manager/explorer/application::withdynamiczone.withdynamiczone',
|
||||
],
|
||||
['GENERATED API', '/withdynamiczones'],
|
||||
// ['GENERATED API', '/withdynamiczones'],
|
||||
])('[%s] => Not required dynamiczone', (_, path) => {
|
||||
beforeAll(async () => {
|
||||
const token = await registerAndLogin();
|
||||
const authRq = createAuthRequest(token);
|
||||
authRq = createAuthRequest(token);
|
||||
|
||||
modelsUtils = createModelsUtils({ rq: authRq });
|
||||
|
||||
await modelsUtils.createComponent({
|
||||
name: 'single-image',
|
||||
name: 'single-media',
|
||||
attributes: {
|
||||
image: {
|
||||
media: {
|
||||
type: 'media',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
await modelsUtils.createComponent({
|
||||
name: 'multiple-image',
|
||||
name: 'multiple-media',
|
||||
attributes: {
|
||||
image: {
|
||||
media: {
|
||||
type: 'media',
|
||||
multiple: true,
|
||||
},
|
||||
@ -40,13 +50,13 @@ describe.each([
|
||||
await modelsUtils.createComponent({
|
||||
name: 'with-nested',
|
||||
attributes: {
|
||||
singleImage: {
|
||||
singleMedia: {
|
||||
type: 'component',
|
||||
component: 'default.single-image',
|
||||
component: 'default.single-media',
|
||||
},
|
||||
multipleImage: {
|
||||
multipleMedia: {
|
||||
type: 'component',
|
||||
component: 'default.multiple-image',
|
||||
component: 'default.multiple-media',
|
||||
},
|
||||
},
|
||||
});
|
||||
@ -56,8 +66,8 @@ describe.each([
|
||||
'dynamiczone',
|
||||
{
|
||||
components: [
|
||||
'default.single-image',
|
||||
'default.multiple-image',
|
||||
'default.single-media',
|
||||
'default.multiple-media',
|
||||
'default.with-nested',
|
||||
],
|
||||
}
|
||||
@ -70,24 +80,222 @@ describe.each([
|
||||
|
||||
afterAll(async () => {
|
||||
await modelsUtils.deleteComponent('default.with-nested');
|
||||
await modelsUtils.deleteComponent('default.single-image');
|
||||
await modelsUtils.deleteComponent('default.multiple-image');
|
||||
await modelsUtils.deleteComponent('default.single-media');
|
||||
await modelsUtils.deleteComponent('default.multiple-media');
|
||||
await modelsUtils.deleteContentType('withdynamiczone');
|
||||
}, 60000);
|
||||
|
||||
describe('Contains components with medias', () => {
|
||||
test.todo('The medias are correctly related to the components on creation');
|
||||
test.todo('The medias are correctly related to the components on edition');
|
||||
test.todo('The media are populated on the components');
|
||||
test('The medias are correctly related to the components on creation', 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);
|
||||
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', () => {
|
||||
test.todo(
|
||||
'The medias are correctly related to the nested components on creation'
|
||||
);
|
||||
test.todo(
|
||||
'The medias are correctly related to the nested components on edition'
|
||||
);
|
||||
test.todo('The media are populated in nested components');
|
||||
test('The medias are correctly related to the nested components on creation', 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.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