@@ -1532,3 +1532,64 @@ it("should increment and decrement userCount when a user is added to a project",
15321532 expect ( finalProjectResponse . body . total_users ) . toBe ( 0 ) ;
15331533
15341534} ) ;
1535+
1536+ it ( "should preserve API Keys app enabled state when updating allowUserApiKeys config" , async ( { expect } ) => {
1537+ await Auth . Otp . signIn ( ) ;
1538+ const { adminAccessToken } = await Project . createAndGetAdminToken ( ) ;
1539+
1540+ // Enable the API Keys app
1541+ const enableAppResponse = await niceBackendFetch ( "/api/v1/internal/config/override" , {
1542+ accessType : "admin" ,
1543+ method : "PATCH" ,
1544+ headers : {
1545+ 'x-stack-admin-access-token' : adminAccessToken ,
1546+ } ,
1547+ body : {
1548+ config_override_string : JSON . stringify ( {
1549+ 'apps.installed.api-keys' : {
1550+ enabled : true ,
1551+ } ,
1552+ } ) ,
1553+ } ,
1554+ } ) ;
1555+ expect ( enableAppResponse ) . toMatchInlineSnapshot ( `
1556+ NiceResponse {
1557+ "status": 200,
1558+ "body": {},
1559+ "headers": Headers { <some fields may have been hidden> },
1560+ }
1561+ ` ) ;
1562+
1563+ // Verify the API Keys app is enabled
1564+ const getConfigResponse1 = await niceBackendFetch ( "/api/v1/internal/config" , {
1565+ accessType : "admin" ,
1566+ headers : {
1567+ 'x-stack-admin-access-token' : adminAccessToken ,
1568+ } ,
1569+ } ) ;
1570+ expect ( getConfigResponse1 . status ) . toBe ( 200 ) ;
1571+ expect ( JSON . parse ( getConfigResponse1 . body . config_string ) . apps . installed [ "api-keys" ] ) . toMatchInlineSnapshot ( `
1572+ { "enabled": true }
1573+ ` ) ;
1574+
1575+ // Update allowUserApiKeys using the old project update endpoint
1576+ const { updateProjectResponse } = await Project . updateCurrent ( adminAccessToken , {
1577+ config : {
1578+ allow_user_api_keys : true ,
1579+ } ,
1580+ } ) ;
1581+ expect ( updateProjectResponse . status ) . toBe ( 200 ) ;
1582+ expect ( updateProjectResponse . body . config . allow_user_api_keys ) . toBe ( true ) ;
1583+
1584+ // Verify the API Keys app is still enabled after the update
1585+ const getConfigResponse2 = await niceBackendFetch ( "/api/v1/internal/config" , {
1586+ accessType : "admin" ,
1587+ headers : {
1588+ 'x-stack-admin-access-token' : adminAccessToken ,
1589+ } ,
1590+ } ) ;
1591+ expect ( getConfigResponse2 . status ) . toBe ( 200 ) ;
1592+ expect ( JSON . parse ( getConfigResponse2 . body . config_string ) . apps . installed [ "api-keys" ] ) . toMatchInlineSnapshot ( `
1593+ { "enabled": true }
1594+ ` ) ;
1595+ } ) ;
0 commit comments