@@ -3,9 +3,11 @@ import type { Manifest, Package } from '../../src';
33import { createApplicationAccess , createProjectAccess } from '../../src' ;
44import * as i18nMock from '../../src/project/i18n/write' ;
55import * as specMock from '../../src/project/specification' ;
6+ import * as capMock from '../../src/project/cap' ;
67import { create as createStorage } from 'mem-fs' ;
78import { create } from 'mem-fs-editor' ;
89import { promises } from 'node:fs' ;
10+ import { readFile , readJSON } from '../../src/file' ;
911
1012describe ( 'Test function createApplicationAccess()' , ( ) => {
1113 const memFs = create ( createStorage ( ) ) ;
@@ -373,6 +375,165 @@ describe('Test function createApplicationAccess()', () => {
373375 expect ( error . message ) . toContain ( 'non-existing-app' ) ;
374376 }
375377 } ) ;
378+
379+ test ( 'Read manifest.json of standalone app without mem-fs' , async ( ) => {
380+ const appRoot = join ( sampleRoot , 'fiori_elements' ) ;
381+ // Test execution
382+ const appAccess = await createApplicationAccess ( appRoot ) ;
383+ const manifest = await appAccess . readManifest ( ) ;
384+ // Result check
385+ expect ( manifest ) . toEqual ( await readJSON ( join ( appRoot , 'webapp/manifest.json' ) ) ) ;
386+ } ) ;
387+
388+ test ( 'Read manifest.json of standalone app with mem-fs' , async ( ) => {
389+ const appRoot = join ( sampleRoot , 'fiori_elements' ) ;
390+ const manifestPath = join ( appRoot , 'webapp/manifest.json' ) ;
391+ const newManifest = await readJSON < { dummy : boolean } > ( join ( appRoot , 'webapp/manifest.json' ) , memFs ) ;
392+ newManifest . dummy = true ;
393+ memFs . writeJSON ( manifestPath , newManifest , undefined , 4 ) ;
394+ // Test execution
395+ const appAccess = await createApplicationAccess ( appRoot ) ;
396+ const manifest = await appAccess . readManifest ( memFs ) ;
397+ // Result check
398+ expect ( 'dummy' in manifest ? manifest . dummy : undefined ) . toEqual ( true ) ;
399+ } ) ;
400+
401+ test ( 'Read manifest.json of standalone app with mem-fs(mem-fs is passed on creation)' , async ( ) => {
402+ const appRoot = join ( sampleRoot , 'fiori_elements' ) ;
403+ const manifestPath = join ( appRoot , 'webapp/manifest.json' ) ;
404+ const newManifest = await readJSON < { dummy : string } > ( join ( appRoot , 'webapp/manifest.json' ) , memFs ) ;
405+ newManifest . dummy = 'Test' ;
406+ memFs . writeJSON ( manifestPath , newManifest , undefined , 4 ) ;
407+ // Test execution
408+ const appAccess = await createApplicationAccess ( appRoot , memFs ) ;
409+ const manifest = await appAccess . readManifest ( ) ;
410+ // Result check
411+ expect ( 'dummy' in manifest ? manifest . dummy : undefined ) . toEqual ( 'Test' ) ;
412+ } ) ;
413+
414+ test ( 'Read flex changes of standalone app without mem-fs - without flex changes' , async ( ) => {
415+ const appRoot = join ( sampleRoot , 'fiori_elements' ) ;
416+ // Test execution
417+ const appAccess = await createApplicationAccess ( appRoot ) ;
418+ const changes = await appAccess . readFlexChanges ( ) ;
419+ // Result check
420+ expect ( Object . keys ( changes ) ) . toEqual ( [ ] ) ;
421+ } ) ;
422+
423+ test ( 'Read flex changes of standalone app without mem-fs - with flex changes' , async ( ) => {
424+ const appRoot = join ( sampleRoot , 'fiori_elements' ) ;
425+ // Test execution
426+ const appAccess = await createApplicationAccess ( appRoot ) ;
427+ // Mock changes folder
428+ appAccess . app . changes = join ( __dirname , '../test-data/project/flex-changes/webapp/changes' ) ;
429+ const changes = await appAccess . readFlexChanges ( ) ;
430+ // Result check
431+ expect ( Object . keys ( changes ) ) . toEqual ( [
432+ 'id_1761320220775_1_propertyChange.change' ,
433+ 'id_1761320220775_2_propertyChange.change'
434+ ] ) ;
435+ } ) ;
436+
437+ test ( 'Read flex changes with mem-fs' , async ( ) => {
438+ const changeFileName = 'id_1761320220775_1_propertyChange.change' ;
439+ const appRoot = join ( sampleRoot , 'fiori_elements' ) ;
440+ const changesPath = join ( __dirname , '../test-data/project/flex-changes/webapp/changes' ) ;
441+ const changeFilePath = join ( changesPath , changeFileName ) ;
442+ memFs . write ( changeFilePath , '{"dummy": true}' ) ;
443+ // Test execution
444+ const appAccess = await createApplicationAccess ( appRoot ) ;
445+ appAccess . app . changes = changesPath ;
446+ const changes = await appAccess . readFlexChanges ( memFs ) ;
447+ // Result check
448+ expect ( changes [ changeFileName ] ) . toEqual ( '{"dummy": true}' ) ;
449+ } ) ;
450+
451+ test ( 'Read flex changes with mem-fs(mem-fs is passed on creation)' , async ( ) => {
452+ const changeFileName = 'id_1761320220775_1_propertyChange.change' ;
453+ const appRoot = join ( sampleRoot , 'fiori_elements' ) ;
454+ const changesPath = join ( __dirname , '../test-data/project/flex-changes/webapp/changes' ) ;
455+ const changeFilePath = join ( changesPath , changeFileName ) ;
456+ memFs . write ( changeFilePath , '{"dummy": "test"}' ) ;
457+ // Test execution
458+ const appAccess = await createApplicationAccess ( appRoot , memFs ) ;
459+ appAccess . app . changes = changesPath ;
460+ const changes = await appAccess . readFlexChanges ( ) ;
461+ // Result check
462+ expect ( changes [ changeFileName ] ) . toEqual ( '{"dummy": "test"}' ) ;
463+ } ) ;
464+
465+ describe ( 'readAnnotationFiles' , ( ) => {
466+ test ( 'Read annotation files of standalone EDMX app without mem-fs' , async ( ) => {
467+ const appRoot = join ( sampleRoot , 'fiori_elements' ) ;
468+ // Test execution
469+ const appAccess = await createApplicationAccess ( appRoot ) ;
470+ const annotationFiles = await appAccess . readAnnotationFiles ( ) ;
471+ // Result check
472+ expect ( annotationFiles . map ( ( annotationFile ) => annotationFile . dataSourceUri ) ) . toEqual ( [
473+ join ( appRoot , 'webapp/localService/metadata.xml' ) ,
474+ join ( appRoot , 'webapp/annotations/annotation.xml' )
475+ ] ) ;
476+ expect ( annotationFiles [ 0 ] . fileContent . includes ( 'Alias="Measures"' ) ) . toBeTruthy ( ) ;
477+ expect ( annotationFiles [ 1 ] . fileContent . includes ( '/catalog-admin-noauth/$metadata' ) ) . toBeTruthy ( ) ;
478+ } ) ;
479+
480+ test ( 'Read annotation files of standalone EDMX app with mem-fs' , async ( ) => {
481+ const appRoot = join ( sampleRoot , 'fiori_elements' ) ;
482+ const expectedFiles = [
483+ join ( appRoot , 'webapp/localService/metadata.xml' ) ,
484+ join ( appRoot , 'webapp/annotations/annotation.xml' )
485+ ] ;
486+ memFs . write ( expectedFiles [ 0 ] , 'Test metadata.xml' ) ;
487+ memFs . write ( expectedFiles [ 1 ] , 'Test annotation.xml' ) ;
488+ // Test execution
489+ const appAccess = await createApplicationAccess ( appRoot ) ;
490+ const annotationFiles = await appAccess . readAnnotationFiles ( memFs ) ;
491+ // Result check
492+ expect ( annotationFiles . map ( ( annotationFile ) => annotationFile . dataSourceUri ) ) . toEqual ( expectedFiles ) ;
493+ expect ( annotationFiles [ 0 ] . fileContent ) . toEqual ( 'Test metadata.xml' ) ;
494+ expect ( annotationFiles [ 1 ] . fileContent ) . toEqual ( 'Test annotation.xml' ) ;
495+ } ) ;
496+
497+ test ( 'Read annotation files of standalone EDMX app with mem-fs(mem-fs is passed on creation)' , async ( ) => {
498+ const appRoot = join ( sampleRoot , 'fiori_elements' ) ;
499+ const expectedFiles = [
500+ join ( appRoot , 'webapp/localService/metadata.xml' ) ,
501+ join ( appRoot , 'webapp/annotations/annotation.xml' )
502+ ] ;
503+ memFs . write ( expectedFiles [ 0 ] , 'Test2 metadata.xml' ) ;
504+ memFs . write ( expectedFiles [ 1 ] , 'Test2 annotation.xml' ) ;
505+ // Make sure manifest.json has original content in mem-fs
506+ const manifestPath = join ( appRoot , 'webapp/manifest.json' ) ;
507+ const originalManifest = await readJSON < { dummy : string } > ( join ( appRoot , 'webapp/manifest.json' ) ) ;
508+ memFs . writeJSON ( manifestPath , originalManifest , undefined , 4 ) ;
509+ // Test execution
510+ const appAccess = await createApplicationAccess ( appRoot , memFs ) ;
511+ const annotationFiles = await appAccess . readAnnotationFiles ( ) ;
512+ // Result check
513+ expect ( annotationFiles . map ( ( annotationFile ) => annotationFile . dataSourceUri ) ) . toEqual ( expectedFiles ) ;
514+ expect ( annotationFiles [ 0 ] . fileContent ) . toEqual ( 'Test2 metadata.xml' ) ;
515+ expect ( annotationFiles [ 1 ] . fileContent ) . toEqual ( 'Test2 annotation.xml' ) ;
516+ } ) ;
517+
518+ test ( 'Read annotation files of CAP app' , async ( ) => {
519+ // Mock setup
520+ const mockedMetadata = await readFile (
521+ join ( sampleRoot , 'fiori_elements' , 'webapp/localService/metadata.xml' )
522+ ) ;
523+ jest . spyOn ( capMock , 'readCapServiceMetadataEdmx' ) . mockResolvedValue ( mockedMetadata ) ;
524+
525+ const projectRoot = join ( sampleRoot , 'cap-project' ) ;
526+ const appRoot = join ( projectRoot , 'apps/two' ) ;
527+ // Test execution
528+ const appAccess = await createApplicationAccess ( appRoot ) ;
529+ const annotationFiles = await appAccess . readAnnotationFiles ( ) ;
530+ // Result check
531+ expect ( annotationFiles . map ( ( annotationFile ) => annotationFile . dataSourceUri ) ) . toEqual ( [
532+ '/sap/opu/odata4/dmo/ODATA_SERVICE/'
533+ ] ) ;
534+ expect ( annotationFiles [ 0 ] . fileContent . includes ( 'Alias="Measures"' ) ) . toBeTruthy ( ) ;
535+ } ) ;
536+ } ) ;
376537} ) ;
377538
378539describe ( 'Test function createProjectAccess()' , ( ) => {
0 commit comments