Skip to content

Commit

Permalink
remove unintended cases for formatter and convert
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Luu committed Jun 3, 2024
1 parent 12b198b commit b9617ee
Showing 1 changed file with 1 addition and 109 deletions.
110 changes: 1 addition & 109 deletions packages/web3-utils/test/unit/formatter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -855,76 +855,7 @@ describe('formatter', () => {
});

describe('convert', () => {
it('should convert array values correctly when schema is an array and items are objects', () => {
const schema = {
type: 'object',
properties: {
transactions: {
type: 'array',
oneOf: [
{
items: {
type: 'object',
properties: {
address: { format: 'string' },
value: { type: 'string' },
},
},
},
{
items: {
type: 'object',
properties: {
address: { format: 'string' },
value: { type: 'number' },
},
},
},
],
},
},
};
const data = {
transactions: [
{ address: 'B', value: '42' },
{ address: 'B', value: 43 },
],
};
expect(
convert(data, schema, [], {
number: FMT_NUMBER.HEX,
bytes: FMT_BYTES.HEX,
}),
).toEqual(data);
});

it('should delete the array property if schema for array items is nullish', () => {
const schema = {
type: 'object',
properties: {
transactions: {
type: 'array',
items: undefined, // Simulate a missing or null schema for items
},
},
};

const data = {
transactions: [
{ type: 'A', value: 'some string' },
{ type: 'B', value: 42 },
],
};

const result = convert(data, schema, [], {
number: FMT_NUMBER.HEX,
bytes: FMT_BYTES.HEX,
});

expect(result).toEqual({});
});

it('should return empty when no proerties or items', () => {
it('should return empty when no properties or items', () => {
const data = { key: 'value' };
const schema = {
type: 'object',
Expand All @@ -933,44 +864,5 @@ describe('formatter', () => {
const result = convert(data, schema, [], f, []);
expect(result).toEqual({});
});

it('should format nested objects with oneOf', () => {
const schema = {
type: 'object',
properties: {
details: {
type: 'object',
oneOf: [
{ properties: { type: { enum: ['A'] }, value: { type: 'string' } } },
{ properties: { type: { enum: ['B'] }, value: { type: 'number' } } },
],
},
},
};

const data = {
details: {
type: 'B',
value: 42,
},
};
const result = convert(
data,
schema,
[],
{
number: FMT_NUMBER.BIGINT,
bytes: FMT_BYTES.UINT8ARRAY,
},
[['details', 1]],
);

expect(result).toEqual({
details: {
type: 'B',
value: 42,
},
});
});
});
});

0 comments on commit b9617ee

Please sign in to comment.