Skip to content

Commit

Permalink
Use services details if present in config (#450)
Browse files Browse the repository at this point in the history
These details can also be set as env var and need to be converted to json object from string for such cases.
Added unit tests
  • Loading branch information
sandeep-paliwal authored Aug 5, 2021
1 parent 6214800 commit d1d645c
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 10 deletions.
27 changes: 18 additions & 9 deletions src/lib/app-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,15 +379,24 @@ function setOrgServicesConfig (supportedServices) {
* @returns {object} op['view'] metadata OR null
*/
async function buildExcShellViewExtensionMetadata (libConsoleCLI, aioConfig) {
const serviceProperties = await libConsoleCLI.getServicePropertiesFromWorkspace(
aioConfig.project.org.id,
aioConfig.project.id,
aioConfig.project.workspace
)
const services = serviceProperties.map(s => ({
name: s.name,
code: s.sdkCode
}))
let serviceProperties
let services
if (aioConfig.project.workspace.details) {
serviceProperties = aioConfig.project.workspace.details.services
}
if (serviceProperties) {
services = (Array.isArray(serviceProperties)) ? serviceProperties : JSON.parse(serviceProperties)
} else {
serviceProperties = await libConsoleCLI.getServicePropertiesFromWorkspace(
aioConfig.project.org.id,
aioConfig.project.id,
aioConfig.project.workspace
)
services = serviceProperties.map(s => ({
name: s.name,
code: s.sdkCode
}))
}
return {
services: Object.assign([], services),
profile: {
Expand Down
87 changes: 86 additions & 1 deletion test/commands/lib/app-helper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ test('setOrgServicesConfig', () => {
})

describe('buildExcShellViewExtensionMetadata', () => {
test('with service properties', async () => {
test('with service properties from console', async () => {
const mockConsoleCLIInstance = {
getServicePropertiesFromWorkspace: jest.fn()
}
Expand Down Expand Up @@ -604,6 +604,91 @@ describe('buildExcShellViewExtensionMetadata', () => {
})
expect(mockConsoleCLIInstance.getServicePropertiesFromWorkspace).toHaveBeenCalledWith('hola', 'bonjour', { id: 'yay', name: 'yo' })
})

test('with service properties in config', async () => {
const mockConsoleCLIInstance = {
getServicePropertiesFromWorkspace: jest.fn()
}
const mockAIOConfig = {
project: {
org: {
id: 'hola'
},
workspace: {
id: 'yay',
name: 'yo',
details: {
services: [
{
code: 'service1code',
name: 'service1'
},
{
code: 'service2code',
name: 'service2'
}
]
}
},
id: 'bonjour'
}
}
const res = await appHelper.buildExcShellViewExtensionMetadata(mockConsoleCLIInstance, mockAIOConfig)
expect(res).toEqual({
services: [
{ name: 'service1', code: 'service1code' },
{ name: 'service2', code: 'service2code' }
],
profile: {
client_id: 'firefly-app',
scope: 'ab.manage,additional_info.job_function,additional_info.projectedProductContext,additional_info.roles,additional_info,AdobeID,adobeio_api,adobeio.appregistry.read,audiencemanager_api,creative_cloud,mps,openid,read_organizations,read_pc.acp,read_pc.dma_tartan,read_pc,session'
}
})
expect(mockConsoleCLIInstance.getServicePropertiesFromWorkspace).toHaveBeenCalledTimes(0)
})

test('with service properties set as string', async () => {
const services = JSON.stringify([
{
code: 'service1code',
name: 'service1'
},
{
code: 'service2code',
name: 'service2'
}
])
const mockConsoleCLIInstance = {
getServicePropertiesFromWorkspace: jest.fn()
}
const mockAIOConfig = {
project: {
org: {
id: 'hola'
},
workspace: {
id: 'yay',
name: 'yo',
details: {
services: services
}
},
id: 'bonjour'
}
}
const res = await appHelper.buildExcShellViewExtensionMetadata(mockConsoleCLIInstance, mockAIOConfig)
expect(res).toEqual({
services: [
{ name: 'service1', code: 'service1code' },
{ name: 'service2', code: 'service2code' }
],
profile: {
client_id: 'firefly-app',
scope: 'ab.manage,additional_info.job_function,additional_info.projectedProductContext,additional_info.roles,additional_info,AdobeID,adobeio_api,adobeio.appregistry.read,audiencemanager_api,creative_cloud,mps,openid,read_organizations,read_pc.acp,read_pc.dma_tartan,read_pc,session'
}
})
expect(mockConsoleCLIInstance.getServicePropertiesFromWorkspace).toHaveBeenCalledTimes(0)
})
})

describe('buildExtensionPointPayloadWoMetadata', () => {
Expand Down

0 comments on commit d1d645c

Please sign in to comment.