aboutsummaryrefslogtreecommitdiff
path: root/test/database_test.ts
diff options
context:
space:
mode:
authorMarvin Borner2020-07-18 18:34:32 +0200
committerMarvin Borner2020-07-18 18:34:32 +0200
commit26f84c953f9fbb9c5afb4f8a063759d272256f36 (patch)
tree653e4beb8353ed05dc800d67061502ea5abdcae4 /test/database_test.ts
parentecbb3c7420ebb63d9a870760df602b27cef82939 (diff)
More database tests!
Diffstat (limited to 'test/database_test.ts')
-rw-r--r--test/database_test.ts74
1 files changed, 69 insertions, 5 deletions
diff --git a/test/database_test.ts b/test/database_test.ts
index ca2e5b0..07c5443 100644
--- a/test/database_test.ts
+++ b/test/database_test.ts
@@ -1,7 +1,71 @@
-import { assertEquals, assertArrayContains } from "https://deno.land/std/testing/asserts.ts";
+import "https://deno.land/x/dotenv/load.ts";
+import { assertThrowsAsync } from "https://deno.land/std/testing/asserts.ts";
+import { Client } from "https://deno.land/x/mysql/mod.ts";
+import DBController from "../src/db/DBController.ts";
-Deno.test("hello world", () => {
- const x = 1 + 2;
- assertEquals(x, 3);
- assertArrayContains([1, 2, 3, 4, 5, 6], [3], "Expected 3 to be in the array");
+const controller = new DBController();
+
+Deno.test("database connection", async () => {
+ await controller.connect();
+});
+
+Deno.test({
+ name: "database initialization",
+ sanitizeOps: false, // TODO: Find async leak in controller.execute!
+ async fn() {
+ await controller.init();
+ },
+});
+
+Deno.test({
+ name: "database table creation",
+ sanitizeOps: false, // TODO: Previous bug!
+ sanitizeResources: false, // TODO: Previous bug!
+ async fn() {
+ await controller.execute("DROP TABLE IF EXISTS test");
+ await controller.execute("CREATE TABLE test (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(16) UNIQUE)");
+ },
+});
+
+Deno.test({
+ name: "database variable arguments",
+ sanitizeOps: false, // TODO: Previous bug!
+ sanitizeResources: false, // TODO: Previous bug!
+ async fn() {
+ await controller.execute("INSERT INTO test(name) VALUES(?)", ["Melvin"]);
+ assertThrowsAsync(
+ () => controller.execute("INSERT INTO test(name) VALUES(?)", ["Melvin"]),
+ Error,
+ "Duplicate entry 'Melvin' for key 'name'"
+ );
+ await controller.execute("INSERT INTO test(name) VALUES(?)", ["LarsVomMars"]);
+ },
+});
+
+Deno.test({
+ name: "database multiple statements",
+ sanitizeOps: false, // TODO: Previous bug!
+ sanitizeResources: false, // TODO: Previous bug!
+ async fn() {
+ await controller.execute_multiple([
+ ["DELETE FROM test WHERE ?? = ?", ["name", "Melvin"]],
+ ["INSERT INTO test(name) VALUES(?)", ["Melvin"]],
+ ]);
+ },
+});
+
+Deno.test({
+ name: "database select statements",
+ sanitizeOps: false, // TODO: Previous bug!
+ sanitizeResources: false, // TODO: Previous bug!
+ async fn() {
+ const count = await controller.query("SELECT ?? FROM ?? WHERE gd=4", ["name", "test"]);
+ // TODO: WHY DOESN'T THIS WORK?
+ console.log(count);
+ },
+});
+
+Deno.test("database close", async () => {
+ await controller.execute("DROP TABLE test");
+ await controller.close(); // TODO: Fix 'Bad resource ID'!
});