mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2024-12-05 02:10:18 +00:00
Fix issue when undefined or missing object entries were incorrectly converted to aqua (#140)
This commit is contained in:
parent
a0a7a9e19b
commit
4910901dc9
@ -185,3 +185,39 @@ describe('Conversion from aqua to typescript', () => {
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe('Conversion corner cases', () => {
|
||||
it('Should accept undefined in object entry', () => {
|
||||
// arrange
|
||||
const type = {
|
||||
tag: 'labeledProduct',
|
||||
fields: {
|
||||
x: opt_i32,
|
||||
y: opt_i32,
|
||||
},
|
||||
} as const;
|
||||
|
||||
const valueInTs = {
|
||||
x: 1,
|
||||
};
|
||||
const valueInAqua = {
|
||||
x: [1],
|
||||
y: [],
|
||||
};
|
||||
|
||||
// act
|
||||
const aqua = ts2aqua(valueInTs, type);
|
||||
const ts = aqua2ts(valueInAqua, type);
|
||||
|
||||
// assert
|
||||
expect(aqua).toStrictEqual({
|
||||
x: [1],
|
||||
y: [],
|
||||
});
|
||||
|
||||
expect(ts).toStrictEqual({
|
||||
x: 1,
|
||||
y: null,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -96,7 +96,7 @@ export const ts2aqua = (value: any, type: NonArrowType) => {
|
||||
return null;
|
||||
})
|
||||
.with({ tag: 'option' }, (opt) => {
|
||||
if (value === null) {
|
||||
if (value === null || value === undefined) {
|
||||
return [];
|
||||
} else {
|
||||
return [ts2aqua(value, opt.type)];
|
||||
|
Loading…
Reference in New Issue
Block a user