From d75d46b044d6ef3ff322626f213b4ed04db43f42 Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Fri, 13 Dec 2019 11:14:40 +0100 Subject: [PATCH] Add with media tests --- .../test/dynamiczones/rec.jpg | Bin 0 -> 787 bytes .../test/dynamiczones/with-media.test.e2e.js | 256 ++++++++++++++++-- .../with-relation-with-media.test.e2e.js | 100 ------- .../dynamiczones/with-relation.test.e2e.js | 100 ------- 4 files changed, 232 insertions(+), 224 deletions(-) create mode 100644 packages/strapi-plugin-content-manager/test/dynamiczones/rec.jpg delete mode 100644 packages/strapi-plugin-content-manager/test/dynamiczones/with-relation-with-media.test.e2e.js delete mode 100644 packages/strapi-plugin-content-manager/test/dynamiczones/with-relation.test.e2e.js diff --git a/packages/strapi-plugin-content-manager/test/dynamiczones/rec.jpg b/packages/strapi-plugin-content-manager/test/dynamiczones/rec.jpg new file mode 100644 index 0000000000000000000000000000000000000000..e402224d6d04ed5bee05c9af55d754c490037d65 GIT binary patch literal 787 zcmex=LK$;OGwtxvPE3$wY!3HV(|CYfbAS1sdzc?emK*3ngfWgAa)0YKg8W4cl zs$izT71^Gf{S2E}UN&&fc=N-l?*9P>K@J8H1`%dPB?cxzMrJ|A|3?_)fp)Sof&o|? zkYHqDW?^Mx=iubx1}fMpz`(@F%*@2X%*qO~hOrhX&%h$cDx_%W$R-?^$gWfnAuRebI{N?Mn?>~P20{IIVo)B*V zNr=zT{3QtV7ZVE$GYdP&UyMxUAdd^Ouqqm|2{{I`Cl(4T88vc8f2KE_o9%~}YXK;@p{B@hbnL!2&3}j>sTnr2hTw+{+Af_Y+1WI~J zz@P^TR)E0~5V!*e|AB@uDygVgm{=s3m?S)#(=g{5$>9H8V6tTTe~W>KnGu+nm<1W^ S8J@jZ)Wx6y#Q!fKm^T3@zAuIV literal 0 HcmV?d00001 diff --git a/packages/strapi-plugin-content-manager/test/dynamiczones/with-media.test.e2e.js b/packages/strapi-plugin-content-manager/test/dynamiczones/with-media.test.e2e.js index 7ff4ba3193..b236b49133 100644 --- a/packages/strapi-plugin-content-manager/test/dynamiczones/with-media.test.e2e.js +++ b/packages/strapi-plugin-content-manager/test/dynamiczones/with-media.test.e2e.js @@ -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), + }), + ]), + }, + }, + ], + }); + }); }); }); diff --git a/packages/strapi-plugin-content-manager/test/dynamiczones/with-relation-with-media.test.e2e.js b/packages/strapi-plugin-content-manager/test/dynamiczones/with-relation-with-media.test.e2e.js deleted file mode 100644 index 1ce47a0e81..0000000000 --- a/packages/strapi-plugin-content-manager/test/dynamiczones/with-relation-with-media.test.e2e.js +++ /dev/null @@ -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'); - }); -}); diff --git a/packages/strapi-plugin-content-manager/test/dynamiczones/with-relation.test.e2e.js b/packages/strapi-plugin-content-manager/test/dynamiczones/with-relation.test.e2e.js deleted file mode 100644 index a7b22b4619..0000000000 --- a/packages/strapi-plugin-content-manager/test/dynamiczones/with-relation.test.e2e.js +++ /dev/null @@ -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'); - }); -});