@@ -19,6 +19,7 @@ process.env.CDS_REQUIRES_DB_CREDENTIALS_URL = ':memory:'
1919
2020const { describe, it, before, after } = require ( 'node:test' )
2121const assert = require ( 'node:assert/strict' )
22+ const { execFileSync } = require ( 'node:child_process' )
2223const cds = require ( '@sap/cds' )
2324
2425// Convenience shortcuts from the CDS query builder
@@ -627,4 +628,94 @@ describe('Star Wars CDS Model Tests', () => {
627628 assert . equal ( data . value [ 0 ] . homeworld ?. name , 'Species Homeworld-speciestest' )
628629 } )
629630 } )
631+
632+ // ─────────────────────────────────────────────────────────────────────────
633+ // Profile-specific model exposure (pg only)
634+ // peopleFirstNamePg is intentionally added via db/postgres model extension
635+ // and must not leak into default/sqlite or hybrid/hana runtime profiles.
636+ // ─────────────────────────────────────────────────────────────────────────
637+ describe ( 'Profile-specific model exposure (pg only)' , ( ) => {
638+ it ( 'default sqlite profile does NOT include peopleFirstNamePg artifacts' , async ( ) => {
639+ const model = await cds . load ( '*' )
640+ assert . equal (
641+ model . definitions [ 'star.wars.peopleFirstNamePg' ] !== undefined ,
642+ false ,
643+ 'star.wars.peopleFirstNamePg must not be present in default sqlite profile'
644+ )
645+ assert . equal (
646+ model . definitions [ 'StarWarsPeople.peopleFirstNamePg' ] !== undefined ,
647+ false ,
648+ 'StarWarsPeople.peopleFirstNamePg must not be exposed in default sqlite profile'
649+ )
650+ } )
651+
652+ it ( 'pg profile includes both db view and service projection artifacts' , ( ) => {
653+ const script = `
654+ process.env.CDS_ENV = 'pg'
655+ const cds = require('@sap/cds')
656+ cds.load('*').then((model) => {
657+ const result = {
658+ view: !!model.definitions['star.wars.peopleFirstNamePg'],
659+ service: !!model.definitions['StarWarsPeople.peopleFirstNamePg']
660+ }
661+ console.log(JSON.stringify(result))
662+ }).catch((err) => {
663+ console.error(err)
664+ process.exit(1)
665+ })
666+ `
667+
668+ const output = execFileSync ( process . execPath , [ '-e' , script ] , {
669+ cwd : __dirname + '/..' ,
670+ encoding : 'utf8'
671+ } )
672+
673+ const jsonLine = output
674+ . split ( / \r ? \n / )
675+ . map ( l => l . trim ( ) )
676+ . filter ( Boolean )
677+ . findLast ( l => l . startsWith ( '{' ) && l . endsWith ( '}' ) )
678+
679+ assert . ok ( jsonLine , 'Expected JSON result from pg profile model check' )
680+ const result = JSON . parse ( jsonLine )
681+
682+ assert . equal ( result . view , true , 'pg profile should include star.wars.peopleFirstNamePg' )
683+ assert . equal ( result . service , true , 'pg profile should include StarWarsPeople.peopleFirstNamePg' )
684+ } )
685+
686+ it ( 'pg profile includes peopleFirstNamePg in StarWarsPeople metadata document' , ( ) => {
687+ const script = `
688+ process.env.CDS_ENV = 'pg'
689+ const cds = require('@sap/cds')
690+
691+ ;(async () => {
692+ const model = await cds.load('*')
693+ const edmx = cds.compile.to.edmx(model, { service: 'StarWarsPeople' })
694+ console.log(JSON.stringify({
695+ hasEntity: String(edmx).includes('peopleFirstNamePg')
696+ }))
697+ process.exit(0)
698+ })().catch((err) => {
699+ console.error(err)
700+ process.exit(1)
701+ })
702+ `
703+
704+ const output = execFileSync ( process . execPath , [ '-e' , script ] , {
705+ cwd : __dirname + '/..' ,
706+ encoding : 'utf8'
707+ } )
708+
709+ const jsonLine = output
710+ . split ( / \r ? \n / )
711+ . map ( l => l . trim ( ) )
712+ . filter ( Boolean )
713+ . findLast ( l => l . startsWith ( '{' ) && l . endsWith ( '}' ) )
714+
715+ assert . ok ( jsonLine , 'Expected JSON result from pg profile metadata endpoint check' )
716+ const result = JSON . parse ( jsonLine )
717+
718+ assert . equal ( result . hasEntity , true , 'Expected peopleFirstNamePg in pg profile StarWarsPeople metadata' )
719+ } )
720+ } )
630721} )
0 commit comments