Closed pe1pip closed 1 year ago
Should be fixed
@Michaelpalacce it seems you actually broke more than you fixed. Following test (demo.test.ts) works as expected in 2.33.0, but throws in 2.34.0:
function getConfigurationElementByPath (path: string, name: string): ConfigurationElement {
const configurationElementCategory = Server.getConfigurationElementCategoryWithPath(path)
const configurationElements = configurationElementCategory.allConfigurationElements
const configurationElement = configurationElements.filter(function (configurationElement) {
return configurationElement.name === name
})
if (configurationElement.length !== 1) {
throw new Error('too many or zero matches')
}
return configurationElement[0]
}
function demo (): string {
const environment = getConfigurationElementByPath('web-root', 'Environment')
return `demo${environment.getAttributeWithKey('demo').value as string}`
}
describe('demo test', () => {
beforeEach(() => {
const envCfg = Server.createConfigurationElement('web-root', 'Environment')
envCfg.setAttributeWithKey('demo', 'Mock', 'string')
})
afterEach(() => {
Server.removeConfigurationElementCategory(Server.getConfigurationElementCategoryWithPath('web-root')) // cleanup all cfgElements
})
it('x', () => {
expect(demo()).toBe('demoMock')
})
})
expected behaviour is environment.getAttributeWithKey('demo').value
to equal 'Mock', but environment.getAttributeWithKey()
returns null, even if the attribute exists.
Description
The mocking for configuration elements is incorrect. When there are no attributes in a config element vRO returns null when the attributes of a config element is accessed, in vRBT the mocking returns an empty array. Similarly, the Server.getConfigurationElementCategoryWithPath() should return null for a non-existent category and category.configurationElements should return null for an empty category.
Note that behaviour of category.allConfigurationElements is different, this returns an empty array if there are zero elements in a category.
Steps to Reproduce
inspect this code in 'typescript/vro-scripting-api/src/configurations.ts':
in vRO run:
Output:
Preconditions: [What are the preconditions to reproduce the issue]
Expected behavior:
mocking to return null when no attributes are present in a configuration element.
Actual behavior:
Mocking returns []
Reproduces how often: 100%
Component/s:
Affects Build/s: 2.32.0
Environment
Client
Server
Failure Logs
Related issues and PRs
n/a
Additional Context
n/a