Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance testing by increasing test coverage #3

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions tests/insert_update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,66 @@ test("update table", async () => {
expect(res.length).toBe(1);
expect(res[0].numUpdatedRows).toBe(BigInt(1));
});

// Additional tests for edge cases and potential error scenarios

test("insert with missing fields", async () => {
const kysely = await setupDb();

const res = await kysely.insertInto("t1")
.values([{
a: 3,
}])
.execute();

expect(res.length).toBe(1);
expect(res[0].numInsertedOrUpdatedRows).toBe(BigInt(1));

const selectRes = await kysely.selectFrom("t1").selectAll().execute();
expect(selectRes.length).toBe(3);
});

test("insert with null values", async () => {
const kysely = await setupDb();

const res = await kysely.insertInto("t1")
.values([{
a: null,
b: 4,
}])
.execute();

expect(res.length).toBe(1);
expect(res[0].numInsertedOrUpdatedRows).toBe(BigInt(1));

const selectRes = await kysely.selectFrom("t1").selectAll().execute();
expect(selectRes.length).toBe(3);
});

test("update with non-existing condition", async () => {
const kysely = await setupDb();

const res = await kysely.updateTable("t1")
.set({
a: 20,
})
.where("a", "=", 100)
.execute();

expect(res.length).toBe(1);
expect(res[0].numUpdatedRows).toBe(BigInt(0));
});

test("update with null values", async () => {
const kysely = await setupDb();

const res = await kysely.updateTable("t1")
.set({
a: null,
})
.where("a", "=", 1)
.execute();

expect(res.length).toBe(1);
expect(res[0].numUpdatedRows).toBe(BigInt(1));
});
61 changes: 61 additions & 0 deletions tests/select.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,64 @@ test("select complex data types with where", async () => {
.execute();
expect(results.length).toBe(1);
});

// Additional tests for edge cases and potential error scenarios

test("select with non-existing condition", async () => {
const kysely = await setupDb();

const results = await kysely
.selectFrom("t1")
.selectAll()
.where("a", "=", 100)
.execute();
expect(results.length).toBe(0);
});

test("select with null values", async () => {
const kysely = await setupDb();

const results = await kysely
.selectFrom("t1")
.selectAll()
.where("a", "is", null)
.execute();
expect(results.length).toBe(0);
});

test("select with multiple conditions", async () => {
const kysely = await setupDb();

const results = await kysely
.selectFrom("t1")
.selectAll()
.where("a", "=", 1)
.where("b", "=", 2)
.execute();
expect(results.length).toBe(1);
expect(results[0]).toEqual({ a: 1, b: 2 });
});

test("select with order by", async () => {
const kysely = await setupDb();

const results = await kysely
.selectFrom("t1")
.selectAll()
.orderBy("a", "desc")
.execute();
expect(results.length).toBe(1);
expect(results[0]).toEqual({ a: 1, b: 2 });
});

test("select with limit", async () => {
const kysely = await setupDb();

const results = await kysely
.selectFrom("t1")
.selectAll()
.limit(1)
.execute();
expect(results.length).toBe(1);
expect(results[0]).toEqual({ a: 1, b: 2 });
});
5 changes: 5 additions & 0 deletions tests/test_common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,10 @@ export const setupDb = async () => {
].join(", ") + ");",
));

// Additional test data for edge cases and potential error scenarios
await kysely.executeQuery(CompiledQuery.raw("INSERT INTO t1 VALUES (3, NULL);"));
await kysely.executeQuery(CompiledQuery.raw("INSERT INTO t1 VALUES (NULL, 4);"));
await kysely.executeQuery(CompiledQuery.raw("INSERT INTO t1 VALUES (5, 6);"));

return kysely;
};
Loading