Skip to content

Commit ace49aa

Browse files
add tests
1 parent 9a04b85 commit ace49aa

File tree

1 file changed

+73
-22
lines changed

1 file changed

+73
-22
lines changed

test/tasks/demo-url-processor/demo-url-processor.test.js

Lines changed: 73 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ describe('Demo URL Processor', () => {
4141
Organization: {
4242
findById: sandbox.stub().resolves({
4343
name: 'Adobe Sites Engineering',
44+
tenantId: 'adobe-sites-engineering',
4445
imsOrgId: '8C6043F15F43B6390A49401A@AdobeOrg',
4546
}),
4647
},
@@ -54,7 +55,10 @@ describe('Demo URL Processor', () => {
5455
organizationId: 'test-org-id',
5556
taskContext: {
5657
experienceUrl: 'https://example.com',
57-
slackContext: 'test-slack-context',
58+
slackContext: {
59+
channelId: 'test-channel',
60+
threadTs: 'test-thread',
61+
},
5862
},
5963
};
6064
});
@@ -76,45 +80,56 @@ describe('Demo URL Processor', () => {
7680
expect(context.log.info.calledWithMatch(sinon.match('Setup complete!'))).to.be.false;
7781
});
7882

79-
it('should handle organization with missing name property', async () => {
80-
// Mock Organization.findById to return organization without name
83+
it('should use tenantId when available (highest priority)', async () => {
84+
// Mock Organization.findById to return organization with tenantId
8185
context.dataAccess.Organization.findById.resolves({
86+
name: 'Adobe Sites Engineering',
87+
tenantId: 'adobe-sites-engineering',
8288
imsOrgId: '8C6043F15F43B6390A49401A@AdobeOrg',
83-
// name property is missing
8489
});
8590

86-
// Set default tenant ID
87-
context.env.DEFAULT_TENANT_ID = 'default-tenant';
88-
8991
await runDemoUrlProcessor(message, context);
9092

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';
93+
// Should use the tenantId (highest priority)
94+
const expectedDemoUrl = 'https://example.com?organizationId=test-org-id#/@adobe-sites-engineering/sites-optimizer/sites/test-site-id/home';
9495
expect(context.log.info.calledWith(`Setup complete! Access your demo environment here: ${expectedDemoUrl}`)).to.be.true;
9596
});
9697

97-
it('should handle organization with missing tenantId property', async () => {
98-
// Mock Organization.findById to return organization without tenantId
98+
it('should fallback to name when tenantId is missing (backward compatibility)', async () => {
99+
// Mock Organization.findById to return organization with name but no tenantId
99100
context.dataAccess.Organization.findById.resolves({
100101
name: 'Adobe Sites Engineering',
101102
imsOrgId: '8C6043F15F43B6390A49401A@AdobeOrg',
102103
// tenantId property is missing
103104
});
104105

106+
await runDemoUrlProcessor(message, context);
107+
108+
// Should use the name-based tenant (lowercase, no spaces) as fallback
109+
const expectedDemoUrl = 'https://example.com?organizationId=test-org-id#/@adobesitesengineering/sites-optimizer/sites/test-site-id/home';
110+
expect(context.log.info.calledWith(`Setup complete! Access your demo environment here: ${expectedDemoUrl}`)).to.be.true;
111+
});
112+
113+
it('should fallback to DEFAULT_TENANT_ID when both name and tenantId are missing', async () => {
114+
// Mock Organization.findById to return organization without name and tenantId
115+
context.dataAccess.Organization.findById.resolves({
116+
imsOrgId: '8C6043F15F43B6390A49401A@AdobeOrg',
117+
// name and tenantId properties are missing
118+
});
119+
105120
// Set default tenant ID
106121
context.env.DEFAULT_TENANT_ID = 'default-tenant';
107122

108123
await runDemoUrlProcessor(message, context);
109124

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;
125+
// Should log error about missing name and tenantId and use fallback
126+
expect(context.log.error.calledWith('Organization name and tenantId are missing, using default tenant ID')).to.be.true;
112127
const expectedDemoUrl = 'https://example.com?organizationId=test-org-id#/@default-tenant/sites-optimizer/sites/test-site-id/home';
113128
expect(context.log.info.calledWith(`Setup complete! Access your demo environment here: ${expectedDemoUrl}`)).to.be.true;
114129
});
115130

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
131+
it('should handle successful demo URL processing with tenantId', async () => {
132+
// Mock Organization.findById to return organization with tenantId
118133
context.dataAccess.Organization.findById.resolves({
119134
name: 'Adobe Sites Engineering',
120135
tenantId: 'adobe-sites-engineering',
@@ -123,17 +138,25 @@ describe('Demo URL Processor', () => {
123138

124139
await runDemoUrlProcessor(message, context);
125140

126-
// Should use the name-based tenant (lowercase, no spaces)
127-
const expectedDemoUrl = 'https://example.com?organizationId=test-org-id#/@adobesitesengineering/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#/@adobe-sites-engineering/sites-optimizer/sites/test-site-id/home';
128151
expect(context.log.info.calledWith(`Setup complete! Access your demo environment here: ${expectedDemoUrl}`)).to.be.true;
129152
});
130153

131-
it('should handle successful demo URL processing', async () => {
132-
// Mock Organization.findById to return organization with both name and tenantId
154+
it('should handle successful demo URL processing with name fallback', async () => {
155+
// Mock Organization.findById to return organization with name but no tenantId
133156
context.dataAccess.Organization.findById.resolves({
134157
name: 'Adobe Sites Engineering',
135-
tenantId: 'adobe-sites-engineering',
136158
imsOrgId: '8C6043F15F43B6390A49401A@AdobeOrg',
159+
// tenantId property is missing
137160
});
138161

139162
await runDemoUrlProcessor(message, context);
@@ -146,9 +169,37 @@ describe('Demo URL Processor', () => {
146169
organizationId: 'test-org-id',
147170
})).to.be.true;
148171

149-
// Should log the completion message
172+
// Should log the completion message with name-based tenant
150173
const expectedDemoUrl = 'https://example.com?organizationId=test-org-id#/@adobesitesengineering/sites-optimizer/sites/test-site-id/home';
151174
expect(context.log.info.calledWith(`Setup complete! Access your demo environment here: ${expectedDemoUrl}`)).to.be.true;
152175
});
176+
177+
it('should handle successful demo URL processing with DEFAULT_TENANT_ID fallback', async () => {
178+
// Mock Organization.findById to return organization without name and tenantId
179+
context.dataAccess.Organization.findById.resolves({
180+
imsOrgId: '8C6043F15F43B6390A49401A@AdobeOrg',
181+
// name and tenantId properties are missing
182+
});
183+
184+
// Set default tenant ID
185+
context.env.DEFAULT_TENANT_ID = 'default-tenant';
186+
187+
await runDemoUrlProcessor(message, context);
188+
189+
// Should log the processing message
190+
expect(context.log.info.calledWith('Processing demo url for site:', {
191+
taskType: 'demo-url-processor',
192+
siteId: 'test-site-id',
193+
experienceUrl: 'https://example.com',
194+
organizationId: 'test-org-id',
195+
})).to.be.true;
196+
197+
// Should log error about missing name and tenantId
198+
expect(context.log.error.calledWith('Organization name and tenantId are missing, using default tenant ID')).to.be.true;
199+
200+
// Should log the completion message with default tenant
201+
const expectedDemoUrl = 'https://example.com?organizationId=test-org-id#/@default-tenant/sites-optimizer/sites/test-site-id/home';
202+
expect(context.log.info.calledWith(`Setup complete! Access your demo environment here: ${expectedDemoUrl}`)).to.be.true;
203+
});
153204
});
154205
});

0 commit comments

Comments
 (0)