strapi/api-tests/plugins/i18n/content-manager/find-existing-relations.test.api.js
Marc Roig ff8ed1fc36
feat: Draft & Publish V5 (#18941)
* feat: use document service in content manager
* feat: locale and status filtering
* feat: refactor single type controllers to use documents
* feat: get locale param from in cm endpoints
* feat: get locale param from cm endpoints
* feat: prevent empty string locale filtering
* fix(content-manager): access to non default locale documents
* chore(content-manager): revert route construction
* test(content-manager): counting number of draft relations for non default locales
* chore(content-manager): remove default locale from entity manager countDraftRelations


---------

Co-authored-by: Ben Irvin <ben@innerdvations.com>
Co-authored-by: Jamie Howard <48524071+jhoward1994@users.noreply.github.com>
Co-authored-by: Josh <37798644+joshuaellis@users.noreply.github.com>
2024-01-25 18:43:08 +01:00

137 lines
2.8 KiB
JavaScript

'use strict';
const { pick } = require('lodash/fp');
const { createTestBuilder } = require('api-tests/builder');
const { createStrapiInstance } = require('api-tests/strapi');
const { createAuthRequest } = require('api-tests/request');
let strapi;
let rq;
const data = {
products: [],
shops: [],
};
const productModel = {
pluginOptions: {
i18n: {
localized: true,
},
},
attributes: {
name: {
type: 'string',
},
},
displayName: 'Product',
singularName: 'product',
pluralName: 'products',
description: '',
collectionName: '',
};
const shopModel = {
pluginOptions: {
i18n: {
localized: true,
},
},
attributes: {
name: {
type: 'string',
},
products: {
type: 'relation',
relation: 'manyToMany',
target: 'api::product.product',
targetAttribute: 'shops',
},
},
displayName: 'Shop',
singularName: 'shop',
pluralName: 'shops',
};
const shops = [
{
name: 'mercato',
locale: 'it',
},
{
name: 'market',
locale: 'en',
},
];
const products = ({ shop: shops }) => {
const entries = [
{
name: 'pomodoro',
shops: [shops[0].id],
locale: 'it',
},
{
name: 'apple',
shops: [shops[1].id],
locale: 'en',
},
];
return entries;
};
// TODO: V5 - Fix relations
describe.skip('i18n - Find existing relations', () => {
const builder = createTestBuilder();
beforeAll(async () => {
await builder
.addContentTypes([productModel, shopModel])
.addFixtures('plugin::i18n.locale', [
{
name: 'It',
code: 'it',
},
])
.addFixtures(shopModel.singularName, shops)
.addFixtures(productModel.singularName, products)
.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('Get Italian product for italian shop filter on any locale', async () => {
const res = await rq({
method: 'GET',
url: `/content-manager/relations/api::shop.shop/${data.shops[0].id}/products`,
});
expect(res.body.results).toHaveLength(1);
expect(res.body.results[0]).toStrictEqual(
pick(['id', 'name', 'publishedAt'], data.products[0])
);
});
test('Get english product for english shop', async () => {
const res = await rq({
method: 'GET',
url: `/content-manager/relations/api::shop.shop/${data.shops[1].id}/products`,
});
expect(res.body.results).toHaveLength(1);
expect(res.body.results[0]).toStrictEqual(
pick(['id', 'name', 'publishedAt'], data.products[1])
);
});
});