From 13cbc3149767e0072c137364acfca086663b7662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20No=C3=ABl?= Date: Wed, 9 Nov 2022 19:35:56 +0100 Subject: [PATCH] remove tests relation-list.test.api.js & relations.test.api.js --- .../content-manager/relations.test.api.js | 75 ------- .../server/tests/relation-list.test.api.js | 196 ------------------ 2 files changed, 271 deletions(-) delete mode 100644 packages/core/content-manager/server/tests/content-manager/relations.test.api.js delete mode 100644 packages/core/content-manager/server/tests/relation-list.test.api.js diff --git a/packages/core/content-manager/server/tests/content-manager/relations.test.api.js b/packages/core/content-manager/server/tests/content-manager/relations.test.api.js deleted file mode 100644 index cc7dbadcde..0000000000 --- a/packages/core/content-manager/server/tests/content-manager/relations.test.api.js +++ /dev/null @@ -1,75 +0,0 @@ -'use strict'; - -// Helpers. -const { createTestBuilder } = require('../../../../../../test/helpers/builder'); -const { createStrapiInstance } = require('../../../../../../test/helpers/strapi'); -const form = require('../../../../../../test/helpers/generators'); -const { createAuthRequest } = require('../../../../../../test/helpers/request'); - -const builder = createTestBuilder(); -let strapi; -let rq; - -const restart = async () => { - await strapi.destroy(); - strapi = await createStrapiInstance(); - rq = await createAuthRequest({ strapi }); -}; - -describe('Content Manager - Hide relations', () => { - beforeAll(async () => { - await builder.addContentTypes([form.article]).build(); - - strapi = await createStrapiInstance(); - rq = await createAuthRequest({ strapi }); - }); - - afterAll(async () => { - await strapi.destroy(); - await builder.cleanup(); - }); - - test('Hide relations', async () => { - await rq({ - url: '/content-manager/content-types/api::article.article/configuration', - method: 'PUT', - body: { - layouts: { - edit: [], - editRelations: [], - list: [], - }, - }, - }); - - const { body } = await rq({ - url: '/content-manager/content-types/api::article.article/configuration', - method: 'GET', - }); - - expect(body.data.contentType.layouts.editRelations).toStrictEqual([]); - }); - - test('Hide relations after server restart', async () => { - await rq({ - url: '/content-manager/content-types/api::article.article/configuration', - method: 'PUT', - body: { - layouts: { - edit: [], - editRelations: [], - list: [], - }, - }, - }); - - await restart(); - - const { body } = await rq({ - url: '/content-manager/content-types/api::article.article/configuration', - method: 'GET', - }); - - expect(body.data.contentType.layouts.editRelations).toStrictEqual([]); - }); -}); diff --git a/packages/core/content-manager/server/tests/relation-list.test.api.js b/packages/core/content-manager/server/tests/relation-list.test.api.js deleted file mode 100644 index ef0e7c65af..0000000000 --- a/packages/core/content-manager/server/tests/relation-list.test.api.js +++ /dev/null @@ -1,196 +0,0 @@ -'use strict'; - -// Test a simple default API with no relations - -const { omit, pick } = require('lodash/fp'); - -const { createTestBuilder } = require('../../../../../test/helpers/builder'); -const { createStrapiInstance } = require('../../../../../test/helpers/strapi'); -const { createAuthRequest } = require('../../../../../test/helpers/request'); - -let strapi; -let rq; -const data = { - products: [], - shops: [], -}; - -const productModel = { - attributes: { - name: { - type: 'string', - }, - }, - displayName: 'Product', - singularName: 'product', - pluralName: 'products', - description: '', - collectionName: '', -}; - -const productWithDPModel = { - attributes: { - name: { - type: 'string', - }, - }, - displayName: 'Product', - singularName: 'product', - pluralName: 'products', - draftAndPublish: true, - description: '', - collectionName: '', -}; - -const shopModel = { - attributes: { - name: { - type: 'string', - }, - products: { - type: 'relation', - relation: 'manyToMany', - target: 'api::product.product', - targetAttribute: 'shops', - }, - }, - displayName: 'Shop', - singularName: 'shop', - pluralName: 'shops', -}; - -const shops = [ - { - name: 'market', - }, -]; - -const products = - ({ withPublished = false }) => - ({ shop }) => { - const shops = [shop[0].id]; - - const entries = [ - { - name: 'tomato', - shops, - publishedAt: new Date(), - }, - { - name: 'apple', - shops, - publishedAt: null, - }, - ]; - - if (withPublished) { - return entries; - } - - return entries.map(omit('publishedAt')); - }; - -describe('Relation-list route', () => { - describe('without draftAndPublish', () => { - const builder = createTestBuilder(); - - beforeAll(async () => { - await builder - .addContentTypes([productModel, shopModel]) - .addFixtures(shopModel.singularName, shops) - .addFixtures(productModel.singularName, products({ withPublished: false })) - .build(); - - strapi = await createStrapiInstance(); - rq = await createAuthRequest({ strapi }); - - data.shops = await builder.sanitizedFixturesFor(shopModel.singularName, strapi); - data.products = await builder.sanitizedFixturesFor(productModel.singularName, strapi); - }); - - afterAll(async () => { - await strapi.destroy(); - await builder.cleanup(); - }); - - test('Can get relation-list for products of a shop', async () => { - const res = await rq({ - method: 'POST', - url: '/content-manager/relations/api::shop.shop/products', - }); - - expect(res.body).toHaveLength(data.products.length); - data.products.forEach((product, index) => { - expect(res.body[index]).toStrictEqual(pick(['_id', 'id', 'name'], product)); - }); - }); - - test('Can get relation-list for products of a shop and omit some results', async () => { - const res = await rq({ - method: 'POST', - url: '/content-manager/relations/api::shop.shop/products', - body: { - idsToOmit: [data.products[0].id], - }, - }); - - expect(res.body).toHaveLength(1); - expect(res.body[0]).toStrictEqual(pick(['_id', 'id', 'name'], data.products[1])); - }); - }); - - describe('with draftAndPublish', () => { - const builder = createTestBuilder(); - - beforeAll(async () => { - await builder - .addContentTypes([productWithDPModel, shopModel]) - .addFixtures(shopModel.singularName, shops) - .addFixtures(productWithDPModel.singularName, products({ withPublished: true })) - .build(); - - strapi = await createStrapiInstance(); - rq = await createAuthRequest({ strapi }); - - data.shops = await builder.sanitizedFixturesFor(shopModel.singularName, strapi); - data.products = await builder.sanitizedFixturesFor(productWithDPModel.singularName, strapi); - }); - - afterAll(async () => { - await strapi.destroy(); - await builder.cleanup(); - }); - - test('Can get relation-list for products of a shop', async () => { - const res = await rq({ - method: 'POST', - url: '/content-manager/relations/api::shop.shop/products', - }); - - expect(res.body).toHaveLength(data.products.length); - - const tomatoProductRes = res.body.find((p) => p.name === 'tomato'); - const appleProductRes = res.body.find((p) => p.name === 'apple'); - - expect(tomatoProductRes).toMatchObject(pick(['_id', 'id', 'name'], data.products[0])); - expect(tomatoProductRes.publishedAt).toBeISODate(); - expect(appleProductRes).toStrictEqual({ - ...pick(['_id', 'id', 'name'], data.products[1]), - publishedAt: null, - }); - }); - - test('Can get relation-list for products of a shop and omit some results', async () => { - const res = await rq({ - method: 'POST', - url: '/content-manager/relations/api::shop.shop/products', - body: { - idsToOmit: [data.products[1].id], - }, - }); - - expect(res.body).toHaveLength(1); - expect(res.body[0]).toMatchObject(pick(['_id', 'id', 'name'], data.products[0])); - }); - }); -});