mirror of
				https://github.com/strapi/strapi.git
				synced 2025-10-31 09:56:44 +00:00 
			
		
		
		
	refacto
This commit is contained in:
		
							parent
							
								
									3c85f38fb4
								
							
						
					
					
						commit
						30f45b9b40
					
				| @ -17,11 +17,11 @@ const create = locale => strapi.query('locale', 'i18n').create(locale); | |||||||
| const update = (params, updates) => strapi.query('locale', 'i18n').update(params, updates); | const update = (params, updates) => strapi.query('locale', 'i18n').update(params, updates); | ||||||
| 
 | 
 | ||||||
| const deleteFn = async ({ id }) => { | const deleteFn = async ({ id }) => { | ||||||
|   let localeToDelete = await strapi.query('locale', 'i18n').findOne({ id }); |   const localeToDelete = await strapi.query('locale', 'i18n').findOne({ id }); | ||||||
| 
 | 
 | ||||||
|   if (localeToDelete) { |   if (localeToDelete) { | ||||||
|     await deleteAllLocalizedEntriesFor({ locale: localeToDelete.code }); |     await deleteAllLocalizedEntriesFor({ locale: localeToDelete.code }); | ||||||
|     localeToDelete = await strapi.query('locale', 'i18n').delete({ id }); |     return strapi.query('locale', 'i18n').delete({ id }); | ||||||
|   } |   } | ||||||
|   return localeToDelete; |   return localeToDelete; | ||||||
| }; | }; | ||||||
|  | |||||||
| @ -328,11 +328,23 @@ describe('CRUD locales', () => { | |||||||
|       expect(res.body.message).toBe('Cannot delete the default locale'); |       expect(res.body.message).toBe('Cannot delete the default locale'); | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     test('Can delete a locale', async () => { |     test('Can delete a locale - simple', async () => { | ||||||
|  |       const res = await rq({ | ||||||
|  |         url: `/i18n/locales/${data.locales[1].id}`, | ||||||
|  |         method: 'DELETE', | ||||||
|  |       }); | ||||||
|  | 
 | ||||||
|  |       expect(res.statusCode).toBe(200); | ||||||
|  |       expect(res.body).toMatchObject(omitTimestamps(data.locales[1])); | ||||||
|  |       data.deletedLocales.push(res.body); | ||||||
|  |       data.locales.splice(1, 1); | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     test('Can delete a locale - with related entities', async () => { | ||||||
|       const { body: frenchProduct } = await rq({ |       const { body: frenchProduct } = await rq({ | ||||||
|         url: '/content-manager/collection-types/application::product.product', |         url: '/content-manager/collection-types/application::product.product', | ||||||
|         method: 'POST', |         method: 'POST', | ||||||
|         qs: { plugins: { i18n: { locale: 'fr' } } }, |         qs: { plugins: { i18n: { locale: 'fr-FR' } } }, | ||||||
|         body: { name: 'product name' }, |         body: { name: 'product name' }, | ||||||
|       }); |       }); | ||||||
| 
 | 
 | ||||||
| @ -348,7 +360,7 @@ describe('CRUD locales', () => { | |||||||
|       } = await rq({ |       } = await rq({ | ||||||
|         url: '/content-manager/collection-types/application::product.product', |         url: '/content-manager/collection-types/application::product.product', | ||||||
|         method: 'GET', |         method: 'GET', | ||||||
|         qs: { _locale: 'fr' }, |         qs: { _locale: 'fr-FR' }, | ||||||
|       }); |       }); | ||||||
| 
 | 
 | ||||||
|       expect(createdProducts).toHaveLength(1); |       expect(createdProducts).toHaveLength(1); | ||||||
| @ -364,7 +376,7 @@ describe('CRUD locales', () => { | |||||||
|       } = await rq({ |       } = await rq({ | ||||||
|         url: '/content-manager/collection-types/application::product.product', |         url: '/content-manager/collection-types/application::product.product', | ||||||
|         method: 'GET', |         method: 'GET', | ||||||
|         qs: { _locale: 'fr' }, |         qs: { _locale: 'fr-FR' }, | ||||||
|       }); |       }); | ||||||
|       expect(frenchProducts).toHaveLength(0); |       expect(frenchProducts).toHaveLength(0); | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Pierre Noël
						Pierre Noël