@@ -15,6 +15,7 @@ import { tripAuditChecks } from '../TripAuditChecks';
1515import { segmentAuditChecks } from '../SegmentAuditChecks' ;
1616import i18n , { registerTranslationDir , addTranslationNamespace } from 'chaire-lib-backend/lib/config/i18next' ;
1717import path from 'path' ;
18+ import fs from 'fs' ;
1819
1920const languages = [ 'en' , 'fr' ] ;
2021
@@ -70,4 +71,43 @@ describe('Audit Locales', () => {
7071
7172 } ) ;
7273
74+ describe ( 'Orphaned audit translations' , ( ) => {
75+ // Get all translation keys from the audit translation files
76+ const getTranslationKeysFromFile = ( language : string ) : string [ ] => {
77+ const translationFilePath = path . join ( __dirname , '../../../../../../../../locales/' , language , 'audits.json' ) ;
78+ if ( ! fs . existsSync ( translationFilePath ) ) {
79+ throw new Error ( `Translation file not found: ${ translationFilePath } ` ) ;
80+ }
81+ const translationFile = fs . readFileSync ( translationFilePath , 'utf-8' ) ;
82+ const translations = JSON . parse ( translationFile ) ;
83+ return Object . keys ( translations ) ;
84+ } ;
85+
86+ // Define the mapping between prefixes and audit check modules
87+ const auditCheckModules : { [ prefix : string ] : Record < string , unknown > } = {
88+ 'I_' : interviewAuditChecks ,
89+ 'HM_' : homeAuditChecks ,
90+ 'HH_' : householdAuditChecks ,
91+ 'J_' : journeyAuditChecks ,
92+ 'P_' : personAuditChecks ,
93+ 'S_' : segmentAuditChecks ,
94+ 'T_' : tripAuditChecks ,
95+ 'VP_' : visitedPlaceAuditChecks
96+ } ;
97+
98+ describe . each ( languages ) ( 'Language: %s' , ( language ) => {
99+ describe . each ( Object . entries ( auditCheckModules ) ) ( 'Prefix: %s' , ( prefix , auditChecks ) => {
100+ it ( `should not have orphaned translations starting with ${ prefix } ` , ( ) => {
101+ const translationKeys = getTranslationKeysFromFile ( language ) ;
102+ const keysWithPrefix = translationKeys . filter ( ( key ) => key . startsWith ( prefix ) ) ;
103+ const auditCheckCodes = Object . keys ( auditChecks ) ;
104+
105+ // Find translations that exist but are not in the audit check module
106+ const orphanedKeys = keysWithPrefix . filter ( ( key ) => ! auditCheckCodes . includes ( key ) ) ;
107+ expect ( orphanedKeys ) . toEqual ( [ ] ) ;
108+ } ) ;
109+ } ) ;
110+ } ) ;
111+ } ) ;
112+
73113} ) ;
0 commit comments