Skip to content

Commit 0298a30

Browse files
committed
test: update functional tests to support new api
1 parent 83a7b4b commit 0298a30

12 files changed

Lines changed: 30 additions & 29 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- Refactored `fetchNumeric()`, `fetchAssociative()`, and `fetchOne()` across `Result`, `Connection`, `QueryBuilder`, portability wrappers, and all bundled drivers to return `undefined` instead of `false` when no row is available, and aligned unit tests and metadata-provider integrations with the new contract.
88
- Normalized bound query parameter values so `undefined` is treated as SQL `NULL` (`null`) before hitting driver statements, preventing mysql2 bind errors and aligning positional and named parameter flows.
9+
- Updated remaining functional tests to assert `undefined` (instead of `false`) for empty single-row `fetch*` results and no-row guards.
910

1011
# 1.1.1
1112

src/__tests__/functional/auto-increment-column.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe("Functional/AutoIncrementColumnTest", () => {
6464

6565
async function maxId(connection: Connection): Promise<number> {
6666
const value = await connection.fetchOne("SELECT MAX(id) FROM auto_increment_table");
67-
expect(value).not.toBe(false);
67+
expect(value).toBeDefined();
6868

6969
return Number(value);
7070
}

src/__tests__/functional/binary-data-access.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ describe("Functional/BinaryDataAccessTest", () => {
5454
stmt.bindValue(2, Buffer.from("c0def00d", "hex"), ParameterType.BINARY);
5555

5656
const row = lowerCaseKeys((await stmt.executeQuery()).fetchAssociative());
57-
expect(row).not.toBe(false);
57+
expect(row).toBeDefined();
5858
expect(Object.keys(row as Record<string, unknown>)).toEqual(["test_int", "test_binary"]);
5959
expect((row as Record<string, unknown>).test_int).toBe(1);
6060
expect(toBinaryBuffer((row as Record<string, unknown>).test_binary)).toEqual(
@@ -130,7 +130,7 @@ describe("Functional/BinaryDataAccessTest", () => {
130130
{ 1: ParameterType.BINARY },
131131
);
132132

133-
expect(row).not.toBe(false);
133+
expect(row).toBeDefined();
134134
const normalized = lowerCaseKeys(row);
135135
expect(normalized.test_int).toBe(1);
136136
expect(toBinaryBuffer(normalized.test_binary)).toEqual(Buffer.from("c0def00d", "hex"));
@@ -145,7 +145,7 @@ describe("Functional/BinaryDataAccessTest", () => {
145145
[ParameterType.STRING, Types.BINARY],
146146
);
147147

148-
expect(row).not.toBe(false);
148+
expect(row).toBeDefined();
149149
const normalized = lowerCaseKeys(row);
150150
expect(normalized.test_int).toBe(1);
151151
expect(toBinaryBuffer(normalized.test_binary)).toEqual(Buffer.from("c0def00d", "hex"));
@@ -160,7 +160,7 @@ describe("Functional/BinaryDataAccessTest", () => {
160160
{ 1: ParameterType.BINARY },
161161
);
162162

163-
expect(row).not.toBe(false);
163+
expect(row).toBeDefined();
164164
expect(row?.[0]).toBe(1);
165165
expect(toBinaryBuffer(row?.[1])).toEqual(Buffer.from("c0def00d", "hex"));
166166
});
@@ -174,7 +174,7 @@ describe("Functional/BinaryDataAccessTest", () => {
174174
[ParameterType.STRING, Types.BINARY],
175175
);
176176

177-
expect(row).not.toBe(false);
177+
expect(row).toBeDefined();
178178
expect(row?.[0]).toBe(1);
179179
expect(toBinaryBuffer(row?.[1])).toEqual(Buffer.from("c0def00d", "hex"));
180180
});
@@ -255,8 +255,8 @@ describe("Functional/BinaryDataAccessTest", () => {
255255
});
256256
});
257257

258-
function lowerCaseKeys(row: false | Record<string, unknown> | undefined): Record<string, unknown> {
259-
if (row === false || row === undefined) {
258+
function lowerCaseKeys(row: Record<string, unknown> | undefined): Record<string, unknown> {
259+
if (row === undefined) {
260260
throw new Error("Expected a row.");
261261
}
262262

src/__tests__/functional/blob.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ describe("Functional/BlobTest", () => {
148148
const blobs = await functional
149149
.connection()
150150
.fetchNumeric("SELECT blobcolumn1, blobcolumn2 FROM blob_table");
151-
expect(blobs).not.toBe(false);
151+
expect(blobs).toBeDefined();
152152

153153
const actual = (blobs ?? []).map((blob) => toText(blob));
154154
expect(actual).toEqual(["test1", "test2"]);

src/__tests__/functional/data-access.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ describe("Functional/DataAccessTest", () => {
129129
[1, "foo"],
130130
);
131131

132-
expect(row).not.toBe(false);
132+
expect(row).toBeDefined();
133133
const normalized = lowerCaseKeys(row);
134134
expect(normalized.test_int).toBe(1);
135135
expect(normalized.test_string).toBe("foo");
@@ -146,7 +146,7 @@ describe("Functional/DataAccessTest", () => {
146146
[ParameterType.STRING, Types.DATETIME_MUTABLE],
147147
);
148148

149-
expect(row).not.toBe(false);
149+
expect(row).toBeDefined();
150150
const normalized = lowerCaseKeys(row);
151151
expect(normalized.test_int).toBe(1);
152152
expect(normalizeDateTimeSecondPrecision(normalized.test_datetime)).toBe("2010-01-01 10:10:10");
@@ -160,7 +160,7 @@ describe("Functional/DataAccessTest", () => {
160160
[1, "foo"],
161161
);
162162

163-
expect(row).not.toBe(false);
163+
expect(row).toBeDefined();
164164
expect(row?.[0]).toBe(1);
165165
expect(row?.[1]).toBe("foo");
166166
});
@@ -176,7 +176,7 @@ describe("Functional/DataAccessTest", () => {
176176
[ParameterType.STRING, Types.DATETIME_MUTABLE],
177177
);
178178

179-
expect(row).not.toBe(false);
179+
expect(row).toBeDefined();
180180
expect(row?.[0]).toBe(1);
181181
expect(normalizeDateTimeSecondPrecision(row?.[1])).toBe("2010-01-01 10:10:10");
182182
});
@@ -420,12 +420,12 @@ async function assertDateExpression(
420420
bindParams(stmt, interval);
421421

422422
const date = (await stmt.executeQuery()).fetchOne();
423-
expect(date).not.toBe(false);
423+
expect(date).toBeDefined();
424424
expect(normalizeDateTimeSecondPrecision(date)).toBe(expected);
425425
}
426426

427-
function lowerCaseKeys(row: false | Record<string, unknown> | undefined): Record<string, unknown> {
428-
if (row === false || row === undefined) {
427+
function lowerCaseKeys(row: Record<string, unknown> | undefined): Record<string, unknown> {
428+
if (row === undefined) {
429429
throw new Error("Expected a row.");
430430
}
431431

src/__tests__/functional/platform/alter-column.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ describe("Functional/Platform/AlterColumnTest", () => {
8181
const hasIcuCollations =
8282
(await functional
8383
.connection()
84-
.fetchOne("SELECT 1 FROM pg_collation WHERE collprovider = 'icu'")) !== false;
84+
.fetchOne("SELECT 1 FROM pg_collation WHERE collprovider = 'icu'")) !== undefined;
8585
if (!hasIcuCollations) {
8686
skip();
8787
}

src/__tests__/functional/platform/default-expression.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ async function assertDefaultExpression(
6767
const row = await connection.fetchNumeric<[unknown, unknown]>(
6868
"SELECT default_value, actual_value FROM default_expr_test",
6969
);
70-
expect(row).not.toBe(false);
71-
if (row === false) {
70+
expect(row).toBeDefined();
71+
if (row === undefined) {
7272
return;
7373
}
7474

src/__tests__/functional/platform/quoting.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ describe("Functional/Platform/QuotingTest", () => {
2828
);
2929
const row = await functional.connection().fetchAssociative(query);
3030

31-
expect(row).not.toBe(false);
32-
if (row === false) {
31+
expect(row).toBeDefined();
32+
if (row === undefined) {
3333
return;
3434
}
3535

src/__tests__/functional/result.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ describe("Functional/ResultTest", () => {
1515
[
1616
"fetchNumeric",
1717
(result: Awaited<ReturnType<typeof connection.executeQuery>>) => result.fetchNumeric(),
18-
false,
18+
undefined,
1919
],
2020
[
2121
"fetchAssociative",
2222
(result: Awaited<ReturnType<typeof connection.executeQuery>>) => result.fetchAssociative(),
23-
false,
23+
undefined,
2424
],
2525
[
2626
"fetchOne",
2727
(result: Awaited<ReturnType<typeof connection.executeQuery>>) => result.fetchOne(),
28-
false,
28+
undefined,
2929
],
3030
[
3131
"fetchAllNumeric",

src/__tests__/functional/schema/postgre-sql/schema.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ describe("Functional/Schema/PostgreSQL/SchemaTest", () => {
4444
["my_table"],
4545
);
4646

47-
expect(row).not.toBe(false);
48-
if (row === false) {
47+
expect(row).toBeDefined();
48+
if (row === undefined) {
4949
return;
5050
}
5151

0 commit comments

Comments
 (0)