@@ -64,110 +64,90 @@ describe('Demo URL Processor', () => {
6464 } ) ;
6565
6666 describe ( 'runDemoUrlProcessor' , ( ) => {
67- it ( 'should process demo URL successfully' , async ( ) => {
68- // Set up the IMS_ORG_TENANT_ID_MAPPINGS secret in context
69- context . env . IMS_ORG_TENANT_ID_MAPPINGS = JSON . stringify ( {
70- '8C6043F15F43B6390A49401A@AdobeOrg' : 'aem-sites-engineering' ,
71- } ) ;
67+ it ( 'should handle organization not found error' , async ( ) => {
68+ // Mock Organization.findById to return null
69+ context . dataAccess . Organization . findById . resolves ( null ) ;
7270
7371 await runDemoUrlProcessor ( message , context ) ;
74- expect ( context . log . info . calledWith ( 'Processing demo url for site:' , {
75- taskType : 'demo-url-processor' ,
76- siteId : 'test-site-id' ,
77- experienceUrl : 'https://example.com' ,
78- organizationId : 'test-org-id' ,
79- } ) ) . to . be . true ;
80- const expectedDemoUrl = 'https://example.com?organizationId=test-org-id#/@aem-sites-engineering/sites-optimizer/sites/test-site-id/home' ;
81- expect ( context . log . info . calledWith ( `Setup complete! Access your demo environment here: ${ expectedDemoUrl } ` ) ) . to . be . true ;
82- } ) ;
8372
84- it ( 'should handle missing slackContext in taskContext' , async ( ) => {
85- // Set up the IMS_ORG_TENANT_ID_MAPPINGS secret in context
86- context . env . IMS_ORG_TENANT_ID_MAPPINGS = JSON . stringify ( {
87- '8C6043F15F43B6390A49401A@AdobeOrg' : 'aem-sites-engineering' ,
88- } ) ;
89-
90- delete message . taskContext . slackContext ;
91- await runDemoUrlProcessor ( message , context ) ;
92- const expectedDemoUrl = 'https://example.com?organizationId=test-org-id#/@aem-sites-engineering/sites-optimizer/sites/test-site-id/home' ;
93- expect ( context . log . info . calledWith ( `Setup complete! Access your demo environment here: ${ expectedDemoUrl } ` ) ) . to . be . true ;
73+ // Should log error and return early
74+ expect ( context . log . error . calledWith ( 'Organization not found for organizationId: test-org-id' ) ) . to . be . true ;
75+ // Should not log the success message
76+ expect ( context . log . info . calledWithMatch ( sinon . match ( 'Setup complete!' ) ) ) . to . be . false ;
9477 } ) ;
9578
96- it ( 'should use IMS_ORG_TENANT_ID_MAPPINGS mapping when available' , async ( ) => {
97- // Set up the IMS_ORG_TENANT_ID_MAPPINGS secret in context
98- context . env . IMS_ORG_TENANT_ID_MAPPINGS = JSON . stringify ( {
99- '8C6043F15F43B6390A49401A@AdobeOrg' : 'aem-sites-engineering' ,
79+ it ( 'should handle organization with missing name property' , async ( ) => {
80+ // Mock Organization.findById to return organization without name
81+ context . dataAccess . Organization . findById . resolves ( {
82+ imsOrgId : '8C6043F15F43B6390A49401A@AdobeOrg' ,
83+ // name property is missing
10084 } ) ;
10185
102- await runDemoUrlProcessor ( message , context ) ;
103-
104- // Should use the mapped tenant name instead of the fallback
105- const expectedDemoUrl = 'https://example.com?organizationId=test-org-id#/@aem-sites-engineering/sites-optimizer/sites/test-site-id/home' ;
106- expect ( context . log . info . calledWith ( `Setup complete! Access your demo environment here: ${ expectedDemoUrl } ` ) ) . to . be . true ;
107- } ) ;
108-
109- it ( 'should fallback to name-based tenant when IMS_ORG_TENANT_ID_MAPPINGS mapping is not available' , async ( ) => {
110- // Don't set IMS_ORG_TENANT_ID_MAPPINGS secret
111- delete context . env . IMS_ORG_TENANT_ID_MAPPINGS ;
86+ // Set default tenant ID
87+ context . env . DEFAULT_TENANT_ID = 'default-tenant' ;
11288
11389 await runDemoUrlProcessor ( message , context ) ;
11490
115- // Should use the fallback name-based tenant (lowercase, no spaces)
116- const expectedDemoUrl = 'https://example.com?organizationId=test-org-id#/@adobesitesengineering/sites-optimizer/sites/test-site-id/home' ;
91+ // Should log error about missing name and use fallback
92+ expect ( context . log . error . calledWith ( 'Organization name is missing, using default tenant ID' ) ) . to . be . true ;
93+ const expectedDemoUrl = 'https://example.com?organizationId=test-org-id#/@default-tenant/sites-optimizer/sites/test-site-id/home' ;
11794 expect ( context . log . info . calledWith ( `Setup complete! Access your demo environment here: ${ expectedDemoUrl } ` ) ) . to . be . true ;
11895 } ) ;
11996
120- it ( 'should fallback to name-based tenant when IMS_ORG_TENANT_ID_MAPPINGS mapping is invalid JSON' , async ( ) => {
121- // Set invalid JSON in IMS_ORG_TENANT_ID_MAPPINGS secret
122- context . env . IMS_ORG_TENANT_ID_MAPPINGS = 'invalid-json' ;
97+ it ( 'should handle organization with missing tenantId property' , async ( ) => {
98+ // Mock Organization.findById to return organization without tenantId
99+ context . dataAccess . Organization . findById . resolves ( {
100+ name : 'Adobe Sites Engineering' ,
101+ imsOrgId : '8C6043F15F43B6390A49401A@AdobeOrg' ,
102+ // tenantId property is missing
103+ } ) ;
104+
105+ // Set default tenant ID
106+ context . env . DEFAULT_TENANT_ID = 'default-tenant' ;
123107
124108 await runDemoUrlProcessor ( message , context ) ;
125109
126- // Should use the fallback name-based tenant
127- const expectedDemoUrl = 'https://example.com?organizationId=test-org-id#/@adobesitesengineering/sites-optimizer/sites/test-site-id/home' ;
110+ // Should log error about missing name and use fallback
111+ expect ( context . log . error . calledWith ( 'Organization name is missing, using default tenant ID' ) ) . to . be . true ;
112+ const expectedDemoUrl = 'https://example.com?organizationId=test-org-id#/@default-tenant/sites-optimizer/sites/test-site-id/home' ;
128113 expect ( context . log . info . calledWith ( `Setup complete! Access your demo environment here: ${ expectedDemoUrl } ` ) ) . to . be . true ;
129114 } ) ;
130115
131- it ( 'should fallback to name-based tenant when IMS_ORG_TENANT_ID_MAPPINGS mapping does not contain the imsOrgId' , async ( ) => {
132- // Set IMS_ORG_TENANT_ID_MAPPINGS secret with different mapping
133- context . env . IMS_ORG_TENANT_ID_MAPPINGS = JSON . stringify ( {
134- 'DIFFERENT_ORG_ID@AdobeOrg' : 'different-team' ,
116+ it ( 'should use organization name when both name and tenantId are present' , async ( ) => {
117+ // Mock Organization.findById to return organization with both name and tenantId
118+ context . dataAccess . Organization . findById . resolves ( {
119+ name : 'Adobe Sites Engineering' ,
120+ tenantId : 'adobe-sites-engineering' ,
121+ imsOrgId : '8C6043F15F43B6390A49401A@AdobeOrg' ,
135122 } ) ;
136123
137124 await runDemoUrlProcessor ( message , context ) ;
138125
139- // Should use the fallback name-based tenant since the imsOrgId is not in the mapping
126+ // Should use the name-based tenant (lowercase, no spaces)
140127 const expectedDemoUrl = 'https://example.com?organizationId=test-org-id#/@adobesitesengineering/sites-optimizer/sites/test-site-id/home' ;
141128 expect ( context . log . info . calledWith ( `Setup complete! Access your demo environment here: ${ expectedDemoUrl } ` ) ) . to . be . true ;
142129 } ) ;
143130
144- it ( 'should handle organization not found error' , async ( ) => {
145- // Mock Organization.findById to return null
146- context . dataAccess . Organization . findById . resolves ( null ) ;
147-
148- await runDemoUrlProcessor ( message , context ) ;
149-
150- // Should log error and return early
151- expect ( context . log . error . calledWith ( 'Organization not found for organizationId: test-org-id' ) ) . to . be . true ;
152- // Should not log the success message
153- expect ( context . log . info . calledWithMatch ( sinon . match ( 'Setup complete!' ) ) ) . to . be . false ;
154- } ) ;
155-
156- it ( 'should handle organization with missing name property' , async ( ) => {
157- // Mock Organization.findById to return organization without name
131+ it ( 'should handle successful demo URL processing' , async ( ) => {
132+ // Mock Organization.findById to return organization with both name and tenantId
158133 context . dataAccess . Organization . findById . resolves ( {
134+ name : 'Adobe Sites Engineering' ,
135+ tenantId : 'adobe-sites-engineering' ,
159136 imsOrgId : '8C6043F15F43B6390A49401A@AdobeOrg' ,
160- // name property is missing
161137 } ) ;
162138
163- // Set default tenant ID
164- context . env . DEFAULT_TENANT_ID = 'default-tenant' ;
165-
166139 await runDemoUrlProcessor ( message , context ) ;
167140
168- // Should log error about missing name and use fallback
169- expect ( context . log . error . calledWith ( 'Organization name is missing, using default tenant ID' ) ) . to . be . true ;
170- const expectedDemoUrl = 'https://example.com?organizationId=test-org-id#/@default-tenant/sites-optimizer/sites/test-site-id/home' ;
141+ // Should log the processing message
142+ expect ( context . log . info . calledWith ( 'Processing demo url for site:' , {
143+ taskType : 'demo-url-processor' ,
144+ siteId : 'test-site-id' ,
145+ experienceUrl : 'https://example.com' ,
146+ organizationId : 'test-org-id' ,
147+ } ) ) . to . be . true ;
148+
149+ // Should log the completion message
150+ const expectedDemoUrl = 'https://example.com?organizationId=test-org-id#/@adobesitesengineering/sites-optimizer/sites/test-site-id/home' ;
171151 expect ( context . log . info . calledWith ( `Setup complete! Access your demo environment here: ${ expectedDemoUrl } ` ) ) . to . be . true ;
172152 } ) ;
173153 } ) ;
0 commit comments