@@ -5,7 +5,7 @@ import * as path from 'node:path';
55
66import papiBackendMock from '@papi/backend' ;
77import type { Pt9InterlinearProjectData } from 'platform-scripture' ;
8- import { importPt9Project , shouldOfferPt9Import } from '../../services/pt9ImportService' ;
8+ import { hasNoInterlinearizerState , importPt9Project } from '../../services/pt9ImportService' ;
99import { resetQueuesForTesting } from '../../services/projectStorage' ;
1010import { createTestActivationContext , enoentError , makeStubProject } from '../test-helpers' ;
1111
@@ -281,67 +281,47 @@ describe('importPt9Project', () => {
281281 } ) ;
282282} ) ;
283283
284- describe ( 'shouldOfferPt9Import ' , ( ) => {
284+ describe ( 'hasNoInterlinearizerState ' , ( ) => {
285285 beforeEach ( ( ) => {
286286 resetQueuesForTesting ( ) ;
287287 } ) ;
288288
289289 /** Seeds storage reads by key; unlisted keys read as never written. */
290290 function seedStorage ( entries : Record < string , string > ) : void {
291- __mockReadUserData . mockImplementation ( async ( _token : unknown , key : string ) => {
292- if ( Object . hasOwn ( entries , key ) ) return entries [ key ] ;
291+ __mockReadUserData . mockImplementation ( async ( _token : unknown , key : unknown ) => {
292+ if ( typeof key === 'string' && Object . hasOwn ( entries , key ) ) return entries [ key ] ;
293293 throw enoentError ( ) ;
294294 } ) ;
295295 }
296296
297- /** Points the PT9 PDP mock at a manifest carrying the given file paths. */
298- function seedManifest ( paths : string [ ] ) : void {
299- __mockProjectDataProvidersGet . mockResolvedValue ( {
300- getPt9InterlinearManifest : jest
301- . fn ( )
302- . mockResolvedValue ( Object . fromEntries ( paths . map ( ( filePath ) => [ filePath , 'hash' ] ) ) ) ,
303- } ) ;
304- }
305-
306- it ( 'offers when nothing is stored and the source has an interlinear book file' , async ( ) => {
297+ it ( 'answers true when the source has no draft and no projects' , async ( ) => {
307298 seedStorage ( { } ) ;
308- seedManifest ( [ 'Lexicon.xml' , 'Interlinear_en/Interlinear_en_MAT.xml' ] ) ;
309299
310- await expect ( shouldOfferPt9Import ( token , 'src-project' ) ) . resolves . toBe ( true ) ;
300+ await expect ( hasNoInterlinearizerState ( token , 'src-project' ) ) . resolves . toBe ( true ) ;
311301 } ) ;
312302
313- it ( 'does not offer when a draft is already stored' , async ( ) => {
303+ it ( 'answers false when a draft is already stored' , async ( ) => {
314304 seedStorage ( { 'draft:src-project' : 'anything' } ) ;
315305
316- await expect ( shouldOfferPt9Import ( token , 'src-project' ) ) . resolves . toBe ( false ) ;
317- expect ( __mockProjectDataProvidersGet ) . not . toHaveBeenCalled ( ) ;
306+ await expect ( hasNoInterlinearizerState ( token , 'src-project' ) ) . resolves . toBe ( false ) ;
318307 } ) ;
319308
320- it ( 'does not offer when a project already exists for the source' , async ( ) => {
309+ it ( 'answers false when a project already exists for the source' , async ( ) => {
321310 seedStorage ( {
322311 projectIds : JSON . stringify ( [ 'p1' ] ) ,
323312 'project:p1' : JSON . stringify ( makeStubProject ( 'p1' ) ) ,
324313 } ) ;
325314
326- await expect ( shouldOfferPt9Import ( token , 'src-project' ) ) . resolves . toBe ( false ) ;
327- expect ( __mockProjectDataProvidersGet ) . not . toHaveBeenCalled ( ) ;
328- } ) ;
329-
330- it ( 'does not offer for a lexicon- or word-analyses-only manifest' , async ( ) => {
331- seedStorage ( { } ) ;
332- seedManifest ( [ 'Lexicon.xml' , 'WordAnalyses.xml' ] ) ;
333-
334- await expect ( shouldOfferPt9Import ( token , 'src-project' ) ) . resolves . toBe ( false ) ;
315+ await expect ( hasNoInterlinearizerState ( token , 'src-project' ) ) . resolves . toBe ( false ) ;
335316 } ) ;
336317
337- it ( 'answers false when the probe fails, and only warns' , async ( ) => {
338- seedStorage ( { } ) ;
339- __mockProjectDataProvidersGet . mockRejectedValue ( new Error ( 'interface unsupported' ) ) ;
318+ it ( 'answers false when the state check fails, and only warns' , async ( ) => {
319+ __mockReadUserData . mockRejectedValue ( new Error ( 'storage unavailable' ) ) ;
340320
341- await expect ( shouldOfferPt9Import ( token , 'src-project' ) ) . resolves . toBe ( false ) ;
321+ await expect ( hasNoInterlinearizerState ( token , 'src-project' ) ) . resolves . toBe ( false ) ;
342322 expect ( __mockLogger . warn ) . toHaveBeenCalledWith (
343- 'Interlinearizer: Paratext 9 convert-offer probe failed; not offering' ,
344- expect . objectContaining ( { message : 'interface unsupported ' } ) ,
323+ 'Interlinearizer: Paratext 9 convert-offer state check failed; not offering' ,
324+ expect . objectContaining ( { message : 'storage unavailable ' } ) ,
345325 ) ;
346326 } ) ;
347327} ) ;
0 commit comments