From 07a36dd82468ec7f26db896c65aadded620d501e Mon Sep 17 00:00:00 2001 From: Daniel Bachler Date: Tue, 27 Feb 2024 12:28:09 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9D=20Remove=20half-finish=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/tests/basic.test.ts | 53 ++---------------------------------------- 1 file changed, 2 insertions(+), 51 deletions(-) diff --git a/db/tests/basic.test.ts b/db/tests/basic.test.ts index 3959e6946fc..49362b51e6f 100644 --- a/db/tests/basic.test.ts +++ b/db/tests/basic.test.ts @@ -5,7 +5,7 @@ import { dataSource } from "./dataSource.dbtests.js" import { knex, Knex } from "knex" import { getConnection, knexRaw } from "../db.js" import { DataSource } from "typeorm" -import { insertUser, updateUser, User } from "../model/User.js" +import { deleteUser, insertUser, updateUser, User } from "../model/User.js" import { Chart } from "../model/Chart.js" import { DbPlainUser, UsersTableName } from "@ourworldindata/types" @@ -137,55 +137,6 @@ test("knex interface", async () => { [UsersTableName] ) expect(usersFromRawQuery.length).toBe(2) - }) -}) - -test("knex interface raw", async () => { - if (!knexInstance) throw new Error("Knex connection not initialized") - - // Create a transaction and run all tests inside it - await knexInstance.transaction(async (trx) => { - // Fetch all users into memory - const users = await trx - .from(UsersTableName) - .select("isSuperuser", "email") - expect(users.length).toBe(1) - - // Fetch all users in a streaming fashion, iterate over them async to avoid having to load everything into memory - const usersStream = trx - .from(UsersTableName) - .select("isSuperuser", "email") - .stream() - - for await (const user of usersStream) { - expect(user.isSuperuser).toBe(0) - expect(user.email).toBe("admin@example.com") - } - - // Use the insert helper method - await insertUser(trx, { - email: "test@example.com", - fullName: "Test User", - }) - - // Use the update helper method - await updateUser(trx, 2, { isSuperuser: 1 }) - - // Check results after update and insert - const afterUpdate = await trx - .from(UsersTableName) - .select("isSuperuser", "email") - .orderBy("id") - expect(afterUpdate.length).toBe(2) - expect(afterUpdate[1].isSuperuser).toBe(1) - - // Use raw queries, using ?? to specify the table name using the shared const value - // The pick type is used to type the result row - const usersFromRawQuery: Pick[] = await knexRaw( - "select email from ??", - trx, - [UsersTableName] - ) - expect(usersFromRawQuery.length).toBe(2) + await deleteUser(trx, 2) }) })