| 
									
										
										
										
											2022-03-14 22:49:27 +07:00
										 |  |  | 'use strict'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const fs = require('fs-extra'); | 
					
						
							| 
									
										
										
										
											2022-03-15 15:52:57 +07:00
										 |  |  | const { updateMissingKeysToJSON } = require('../add-missing-keys-to-other-language'); | 
					
						
							| 
									
										
										
										
											2022-03-14 22:49:27 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-15 15:52:57 +07:00
										 |  |  | describe('updateMissingKeysToJSON', () => { | 
					
						
							| 
									
										
										
										
											2022-03-14 22:49:27 +07:00
										 |  |  |   it('should add missing keys from en.json to translation file', async () => { | 
					
						
							| 
									
										
										
										
											2022-07-11 14:40:58 +02:00
										 |  |  |     const TARGET_TRANSLATION_FILE_PATH = 'scripts/front/tests/vi.json'; | 
					
						
							|  |  |  |     const SOURCE_TRANSLATION_FILE_PATH = 'scripts/front/tests/en.json'; | 
					
						
							| 
									
										
										
										
											2022-03-14 22:49:27 +07:00
										 |  |  |     // Save original `vi.json` file content
 | 
					
						
							|  |  |  |     const originalTargetTranslationFileContent = fs.readFileSync( | 
					
						
							|  |  |  |       TARGET_TRANSLATION_FILE_PATH, | 
					
						
							|  |  |  |       'utf8' | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |     const originalTargetTranslationFileJSON = JSON.parse(originalTargetTranslationFileContent); | 
					
						
							|  |  |  |     const mainTranslationFileJSON = await fs.readJSON(SOURCE_TRANSLATION_FILE_PATH); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Add missing keys for `vi.json`
 | 
					
						
							| 
									
										
										
										
											2022-03-15 15:52:57 +07:00
										 |  |  |     const updatedTargetTranslationFileJSON = await updateMissingKeysToJSON( | 
					
						
							|  |  |  |       TARGET_TRANSLATION_FILE_PATH | 
					
						
							| 
									
										
										
										
											2022-03-14 22:49:27 +07:00
										 |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // `vi.json` should have all keys from `en.json`
 | 
					
						
							| 
									
										
										
										
											2022-08-08 23:33:39 +02:00
										 |  |  |     Object.keys(mainTranslationFileJSON).forEach((key) => { | 
					
						
							| 
									
										
										
										
											2022-03-14 22:49:27 +07:00
										 |  |  |       expect(key in updatedTargetTranslationFileJSON).toBe(true); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // `vi.json` should keep the current translation
 | 
					
						
							| 
									
										
										
										
											2022-08-08 23:33:39 +02:00
										 |  |  |     Object.keys(originalTargetTranslationFileContent).forEach((key) => { | 
					
						
							| 
									
										
										
										
											2022-03-14 22:49:27 +07:00
										 |  |  |       expect(updatedTargetTranslationFileJSON[key]).toEqual(originalTargetTranslationFileJSON[key]); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); |