mirror of
https://github.com/strapi/strapi.git
synced 2025-10-27 16:10:08 +00:00
Suport media format
This commit is contained in:
parent
68826f7ae0
commit
5a9371b5c3
@ -119,4 +119,108 @@ describe('Transforms', () => {
|
||||
meta: {},
|
||||
});
|
||||
});
|
||||
|
||||
test('Handles relations recursively', () => {
|
||||
const contentType = {
|
||||
attributes: {
|
||||
relation: {
|
||||
type: 'relation',
|
||||
target: 'xxx',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
global.strapi = {
|
||||
contentType() {
|
||||
return {
|
||||
attributes: {
|
||||
nestedRelation: {
|
||||
type: 'relation',
|
||||
target: 'xxxx',
|
||||
},
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
expect(
|
||||
transforms.transformResponse(
|
||||
{
|
||||
id: 1,
|
||||
title: 'Hello',
|
||||
relation: [{ id: 1, value: 'test', nestedRelation: { id: 2, foo: 'bar' } }],
|
||||
},
|
||||
undefined,
|
||||
{ contentType }
|
||||
)
|
||||
).toStrictEqual({
|
||||
data: {
|
||||
id: 1,
|
||||
attributes: {
|
||||
title: 'Hello',
|
||||
relation: {
|
||||
data: [
|
||||
{
|
||||
id: 1,
|
||||
attributes: {
|
||||
value: 'test',
|
||||
nestedRelation: {
|
||||
data: {
|
||||
id: 2,
|
||||
attributes: {
|
||||
foo: 'bar',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
meta: {},
|
||||
});
|
||||
});
|
||||
|
||||
test('Handles media like relations', () => {
|
||||
const contentType = {
|
||||
attributes: {
|
||||
media: {
|
||||
type: 'media',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
global.strapi = {
|
||||
contentType() {
|
||||
return undefined;
|
||||
},
|
||||
};
|
||||
|
||||
expect(
|
||||
transforms.transformResponse(
|
||||
{ id: 1, title: 'Hello', media: [{ id: 1, value: 'test' }] },
|
||||
undefined,
|
||||
{ contentType }
|
||||
)
|
||||
).toStrictEqual({
|
||||
data: {
|
||||
id: 1,
|
||||
attributes: {
|
||||
title: 'Hello',
|
||||
media: {
|
||||
data: [
|
||||
{
|
||||
id: 1,
|
||||
attributes: {
|
||||
value: 'test',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
meta: {},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -37,6 +37,10 @@ const transformEntry = (entry, contentType) => {
|
||||
if (attribute && attribute.type === 'relation') {
|
||||
const data = transformEntry(property, strapi.contentType(attribute.target));
|
||||
|
||||
attributeValues[key] = { data };
|
||||
} else if (attribute && attribute.type === 'media') {
|
||||
const data = transformEntry(property, strapi.contentType('plugin::upload.file'));
|
||||
|
||||
attributeValues[key] = { data };
|
||||
} else {
|
||||
attributeValues[key] = property;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user