mirror of
				https://github.com/strapi/strapi.git
				synced 2025-10-31 09:56:44 +00:00 
			
		
		
		
	Suport media format
This commit is contained in:
		
							parent
							
								
									68826f7ae0
								
							
						
					
					
						commit
						5a9371b5c3
					
				| @ -119,4 +119,108 @@ describe('Transforms', () => { | |||||||
|       meta: {}, |       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') { |     if (attribute && attribute.type === 'relation') { | ||||||
|       const data = transformEntry(property, strapi.contentType(attribute.target)); |       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 }; |       attributeValues[key] = { data }; | ||||||
|     } else { |     } else { | ||||||
|       attributeValues[key] = property; |       attributeValues[key] = property; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Alexandre Bodin
						Alexandre Bodin