File size: 1,960 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
import { expect } from 'chai'
import { convertNestedParam } from './convert-nested-param.js'
const jsonField = {
number: '123',
date: '2020-11-08',
nested: {
number: '456',
},
nestedList: [{
number: '789',
}, {
number: '111',
}],
}
describe('module:paramConverter.convertNestedParam', () => {
it('should convert number property of a JSON to actual number', () => {
const property = {
type: 'number',
propertyPath: 'jsonField.number',
subProperties: [],
}
const convertedJson = convertNestedParam(jsonField, property as any)
expect(convertedJson.number).to.equal(123)
})
it('should convert date property of a JSON to actual number', () => {
const property = {
type: 'datetime',
propertyPath: 'jsonField.date',
subProperties: [],
}
const convertedJson = convertNestedParam(jsonField, property as any)
expect(convertedJson.date.getTime()).to.equal(new Date('2020-11-08').getTime())
})
it('should convert a nested json property\'s number string to actual number', () => {
const property = {
type: 'mixed',
propertyPath: 'jsonField.nested',
isArray: false,
subProperties: [{
propertyPath: 'jsonField.nested.number',
type: 'number',
}],
}
const convertedJson = convertNestedParam(jsonField, property as any)
expect(convertedJson.nested.number).to.equal(456)
})
it('should convert a nested json array property\'s number string to actual number', () => {
const property = {
type: 'mixed',
propertyPath: 'jsonField.nestedList',
isArray: true,
subProperties: [{
propertyPath: 'jsonField.nestedList.number',
type: 'number',
}],
}
const convertedJson = convertNestedParam(jsonField, property as any)
expect(convertedJson.nestedList[0].number).to.equal(789)
expect(convertedJson.nestedList[1].number).to.equal(111)
})
})
|