Skip to content

Commit 21d6d3d

Browse files
committed
test(schema-compiler): Add missing numeric types to ScaffoldingSchema columnType mapping
1 parent 23ea22b commit 21d6d3d

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

packages/cubejs-schema-compiler/test/unit/scaffolding-schema.test.ts

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,4 +554,105 @@ describe('ScaffoldingSchema', () => {
554554
}
555555
]);
556556
});
557+
558+
describe('columnType mapping for numeric types', () => {
559+
it('should map FLOAT types to number', () => {
560+
const schemas = {
561+
public: {
562+
test: [
563+
{ name: 'float_col', type: 'FLOAT', attributes: [] },
564+
{ name: 'float4_col', type: 'FLOAT4', attributes: [] },
565+
{ name: 'float8_col', type: 'FLOAT8', attributes: [] },
566+
{ name: 'float32_col', type: 'FLOAT32', attributes: [] },
567+
{ name: 'float64_col', type: 'FLOAT64', attributes: [] },
568+
]
569+
}
570+
};
571+
const schema = new ScaffoldingSchema(schemas);
572+
schemas.public.test.forEach(col => {
573+
expect(schema['columnType'](col)).toBe('number');
574+
});
575+
});
576+
577+
it('should map REAL type to number', () => {
578+
const schemas = {
579+
public: {
580+
test: [{ name: 'real_col', type: 'REAL', attributes: [] }]
581+
}
582+
};
583+
const schema = new ScaffoldingSchema(schemas);
584+
expect(schema['columnType'](schemas.public.test[0])).toBe('number');
585+
});
586+
587+
it('should map SERIAL types to number', () => {
588+
const schemas = {
589+
public: {
590+
test: [
591+
{ name: 'serial_col', type: 'SERIAL', attributes: [] },
592+
{ name: 'bigserial_col', type: 'BIGSERIAL', attributes: [] },
593+
{ name: 'smallserial_col', type: 'SMALLSERIAL', attributes: [] },
594+
]
595+
}
596+
};
597+
const schema = new ScaffoldingSchema(schemas);
598+
schemas.public.test.forEach(col => {
599+
expect(schema['columnType'](col)).toBe('number');
600+
});
601+
});
602+
603+
it('should map MONEY types to number', () => {
604+
const schemas = {
605+
public: {
606+
test: [
607+
{ name: 'money_col', type: 'MONEY', attributes: [] },
608+
{ name: 'smallmoney_col', type: 'SMALLMONEY', attributes: [] },
609+
]
610+
}
611+
};
612+
const schema = new ScaffoldingSchema(schemas);
613+
schemas.public.test.forEach(col => {
614+
expect(schema['columnType'](col)).toBe('number');
615+
});
616+
});
617+
618+
it('should map various integer types to number (covered by int keyword)', () => {
619+
const schemas = {
620+
public: {
621+
test: [
622+
// Standard integer types
623+
{ name: 'tinyint_col', type: 'TINYINT', attributes: [] },
624+
{ name: 'mediumint_col', type: 'MEDIUMINT', attributes: [] },
625+
{ name: 'hugeint_col', type: 'HUGEINT', attributes: [] },
626+
// Unsigned integer types
627+
{ name: 'uint8_col', type: 'UINT8', attributes: [] },
628+
{ name: 'uint32_col', type: 'UINT32', attributes: [] },
629+
{ name: 'uinteger_col', type: 'UINTEGER', attributes: [] },
630+
{ name: 'ubigint_col', type: 'UBIGINT', attributes: [] },
631+
// Other variants
632+
{ name: 'byteint_col', type: 'BYTEINT', attributes: [] },
633+
]
634+
}
635+
};
636+
const schema = new ScaffoldingSchema(schemas);
637+
schemas.public.test.forEach(col => {
638+
expect(schema['columnType'](col)).toBe('number');
639+
});
640+
});
641+
642+
it('should be case insensitive for type matching', () => {
643+
const schemas = {
644+
public: {
645+
test: [
646+
{ name: 'float_lower', type: 'float', attributes: [] },
647+
{ name: 'float_upper', type: 'FLOAT', attributes: [] },
648+
{ name: 'float_mixed', type: 'Float', attributes: [] },
649+
]
650+
}
651+
};
652+
const schema = new ScaffoldingSchema(schemas);
653+
schemas.public.test.forEach(col => {
654+
expect(schema['columnType'](col)).toBe('number');
655+
});
656+
});
657+
});
557658
});

0 commit comments

Comments
 (0)