|
| 1 | +import { Firebolt } from "../../../src/index"; |
| 2 | +import BigNumber from "bignumber.js"; |
| 3 | + |
| 4 | +const connectionParams = { |
| 5 | + auth: { |
| 6 | + client_id: process.env.FIREBOLT_CLIENT_ID as string, |
| 7 | + client_secret: process.env.FIREBOLT_CLIENT_SECRET as string |
| 8 | + }, |
| 9 | + account: process.env.FIREBOLT_ACCOUNT as string, |
| 10 | + database: process.env.FIREBOLT_DATABASE as string |
| 11 | +}; |
| 12 | + |
| 13 | +jest.setTimeout(100000); |
| 14 | + |
| 15 | +describe("test type casting on fetch", () => { |
| 16 | + it("select boolean", async () => { |
| 17 | + const firebolt = Firebolt({ |
| 18 | + apiEndpoint: process.env.FIREBOLT_API_ENDPOINT as string |
| 19 | + }); |
| 20 | + |
| 21 | + const connection = await firebolt.connect(connectionParams); |
| 22 | + |
| 23 | + const statement = await connection.execute("select true::boolean"); |
| 24 | + |
| 25 | + const { data, meta } = await statement.fetchResult(); |
| 26 | + expect(meta[0].type).toEqual("boolean"); |
| 27 | + const row = data[0]; |
| 28 | + expect((row as unknown[])[0]).toEqual(true); |
| 29 | + }); |
| 30 | + it("select bigint", async () => { |
| 31 | + const firebolt = Firebolt({ |
| 32 | + apiEndpoint: process.env.FIREBOLT_API_ENDPOINT as string |
| 33 | + }); |
| 34 | + |
| 35 | + const connection = await firebolt.connect(connectionParams); |
| 36 | + |
| 37 | + // Max value for a signed 64-bit integer (bigint) |
| 38 | + const statement = await connection.execute("select 9223372036854775807"); |
| 39 | + |
| 40 | + const { data, meta } = await statement.fetchResult(); |
| 41 | + expect(meta[0].type).toEqual("long"); |
| 42 | + const row = data[0]; |
| 43 | + expect((row as unknown[])[0]).toEqual(new BigNumber("9223372036854775807")); |
| 44 | + }); |
| 45 | + it("select negative bigint", async () => { |
| 46 | + const firebolt = Firebolt({ |
| 47 | + apiEndpoint: process.env.FIREBOLT_API_ENDPOINT as string |
| 48 | + }); |
| 49 | + |
| 50 | + const connection = await firebolt.connect(connectionParams); |
| 51 | + |
| 52 | + // Max negative value for a signed 64-bit integer (bigint) |
| 53 | + const statement = await connection.execute("select -9223372036854775808"); |
| 54 | + |
| 55 | + const { data, meta } = await statement.fetchResult(); |
| 56 | + expect(meta[0].type).toEqual("long"); |
| 57 | + const row = data[0]; |
| 58 | + expect((row as unknown[])[0]).toEqual( |
| 59 | + new BigNumber("-9223372036854775808") |
| 60 | + ); |
| 61 | + }); |
| 62 | +}); |
0 commit comments