| 
									
										
										
										
											2022-06-16 19:37:18 +01:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const fs = require('fs'); | 
					
						
							|  |  |  | const path = require('path'); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-05 10:32:20 +02:00
										 |  |  | const { createTestBuilder } = require('api-tests/builder'); | 
					
						
							|  |  |  | const { createStrapiInstance } = require('api-tests/strapi'); | 
					
						
							|  |  |  | const { createAuthRequest } = require('api-tests/request'); | 
					
						
							| 
									
										
										
										
											2022-06-16 19:37:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | const builder = createTestBuilder(); | 
					
						
							|  |  |  | let strapi; | 
					
						
							|  |  |  | let rq; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe('Dimensions are populated when uploading an image', () => { | 
					
						
							|  |  |  |   beforeAll(async () => { | 
					
						
							|  |  |  |     strapi = await createStrapiInstance(); | 
					
						
							|  |  |  |     rq = await createAuthRequest({ strapi }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   afterAll(async () => { | 
					
						
							|  |  |  |     await strapi.destroy(); | 
					
						
							|  |  |  |     await builder.cleanup(); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   test.each([['.jpg'], ['.png'], ['.webp'], ['.tiff'], ['.svg'], ['.gif']])( | 
					
						
							|  |  |  |     'Dimensions are populated for %s', | 
					
						
							| 
									
										
										
										
											2022-08-08 23:33:39 +02:00
										 |  |  |     async (ext) => { | 
					
						
							| 
									
										
										
										
											2022-06-16 19:37:18 +01:00
										 |  |  |       const res = await rq({ | 
					
						
							|  |  |  |         method: 'POST', | 
					
						
							|  |  |  |         url: '/upload', | 
					
						
							|  |  |  |         formData: { files: fs.createReadStream(path.join(__dirname, `../utils/strapi${ext}`)) }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(res.statusCode).toBe(200); | 
					
						
							|  |  |  |       expect(res.body[0]).toMatchObject({ | 
					
						
							|  |  |  |         width: 256, | 
					
						
							|  |  |  |         height: 256, | 
					
						
							|  |  |  |         ext, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | }); |