Skip to content

Commit

Permalink
fix(core): cannot add productInfo to hawtconfig when about is absent
Browse files Browse the repository at this point in the history
Fix #715
  • Loading branch information
tadayosi committed Feb 20, 2024
1 parent 08034bf commit 47d7d15
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
18 changes: 18 additions & 0 deletions packages/hawtio/src/core/config-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,22 @@ describe('ConfigManager', () => {
expect(product3?.name).toEqual('Hawtio React')
expect(product3?.value).toEqual('1.0.0')
})

test('adds product info to empty config', async () => {
// response for fetching hawtconfig.json
fetchMock.mockResponse(JSON.stringify({}))

configManager.addProductInfo('Hawtio React', '1.0.0')
const config = await configManager.getHawtconfig()
expect(config.about).not.toBeUndefined()
expect(config.about?.productInfo).toHaveLength(1)
expect(config.about?.title).toBeUndefined()
expect(config.about?.description).toBeUndefined()
expect(config.about?.imgSrc).toBeUndefined()
expect(config.about?.copyright).toBeUndefined()

const product = config.about?.productInfo?.[0]
expect(product?.name).toEqual('Hawtio React')
expect(product?.value).toEqual('1.0.0')
})
})
10 changes: 8 additions & 2 deletions packages/hawtio/src/core/config-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,14 @@ class ConfigManager {
}

async addProductInfo(name: string, value: string) {
const { about } = await this.getHawtconfig()
about?.productInfo?.push({ name, value })
const config = await this.getHawtconfig()
if (!config.about) {
config.about = {}
}
if (!config.about.productInfo) {
config.about.productInfo = []
}
config.about.productInfo.push({ name, value })
}
}

Expand Down

0 comments on commit 47d7d15

Please sign in to comment.