@@ -1630,51 +1630,20 @@ describe('run', () => {
16301630 expect ( mockRuntimeLib . deployActions ) . toHaveBeenCalledTimes ( 1 )
16311631 expect ( mockWebLib . deployWeb ) . toHaveBeenCalledTimes ( 1 )
16321632 } )
1633-
1634- test ( 'should deploy successfully when auto-provision database is configured' , async ( ) => {
1635- // Create app config with database auto-provision enabled
1636- const appConfigWithDb = createAppConfig ( {
1637- ...command . appConfig ,
1638- manifest : {
1639- full : {
1640- database : {
1641- 'auto-provision' : true ,
1642- region : 'emea'
1643- }
1644- }
1645- }
1646- } )
1647-
1648- command . getAppExtConfigs . mockResolvedValueOnce ( appConfigWithDb )
1649- command . provisionDatabase = jest . fn ( ) . mockResolvedValue ( )
1650-
1651- await command . run ( )
1652-
1653- expect ( command . error ) . toHaveBeenCalledTimes ( 0 )
1654- expect ( command . provisionDatabase ) . toHaveBeenCalledTimes ( 1 )
1655- expect ( command . provisionDatabase ) . toHaveBeenCalledWith (
1656- appConfigWithDb . application ,
1657- expect . any ( Object ) , // spinner
1658- expect . objectContaining ( { 'force-build' : true } ) // flags
1659- )
1660- expect ( mockRuntimeLib . deployActions ) . toHaveBeenCalledTimes ( 1 )
1661- expect ( mockWebLib . deployWeb ) . toHaveBeenCalledTimes ( 1 )
1662- } )
16631633} )
16641634
16651635describe ( 'database provisioning' , ( ) => {
1666- const createDatabaseConfig = ( region = null , autoProvision = true ) => ( {
1636+ // Helper functions for unit tests
1637+ const createDatabaseConfig = ( region = null ) => ( {
16671638 manifest : {
16681639 full : {
16691640 database : {
1670- 'auto-provision' : autoProvision ,
16711641 ...( region && { region } )
16721642 }
16731643 }
16741644 }
16751645 } )
16761646
1677- // Helper function to set up and run test
16781647 const runProvisionTest = async ( config , flags , mockResult ) => {
16791648 const spinner = ora ( )
16801649
@@ -1690,18 +1659,60 @@ describe('database provisioning', () => {
16901659 }
16911660 }
16921661
1693- test ( 'should use default region when not specified in manifest' , async ( ) => {
1694- const config = createDatabaseConfig ( )
1695- const flags = { verbose : false }
1662+ test ( 'should provision database when auto-provision is true' , async ( ) => {
1663+ const appConfigWithDb = createAppConfig ( {
1664+ ...command . appConfig ,
1665+ manifest : {
1666+ full : {
1667+ database : {
1668+ 'auto-provision' : true ,
1669+ region : 'emea'
1670+ }
1671+ }
1672+ }
1673+ } )
16961674
1697- const { spinner } = await runProvisionTest ( config , flags )
1675+ command . getAppExtConfigs . mockResolvedValueOnce ( appConfigWithDb )
1676+ command . config . runCommand . mockResolvedValue ( )
16981677
1699- expect ( spinner . start ) . toHaveBeenCalledWith ( 'Deploying database in default region' )
1700- expect ( command . config . runCommand ) . toHaveBeenCalledWith ( 'app:db:provision' , [ '--yes' ] )
1701- expect ( spinner . succeed ) . toHaveBeenCalledWith ( expect . stringContaining ( 'Deployed database for application' ) )
1678+ await command . run ( )
1679+
1680+ expect ( command . error ) . toHaveBeenCalledTimes ( 0 )
1681+ expect ( command . config . runCommand ) . toHaveBeenCalledWith ( 'app:db:provision' , [ '--region' , 'emea' , '--yes' ] )
1682+ expect ( mockRuntimeLib . deployActions ) . toHaveBeenCalledTimes ( 1 )
1683+ expect ( mockWebLib . deployWeb ) . toHaveBeenCalledTimes ( 1 )
1684+ expect ( command . log ) . toHaveBeenCalledWith (
1685+ expect . stringContaining ( 'Successful deployment 🏄' )
1686+ )
1687+ } )
1688+
1689+ test ( 'should not provision database when auto-provision is false' , async ( ) => {
1690+ const appConfigWithoutDb = createAppConfig ( {
1691+ ...command . appConfig ,
1692+ manifest : {
1693+ full : {
1694+ database : {
1695+ 'auto-provision' : false
1696+ }
1697+ }
1698+ }
1699+ } )
1700+
1701+ command . getAppExtConfigs . mockResolvedValueOnce ( appConfigWithoutDb )
1702+
1703+ await command . run ( )
1704+
1705+ expect ( command . error ) . toHaveBeenCalledTimes ( 0 )
1706+ expect ( command . config . runCommand ) . not . toHaveBeenCalledWith ( 'app:db:provision' , expect . anything ( ) )
1707+ expect ( mockRuntimeLib . deployActions ) . toHaveBeenCalledTimes ( 1 )
1708+ expect ( mockWebLib . deployWeb ) . toHaveBeenCalledTimes ( 1 )
1709+ expect ( command . log ) . toHaveBeenCalledWith (
1710+ expect . stringContaining ( 'Successful deployment 🏄' )
1711+ )
17021712 } )
17031713
1704- test ( 'should use configured region when specified in manifest' , async ( ) => {
1714+ // tests for provisionDatabase method behavior
1715+ test ( 'should run provision command correctly with region' , async ( ) => {
17051716 const config = createDatabaseConfig ( 'emea' )
17061717 const flags = { verbose : false }
17071718
@@ -1712,7 +1723,18 @@ describe('database provisioning', () => {
17121723 expect ( spinner . succeed ) . toHaveBeenCalledWith ( expect . stringContaining ( 'Deployed database for application in region \'emea\'' ) )
17131724 } )
17141725
1715- test ( 'should show verbose output when verbose flag is true' , async ( ) => {
1726+ test ( 'should run provision command correctly without region' , async ( ) => {
1727+ const config = createDatabaseConfig ( )
1728+ const flags = { verbose : false }
1729+
1730+ const { spinner } = await runProvisionTest ( config , flags )
1731+
1732+ expect ( spinner . start ) . toHaveBeenCalledWith ( 'Deploying database in default region' )
1733+ expect ( command . config . runCommand ) . toHaveBeenCalledWith ( 'app:db:provision' , [ '--yes' ] )
1734+ expect ( spinner . succeed ) . toHaveBeenCalledWith ( expect . stringContaining ( 'Deployed database for application' ) )
1735+ } )
1736+
1737+ test ( 'should show verbose output with region' , async ( ) => {
17161738 const config = createDatabaseConfig ( 'amer' )
17171739 const flags = { verbose : true }
17181740
@@ -1723,7 +1745,7 @@ describe('database provisioning', () => {
17231745 expect ( spinner . succeed ) . toHaveBeenCalledWith ( expect . stringContaining ( 'Deployed database for application in region \'amer\'' ) )
17241746 } )
17251747
1726- test ( 'should show verbose output without region when no region configured ' , async ( ) => {
1748+ test ( 'should show verbose output without region' , async ( ) => {
17271749 const config = createDatabaseConfig ( )
17281750 const flags = { verbose : true }
17291751
@@ -1741,27 +1763,5 @@ describe('database provisioning', () => {
17411763
17421764 await expect ( runProvisionTest ( config , flags , error ) )
17431765 . rejects . toThrow ( 'Database provision failed' )
1744-
1745- expect ( command . warn ) . not . toHaveBeenCalled ( )
1746- } )
1747-
1748- test ( 'should show verbose error details when verbose flag is true and provision fails' , async ( ) => {
1749- const config = createDatabaseConfig ( 'amer' )
1750- const flags = { verbose : true }
1751- const error = new Error ( 'Database provision failed' )
1752-
1753- await expect ( runProvisionTest ( config , flags , error ) )
1754- . rejects . toThrow ( 'Database provision failed' )
1755-
1756- expect ( command . warn ) . not . toHaveBeenCalled ( )
1757- } )
1758-
1759- test ( 'should fail if invalid region specified' , async ( ) => {
1760- const config = createDatabaseConfig ( 'invalid-region' )
1761- const flags = { verbose : false }
1762- const error = new Error ( 'Invalid region: invalid-region' )
1763-
1764- await expect ( runProvisionTest ( config , flags , error ) )
1765- . rejects . toThrow ( 'Invalid region: invalid-region' )
17661766 } )
17671767} )
0 commit comments