mirror of
https://github.com/strapi/strapi.git
synced 2025-07-19 15:06:11 +00:00

* feat(content-manager): Rework findAvailable and findExisting (#19597) * feat(content-manager): wip rework findAvailable and findExisting * chore(strapi): simplify relations controller * feat(content-manager): entity Id based find available * feat(content-manager): entity Id based find existing * fix(content-manager): build issues * chore(content-manager): cleanup * fix(content-manager): relations controllers unit tests * fix(content-manager): improve error handling * fix(content-manager): simplify findExisting relations logic * fix(content-manager): clean up types * fix(content-manager): extend available relation API tests * fix(content-manager): pr feedback * feat(content-manager): cover find existing test cases * feat(content-manager): test that we can only find available relations in the same locale * fix: wip fix unit tests * chore(content-manager): pr feedback * fix(content-manager): use db layer to find relations fix(content-manager): failing relations tests * fix(content-manager): find relations test * fix(content-manager): build issues * fix(content-manager): return latest status of relations in findAvailable (#19681) * fix(content-manager): return latest status of relations in findAvailable * fix(content-manager): share logic for findAvailable and findExisting * fix(admin): relation tests * fix(content-manager): clean up types * fix(content-manager): support status for find exisiting * fix(content-manager): add status and locale filters to subQuery * fix(content-manager): ts front and skip relations unit tests * fix(content-manager): request specific status or get latest using document-metadata * chore(content-manager): use interface * fix(content-manager): tidy up target relation subquery * fix(content-manager): tidy up and skip TS for build issues * fix(content-manager): return status when requested * chore(content-manager): dont re type entity service response * fix(content-manager): use document metadata getManyAvailableStatus * chore(content-manager): remove mapAsync * feat: implement relations in the cm (#19702) * Fix: Relating i18n and non-i18n content types (#19731) * chore: re-enable e2e relation tests * fix: return undefined --------- Co-authored-by: Jamie Howard <48524071+jhoward1994@users.noreply.github.com> Co-authored-by: Jamie Howard <jamie.howard@strapi.io> Co-authored-by: Marc-Roig <marc12info@gmail.com>
165 lines
3.5 KiB
JavaScript
165 lines
3.5 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;
|
|
};
|
|
|
|
describe('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 () => {
|
|
// Delete all locales that have been created
|
|
await strapi.db.query('plugin::i18n.locale').deleteMany({ code: { $ne: 'en' } });
|
|
|
|
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].documentId}/products`,
|
|
qs: {
|
|
locale: 'it',
|
|
status: 'published',
|
|
},
|
|
});
|
|
|
|
const { id, documentId, name, publishedAt, updatedAt, locale } = data.products[0];
|
|
const expectedObj = {
|
|
documentId,
|
|
id,
|
|
name,
|
|
locale,
|
|
publishedAt,
|
|
updatedAt,
|
|
status: 'published',
|
|
};
|
|
|
|
expect(res.body.results).toHaveLength(1);
|
|
expect(res.body.results[0]).toStrictEqual(expectedObj);
|
|
});
|
|
|
|
test('Get english product for english shop', async () => {
|
|
const res = await rq({
|
|
method: 'GET',
|
|
url: `/content-manager/relations/api::shop.shop/${data.shops[1].documentId}/products`,
|
|
qs: {
|
|
locale: 'en',
|
|
status: 'published',
|
|
},
|
|
});
|
|
|
|
const { id, documentId, name, publishedAt, updatedAt, locale } = data.products[1];
|
|
const expectedObj = {
|
|
documentId,
|
|
id,
|
|
name,
|
|
locale,
|
|
publishedAt,
|
|
updatedAt,
|
|
status: 'published',
|
|
};
|
|
|
|
expect(res.body.results).toHaveLength(1);
|
|
expect(res.body.results[0]).toStrictEqual(expectedObj);
|
|
});
|
|
});
|