77
88import { GlossaryCommand } from '../../src/cli/commands/glossary' ;
99import { GlossaryService } from '../../src/services/glossary' ;
10- import { GlossaryInfo } from '../../src/api/deepl-client ' ;
10+ import { GlossaryInfo } from '../../src/types/glossary.js ' ;
1111import * as fs from 'fs' ;
1212
1313// Mock dependencies
@@ -21,11 +21,14 @@ describe('GlossaryCommand', () => {
2121 const mockGlossary : GlossaryInfo = {
2222 glossary_id : '123-456-789' ,
2323 name : 'Tech Terms' ,
24- ready : true ,
2524 source_lang : 'en' ,
26- target_lang : 'es' ,
25+ target_langs : [ 'es' ] ,
26+ dictionaries : [ {
27+ source_lang : 'en' ,
28+ target_lang : 'es' ,
29+ entry_count : 10 ,
30+ } ] ,
2731 creation_time : '2024-01-15T10:30:00Z' ,
28- entry_count : 10 ,
2932 } ;
3033
3134 beforeEach ( ( ) => {
@@ -58,15 +61,15 @@ describe('GlossaryCommand', () => {
5861 } ) ;
5962
6063 it ( 'should create glossary from TSV file' , async ( ) => {
61- const result = await glossaryCommand . create ( 'Tech Terms' , 'en' , 'es' , '/path/to/glossary.tsv' ) ;
64+ const result = await glossaryCommand . create ( 'Tech Terms' , 'en' , [ 'es' ] , '/path/to/glossary.tsv' ) ;
6265
6366 expect ( result ) . toEqual ( mockGlossary ) ;
6467 expect ( fs . existsSync ) . toHaveBeenCalledWith ( '/path/to/glossary.tsv' ) ;
6568 expect ( fs . readFileSync ) . toHaveBeenCalledWith ( '/path/to/glossary.tsv' , 'utf-8' ) ;
6669 expect ( mockGlossaryService . createGlossaryFromTSV ) . toHaveBeenCalledWith (
6770 'Tech Terms' ,
6871 'en' ,
69- 'es' ,
72+ [ 'es' ] ,
7073 'hello\thola\nworld\tmundo'
7174 ) ;
7275 } ) ;
@@ -75,7 +78,7 @@ describe('GlossaryCommand', () => {
7578 ( fs . existsSync as jest . Mock ) . mockReturnValue ( false ) ;
7679
7780 await expect (
78- glossaryCommand . create ( 'Tech Terms' , 'en' , 'es' , '/path/to/missing.tsv' )
81+ glossaryCommand . create ( 'Tech Terms' , 'en' , [ 'es' ] , '/path/to/missing.tsv' )
7982 ) . rejects . toThrow ( 'File not found' ) ;
8083 } ) ;
8184
@@ -85,7 +88,7 @@ describe('GlossaryCommand', () => {
8588 ) ;
8689
8790 await expect (
88- glossaryCommand . create ( 'Tech Terms' , 'en' , 'es' , '/path/to/glossary.tsv' )
91+ glossaryCommand . create ( 'Tech Terms' , 'en' , [ 'es' ] , '/path/to/glossary.tsv' )
8992 ) . rejects . toThrow ( 'Invalid glossary format' ) ;
9093 } ) ;
9194 } ) ;
@@ -163,7 +166,7 @@ describe('GlossaryCommand', () => {
163166
164167 expect ( result ) . toEqual ( { hello : 'hola' , world : 'mundo' } ) ;
165168 expect ( mockGlossaryService . getGlossary ) . toHaveBeenCalledWith ( '123-456-789' ) ;
166- expect ( mockGlossaryService . getGlossaryEntries ) . toHaveBeenCalledWith ( '123-456-789' ) ;
169+ expect ( mockGlossaryService . getGlossaryEntries ) . toHaveBeenCalledWith ( '123-456-789' , 'en' , 'es' ) ;
167170 } ) ;
168171 } ) ;
169172
@@ -184,96 +187,85 @@ describe('GlossaryCommand', () => {
184187
185188 describe ( 'addEntry()' , ( ) => {
186189 it ( 'should add entry to glossary by ID' , async ( ) => {
187- ( mockGlossaryService . addEntry as jest . Mock ) . mockResolvedValue ( mockGlossary ) ;
190+ ( mockGlossaryService . addEntry as jest . Mock ) . mockResolvedValue ( undefined ) ;
188191
189- const result = await glossaryCommand . addEntry ( '123-456-789' , 'hello' , 'hola' ) ;
192+ await glossaryCommand . addEntry ( '123-456-789' , 'hello' , 'hola' ) ;
190193
191194 expect ( mockGlossaryService . getGlossary ) . toHaveBeenCalledWith ( '123-456-789' ) ;
192- expect ( mockGlossaryService . addEntry ) . toHaveBeenCalledWith ( '123-456-789' , 'hello' , 'hola' ) ;
193- expect ( result ) . toEqual ( mockGlossary ) ;
195+ expect ( mockGlossaryService . addEntry ) . toHaveBeenCalledWith ( '123-456-789' , 'en' , 'es' , 'hello' , 'hola' ) ;
194196 } ) ;
195197
196198 it ( 'should add entry to glossary by name' , async ( ) => {
197199 ( mockGlossaryService . getGlossary as jest . Mock ) . mockRejectedValueOnce ( new Error ( 'Not found' ) ) ;
198- ( mockGlossaryService . addEntry as jest . Mock ) . mockResolvedValue ( mockGlossary ) ;
200+ ( mockGlossaryService . addEntry as jest . Mock ) . mockResolvedValue ( undefined ) ;
199201
200- const result = await glossaryCommand . addEntry ( 'Tech Terms' , 'hello' , 'hola' ) ;
202+ await glossaryCommand . addEntry ( 'Tech Terms' , 'hello' , 'hola' ) ;
201203
202204 expect ( mockGlossaryService . getGlossaryByName ) . toHaveBeenCalledWith ( 'Tech Terms' ) ;
203- expect ( mockGlossaryService . addEntry ) . toHaveBeenCalledWith ( '123-456-789' , 'hello' , 'hola' ) ;
204- expect ( result ) . toEqual ( mockGlossary ) ;
205+ expect ( mockGlossaryService . addEntry ) . toHaveBeenCalledWith ( '123-456-789' , 'en' , 'es' , 'hello' , 'hola' ) ;
205206 } ) ;
206207 } ) ;
207208
208209 describe ( 'updateEntry()' , ( ) => {
209210 it ( 'should update entry in glossary by ID' , async ( ) => {
210- ( mockGlossaryService . updateEntry as jest . Mock ) . mockResolvedValue ( mockGlossary ) ;
211+ ( mockGlossaryService . updateEntry as jest . Mock ) . mockResolvedValue ( undefined ) ;
211212
212- const result = await glossaryCommand . updateEntry ( '123-456-789' , 'hello' , 'hola updated' ) ;
213+ await glossaryCommand . updateEntry ( '123-456-789' , 'hello' , 'hola updated' ) ;
213214
214215 expect ( mockGlossaryService . getGlossary ) . toHaveBeenCalledWith ( '123-456-789' ) ;
215- expect ( mockGlossaryService . updateEntry ) . toHaveBeenCalledWith ( '123-456-789' , 'hello' , 'hola updated' ) ;
216- expect ( result ) . toEqual ( mockGlossary ) ;
216+ expect ( mockGlossaryService . updateEntry ) . toHaveBeenCalledWith ( '123-456-789' , 'en' , 'es' , 'hello' , 'hola updated' ) ;
217217 } ) ;
218218
219219 it ( 'should update entry in glossary by name' , async ( ) => {
220220 ( mockGlossaryService . getGlossary as jest . Mock ) . mockRejectedValueOnce ( new Error ( 'Not found' ) ) ;
221- ( mockGlossaryService . updateEntry as jest . Mock ) . mockResolvedValue ( mockGlossary ) ;
221+ ( mockGlossaryService . updateEntry as jest . Mock ) . mockResolvedValue ( undefined ) ;
222222
223- const result = await glossaryCommand . updateEntry ( 'Tech Terms' , 'hello' , 'hola updated' ) ;
223+ await glossaryCommand . updateEntry ( 'Tech Terms' , 'hello' , 'hola updated' ) ;
224224
225225 expect ( mockGlossaryService . getGlossaryByName ) . toHaveBeenCalledWith ( 'Tech Terms' ) ;
226- expect ( mockGlossaryService . updateEntry ) . toHaveBeenCalledWith ( '123-456-789' , 'hello' , 'hola updated' ) ;
227- expect ( result ) . toEqual ( mockGlossary ) ;
226+ expect ( mockGlossaryService . updateEntry ) . toHaveBeenCalledWith ( '123-456-789' , 'en' , 'es' , 'hello' , 'hola updated' ) ;
228227 } ) ;
229228 } ) ;
230229
231230 describe ( 'removeEntry()' , ( ) => {
232231 it ( 'should remove entry from glossary by ID' , async ( ) => {
233- ( mockGlossaryService . removeEntry as jest . Mock ) . mockResolvedValue ( mockGlossary ) ;
232+ ( mockGlossaryService . removeEntry as jest . Mock ) . mockResolvedValue ( undefined ) ;
234233
235- const result = await glossaryCommand . removeEntry ( '123-456-789' , 'hello' ) ;
234+ await glossaryCommand . removeEntry ( '123-456-789' , 'hello' ) ;
236235
237236 expect ( mockGlossaryService . getGlossary ) . toHaveBeenCalledWith ( '123-456-789' ) ;
238- expect ( mockGlossaryService . removeEntry ) . toHaveBeenCalledWith ( '123-456-789' , 'hello' ) ;
239- expect ( result ) . toEqual ( mockGlossary ) ;
237+ expect ( mockGlossaryService . removeEntry ) . toHaveBeenCalledWith ( '123-456-789' , 'en' , 'es' , 'hello' ) ;
240238 } ) ;
241239
242240 it ( 'should remove entry from glossary by name' , async ( ) => {
243241 ( mockGlossaryService . getGlossary as jest . Mock ) . mockRejectedValueOnce ( new Error ( 'Not found' ) ) ;
244- ( mockGlossaryService . removeEntry as jest . Mock ) . mockResolvedValue ( mockGlossary ) ;
242+ ( mockGlossaryService . removeEntry as jest . Mock ) . mockResolvedValue ( undefined ) ;
245243
246- const result = await glossaryCommand . removeEntry ( 'Tech Terms' , 'hello' ) ;
244+ await glossaryCommand . removeEntry ( 'Tech Terms' , 'hello' ) ;
247245
248246 expect ( mockGlossaryService . getGlossaryByName ) . toHaveBeenCalledWith ( 'Tech Terms' ) ;
249- expect ( mockGlossaryService . removeEntry ) . toHaveBeenCalledWith ( '123-456-789' , 'hello' ) ;
250- expect ( result ) . toEqual ( mockGlossary ) ;
247+ expect ( mockGlossaryService . removeEntry ) . toHaveBeenCalledWith ( '123-456-789' , 'en' , 'es' , 'hello' ) ;
251248 } ) ;
252249 } ) ;
253250
254251 describe ( 'rename()' , ( ) => {
255252 it ( 'should rename glossary by ID' , async ( ) => {
256- const renamedGlossary = { ...mockGlossary , name : 'New Name' } ;
257- ( mockGlossaryService . renameGlossary as jest . Mock ) . mockResolvedValue ( renamedGlossary ) ;
253+ ( mockGlossaryService . renameGlossary as jest . Mock ) . mockResolvedValue ( undefined ) ;
258254
259- const result = await glossaryCommand . rename ( '123-456-789' , 'New Name' ) ;
255+ await glossaryCommand . rename ( '123-456-789' , 'New Name' ) ;
260256
261257 expect ( mockGlossaryService . getGlossary ) . toHaveBeenCalledWith ( '123-456-789' ) ;
262258 expect ( mockGlossaryService . renameGlossary ) . toHaveBeenCalledWith ( '123-456-789' , 'New Name' ) ;
263- expect ( result ) . toEqual ( renamedGlossary ) ;
264- expect ( result . name ) . toBe ( 'New Name' ) ;
265259 } ) ;
266260
267261 it ( 'should rename glossary by name' , async ( ) => {
268262 ( mockGlossaryService . getGlossary as jest . Mock ) . mockRejectedValueOnce ( new Error ( 'Not found' ) ) ;
269- const renamedGlossary = { ...mockGlossary , name : 'New Name' } ;
270- ( mockGlossaryService . renameGlossary as jest . Mock ) . mockResolvedValue ( renamedGlossary ) ;
263+ ( mockGlossaryService . renameGlossary as jest . Mock ) . mockResolvedValue ( undefined ) ;
271264
272- const result = await glossaryCommand . rename ( 'Tech Terms' , 'New Name' ) ;
265+ await glossaryCommand . rename ( 'Tech Terms' , 'New Name' ) ;
273266
274267 expect ( mockGlossaryService . getGlossaryByName ) . toHaveBeenCalledWith ( 'Tech Terms' ) ;
275268 expect ( mockGlossaryService . renameGlossary ) . toHaveBeenCalledWith ( '123-456-789' , 'New Name' ) ;
276- expect ( result ) . toEqual ( renamedGlossary ) ;
277269 } ) ;
278270
279271 it ( 'should handle rename errors' , async ( ) => {
@@ -293,25 +285,17 @@ describe('GlossaryCommand', () => {
293285
294286 expect ( result ) . toContain ( 'Name: Tech Terms' ) ;
295287 expect ( result ) . toContain ( 'ID: 123-456-789' ) ;
296- expect ( result ) . toContain ( 'Status: Ready' ) ;
297- expect ( result ) . toContain ( 'Language pair: en → es' ) ;
298- expect ( result ) . toContain ( 'Entries: 10' ) ;
299- } ) ;
300-
301- it ( 'should show not ready status' , ( ) => {
302- const notReadyGlossary = { ...mockGlossary , ready : false } ;
303-
304- const result = glossaryCommand . formatGlossaryInfo ( notReadyGlossary ) ;
305-
306- expect ( result ) . toContain ( 'Status: Not ready' ) ;
288+ expect ( result ) . toContain ( 'Source language: en' ) ;
289+ expect ( result ) . toContain ( 'Target languages: es' ) ;
290+ expect ( result ) . toContain ( 'Total entries: 10' ) ;
307291 } ) ;
308292 } ) ;
309293
310294 describe ( 'formatGlossaryList()' , ( ) => {
311295 it ( 'should format glossary list for display' , ( ) => {
312296 const result = glossaryCommand . formatGlossaryList ( [ mockGlossary ] ) ;
313297
314- expect ( result ) . toContain ( '✓ Tech Terms' ) ;
298+ expect ( result ) . toContain ( 'Tech Terms' ) ;
315299 expect ( result ) . toContain ( '(en→es)' ) ;
316300 expect ( result ) . toContain ( '10 entries' ) ;
317301 } ) ;
@@ -321,14 +305,6 @@ describe('GlossaryCommand', () => {
321305
322306 expect ( result ) . toBe ( 'No glossaries found' ) ;
323307 } ) ;
324-
325- it ( 'should show not ready status with circle' , ( ) => {
326- const notReadyGlossary = { ...mockGlossary , ready : false } ;
327-
328- const result = glossaryCommand . formatGlossaryList ( [ notReadyGlossary ] ) ;
329-
330- expect ( result ) . toContain ( '○ Tech Terms' ) ;
331- } ) ;
332308 } ) ;
333309
334310 describe ( 'formatEntries()' , ( ) => {
0 commit comments