From d092cdd912293ba39d54c9c03529e7e266a4158b Mon Sep 17 00:00:00 2001 From: codecanna Date: Mon, 29 Dec 2025 16:38:28 -0700 Subject: [PATCH 1/6] Added a check for the test db directory structure, creates it if not found --- tests/dbutils_test.ts | 8 ++++- tests/entry_test.ts | 8 ++++- tests/gad7_score_test.ts | 9 ++++- tests/journal_entry_photo_test.ts | 8 ++++- tests/journal_test.ts | 8 ++++- tests/migration_test.ts | 56 +++++++++++++++++-------------- tests/misc_test.ts | 7 ++++ tests/phq9_score_test.ts | 8 ++++- tests/settings_test.ts | 8 ++++- 9 files changed, 88 insertions(+), 32 deletions(-) diff --git a/tests/dbutils_test.ts b/tests/dbutils_test.ts index 7e117e2..b741d50 100644 --- a/tests/dbutils_test.ts +++ b/tests/dbutils_test.ts @@ -1,9 +1,15 @@ import { assertEquals } from "@std/assert/equals"; -import { testDbFile } from "../constants/paths.ts"; +import { testDbFile, testDbFileBasePath } from "../constants/paths.ts"; import { createUserTable } from "../db/migration.ts"; import { insertUser } from "../models/user.ts"; import { User } from "../types/types.ts"; import { getLatestId } from "../utils/dbUtils.ts"; +import { existsSync } from "node:fs"; + +// Create test db directory structure +if (!existsSync(testDbFileBasePath)) { + Deno.mkdirSync(testDbFileBasePath, { recursive: true }); +} Deno.test("Test getLatestId()", () => { const testUser: User = { diff --git a/tests/entry_test.ts b/tests/entry_test.ts index b08234f..88aaca3 100644 --- a/tests/entry_test.ts +++ b/tests/entry_test.ts @@ -9,8 +9,14 @@ import { insertEntry, updateEntry, } from "../models/entry.ts"; -import { testDbFile } from "../constants/paths.ts"; +import { testDbFile, testDbFileBasePath } from "../constants/paths.ts"; import { assertObjectMatch } from "@std/assert/object-match"; +import { existsSync } from "node:fs"; + +// Create test db directory structure +if (!existsSync(testDbFileBasePath)) { + Deno.mkdirSync(testDbFileBasePath, { recursive: true }); +} // Create test entry const testEntry: Entry = { diff --git a/tests/gad7_score_test.ts b/tests/gad7_score_test.ts index 4a17564..a0621ae 100644 --- a/tests/gad7_score_test.ts +++ b/tests/gad7_score_test.ts @@ -3,7 +3,14 @@ import { getGadScoreById, insertGadScore } from "../models/gad7_score.ts"; import { AnxietySeverity, GAD7Score, User } from "../types/types.ts"; import { createGadScoreTable, createUserTable } from "../db/migration.ts"; import { insertUser } from "../models/user.ts"; -import { testDbFile } from "../constants/paths.ts"; +import { testDbFile, testDbFileBasePath } from "../constants/paths.ts"; +import { existsSync } from "node:fs"; + +// Create test db directory structure +if (!existsSync(testDbFileBasePath)) { + Deno.mkdirSync(testDbFileBasePath, { recursive: true }); +} + // Create test user const testUser: User = { telegramId: 12345, diff --git a/tests/journal_entry_photo_test.ts b/tests/journal_entry_photo_test.ts index e5298a8..8b22d0d 100644 --- a/tests/journal_entry_photo_test.ts +++ b/tests/journal_entry_photo_test.ts @@ -1,5 +1,5 @@ import { assertEquals } from "@std/assert/equals"; -import { testDbFile } from "../constants/paths.ts"; +import { testDbFile, testDbFileBasePath } from "../constants/paths.ts"; import { createJournalEntryPhotosTable, createJournalTable, @@ -9,6 +9,12 @@ import { insertJournalEntry } from "../models/journal.ts"; import { insertJournalEntryPhoto } from "../models/journal_entry_photo.ts"; import { insertUser } from "../models/user.ts"; import { JournalEntry, JournalEntryPhoto, User } from "../types/types.ts"; +import { existsSync } from "node:fs"; + +// Create test db directory structure +if (!existsSync(testDbFileBasePath)) { + Deno.mkdirSync(testDbFileBasePath, { recursive: true }); +} // Create test user const testUser: User = { diff --git a/tests/journal_test.ts b/tests/journal_test.ts index 0389af1..d8b64c3 100644 --- a/tests/journal_test.ts +++ b/tests/journal_test.ts @@ -1,5 +1,5 @@ import { assertEquals } from "@std/assert/equals"; -import { testDbFile } from "../constants/paths.ts"; +import { testDbFile, testDbFileBasePath } from "../constants/paths.ts"; import { createJournalTable, createUserTable } from "../db/migration.ts"; import { deleteJournalEntryById, @@ -11,6 +11,12 @@ import { import { insertUser } from "../models/user.ts"; import { JournalEntry, User } from "../types/types.ts"; import { assertObjectMatch } from "@std/assert/object-match"; +import { existsSync } from "node:fs"; + +// Create test db directory structure +if (!existsSync(testDbFileBasePath)) { + Deno.mkdirSync(testDbFileBasePath, { recursive: true }); +} // Create test journal entry const testJournalEntry: JournalEntry = { diff --git a/tests/migration_test.ts b/tests/migration_test.ts index daf668f..287290e 100644 --- a/tests/migration_test.ts +++ b/tests/migration_test.ts @@ -11,123 +11,129 @@ import { } from "../db/migration.ts"; import { assertNotEquals } from "@std/assert/not-equals"; import { assertEquals } from "@std/assert/equals"; +import { testDbFile, testDbFileBasePath } from "../constants/paths.ts"; +import { existsSync } from "node:fs"; + +// Create test db directory structure +if (!existsSync(testDbFileBasePath)) { + Deno.mkdirSync(testDbFileBasePath, { recursive: true }); +} -const testDbPath = "db/test_db/jotbot_test.db"; Deno.test("Test createEntryTable()", () => { // Create test entry db - createEntryTable(testDbPath); + createEntryTable(testDbFile); // Get table - const db = new DatabaseSync(testDbPath); + const db = new DatabaseSync(testDbFile); const table = db.prepare( `SELECT name FROM sqlite_master WHERE type ='table' AND name = 'entry_db';`, ).get(); assertNotEquals(table, undefined); assertEquals(table?.name, "entry_db"); - Deno.removeSync(testDbPath); + Deno.removeSync(testDbFile); }); Deno.test("Test createGadScoreTable()", () => { // Create test gad score table - createGadScoreTable(testDbPath); + createGadScoreTable(testDbFile); // Get the table info from the table - const db = new DatabaseSync(testDbPath); + const db = new DatabaseSync(testDbFile); const table = db.prepare( `SELECT name FROM sqlite_master WHERE type ='table' AND name = 'gad_score_db';`, ).get(); assertNotEquals(table, undefined); assertEquals(table?.name, "gad_score_db"); - Deno.removeSync(testDbPath); + Deno.removeSync(testDbFile); }); Deno.test("Test createPhqScoreTable()", () => { // Create test gad score table - createPhqScoreTable(testDbPath); + createPhqScoreTable(testDbFile); // Get the table info from the table - const db = new DatabaseSync(testDbPath); + const db = new DatabaseSync(testDbFile); const table = db.prepare( `SELECT name FROM sqlite_master WHERE type ='table' AND name = 'phq_score_db';`, ).get(); assertNotEquals(table, undefined); assertEquals(table?.name, "phq_score_db"); - Deno.removeSync(testDbPath); + Deno.removeSync(testDbFile); }); Deno.test("Test createUserTable()", () => { // Create test gad score table - createUserTable(testDbPath); + createUserTable(testDbFile); // Get the table info from the table - const db = new DatabaseSync(testDbPath); + const db = new DatabaseSync(testDbFile); const table = db.prepare( `SELECT name FROM sqlite_master WHERE type ='table' AND name = 'user_db';`, ).get(); assertNotEquals(table, undefined); assertEquals(table?.name, "user_db"); - Deno.removeSync(testDbPath); + Deno.removeSync(testDbFile); }); Deno.test("Test createSettingsTable()", () => { // Create test gad score table - createSettingsTable(testDbPath); + createSettingsTable(testDbFile); // Get the table info from the table - const db = new DatabaseSync(testDbPath); + const db = new DatabaseSync(testDbFile); const table = db.prepare( `SELECT name FROM sqlite_master WHERE type ='table' AND name = 'settings_db';`, ).get(); assertNotEquals(table, undefined); assertEquals(table?.name, "settings_db"); - Deno.removeSync(testDbPath); + Deno.removeSync(testDbFile); }); Deno.test("Test createJournalTable()", () => { // Create test gad score table - createJournalTable(testDbPath); + createJournalTable(testDbFile); // Get the table info from the table - const db = new DatabaseSync(testDbPath); + const db = new DatabaseSync(testDbFile); const table = db.prepare( `SELECT name FROM sqlite_master WHERE type ='table' AND name = 'journal_db';`, ).get(); assertNotEquals(table, undefined); assertEquals(table?.name, "journal_db"); - Deno.removeSync(testDbPath); + Deno.removeSync(testDbFile); }); Deno.test("Test createJournalEntryPhotosTable()", () => { // Create test gad score table - createJournalEntryPhotosTable(testDbPath); + createJournalEntryPhotosTable(testDbFile); // Get the table info from the table - const db = new DatabaseSync(testDbPath); + const db = new DatabaseSync(testDbFile); const table = db.prepare( `SELECT name FROM sqlite_master WHERE type ='table' AND name = 'photo_db';`, ).get(); assertNotEquals(table, undefined); assertEquals(table?.name, "photo_db"); - Deno.removeSync(testDbPath); + Deno.removeSync(testDbFile); }); Deno.test("Test createVoiceRecordingTable()", () => { - createVoiceRecordingTable(testDbPath); + createVoiceRecordingTable(testDbFile); // Get the table info from the table - const db = new DatabaseSync(testDbPath); + const db = new DatabaseSync(testDbFile); const table = db.prepare( `SELECT name FROM sqlite_master WHERE type ='table' AND name = 'voice_recording_db';`, ).get(); assertNotEquals(table, undefined); assertEquals(table?.name, "voice_recording_db"); - Deno.removeSync(testDbPath); + Deno.removeSync(testDbFile); }); diff --git a/tests/misc_test.ts b/tests/misc_test.ts index 62f8bc6..a307ed2 100644 --- a/tests/misc_test.ts +++ b/tests/misc_test.ts @@ -1,6 +1,13 @@ import { assertEquals, assertObjectMatch } from "@std/assert"; import { entryFromString, entryToString } from "../utils/misc.ts"; import { Entry } from "../types/types.ts"; +import { testDbFileBasePath } from "../constants/paths.ts"; +import { existsSync } from "node:fs"; + +// Create test db directory structure +if (!existsSync(testDbFileBasePath)) { + Deno.mkdirSync(testDbFileBasePath, { recursive: true }); +} Deno.test("Test entryFromString()", () => { const testEntryString = `Page 1 of 15 diff --git a/tests/phq9_score_test.ts b/tests/phq9_score_test.ts index 93dcf64..73dfad2 100644 --- a/tests/phq9_score_test.ts +++ b/tests/phq9_score_test.ts @@ -1,10 +1,16 @@ import { assertEquals } from "@std/assert/equals"; -import { testDbFile } from "../constants/paths.ts"; +import { testDbFile, testDbFileBasePath } from "../constants/paths.ts"; import { createPhqScoreTable, createUserTable } from "../db/migration.ts"; import { getPhqScoreByUserId, insertPhqScore } from "../models/phq9_score.ts"; import { insertUser } from "../models/user.ts"; import { DepressionSeverity, PHQ9Score, User } from "../types/types.ts"; import { assertObjectMatch } from "@std/assert/object-match"; +import { existsSync } from "node:fs"; + +// Create test db directory structure +if (!existsSync(testDbFileBasePath)) { + Deno.mkdirSync(testDbFileBasePath, { recursive: true }); +} // Create test user const testUser: User = { diff --git a/tests/settings_test.ts b/tests/settings_test.ts index 82abc79..75c969e 100644 --- a/tests/settings_test.ts +++ b/tests/settings_test.ts @@ -1,5 +1,5 @@ import { assertEquals } from "@std/assert/equals"; -import { testDbFile } from "../constants/paths.ts"; +import { testDbFile, testDbFileBasePath } from "../constants/paths.ts"; import { createSettingsTable, createUserTable } from "../db/migration.ts"; import { getSettingsById, @@ -10,6 +10,12 @@ import { insertUser } from "../models/user.ts"; import { User } from "../types/types.ts"; import { Settings } from "../types/types.ts"; import { assertObjectMatch } from "@std/assert/object-match"; +import { existsSync } from "node:fs"; + +// Create test db directory structure +if (!existsSync(testDbFileBasePath)) { + Deno.mkdirSync(testDbFileBasePath, { recursive: true }); +} // Create test user const testUser: User = { From 52e5a5fb8b00d1f16b9d1e0d7bbd2c5b375ba011 Mon Sep 17 00:00:00 2001 From: codecanna Date: Mon, 29 Dec 2025 16:38:49 -0700 Subject: [PATCH 2/6] Parsed the path a little bit --- constants/paths.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/constants/paths.ts b/constants/paths.ts index 5a1b9b6..1939309 100644 --- a/constants/paths.ts +++ b/constants/paths.ts @@ -1,4 +1,6 @@ -export const dbFile: string = `db/prod_db/jotbot.db`; -export const testDbFile: string = `db/test_db/jotbot_test.db`; +export const dbFileBasePath = `db/prod_db`; +export const dbFile: string = `${dbFileBasePath}/jotbot.db`; +export const testDbFileBasePath = `db/test_db`; +export const testDbFile: string = `${testDbFileBasePath}/jotbot_test.db`; export const selfieDirPath: string = `${Deno.cwd()}/assets/selfies`; export const sqlFilePath = "db/sql"; From 81bd1ec42261dc9887e40612ea2f76cf68b1c44a Mon Sep 17 00:00:00 2001 From: codecanna Date: Mon, 29 Dec 2025 16:39:13 -0700 Subject: [PATCH 3/6] Added check for prod_db structure creates if not detected --- utils/dbUtils.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/utils/dbUtils.ts b/utils/dbUtils.ts index 1553f82..96d5d7f 100644 --- a/utils/dbUtils.ts +++ b/utils/dbUtils.ts @@ -1,4 +1,4 @@ -import { PathLike } from "node:fs"; +import { existsSync, PathLike } from "node:fs"; import { createEntryTable, createGadScoreTable, @@ -7,12 +7,19 @@ import { createUserTable, } from "../db/migration.ts"; import { DatabaseSync } from "node:sqlite"; +import { dbFileBasePath, testDbFileBasePath } from "../constants/paths.ts"; /** * @param dbFile */ export function createDatabase(dbFile: PathLike) { try { + // Create db directory structure + if (!existsSync(dbFileBasePath)) { + Deno.mkdirSync(dbFileBasePath, { recursive: true }); + } + + // Create db createUserTable(dbFile); createGadScoreTable(dbFile); createPhqScoreTable(dbFile); From 87dc8a70c41ba71d823c859e86e9e2056a20a4f7 Mon Sep 17 00:00:00 2001 From: codecanna Date: Mon, 29 Dec 2025 16:42:01 -0700 Subject: [PATCH 4/6] deno fmt --- handlers/view_journal_entries.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/handlers/view_journal_entries.ts b/handlers/view_journal_entries.ts index 6e4289c..22bf7c9 100644 --- a/handlers/view_journal_entries.ts +++ b/handlers/view_journal_entries.ts @@ -1,9 +1,14 @@ import { Conversation } from "@grammyjs/conversations"; import { Context, InlineKeyboard } from "grammy"; -export async function view_journal_entries(conversation: Conversation, ctx: Context) { - await ctx.reply('Buttons!', {reply_markup: new InlineKeyboard().text("Add beans")}); +export async function view_journal_entries( + conversation: Conversation, + ctx: Context, +) { + await ctx.reply("Buttons!", { + reply_markup: new InlineKeyboard().text("Add beans"), + }); - const otherCtx = await conversation.wait(); - await ctx.reply("Tits"); -} \ No newline at end of file + const otherCtx = await conversation.wait(); + await ctx.reply("Tits"); +} From a486221863eeb26157bc0f8c17414addbe2ce279 Mon Sep 17 00:00:00 2001 From: codecanna Date: Mon, 29 Dec 2025 16:44:54 -0700 Subject: [PATCH 5/6] deno dmt --- handlers/view_journal_entries.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/handlers/view_journal_entries.ts b/handlers/view_journal_entries.ts index 22bf7c9..3b92fec 100644 --- a/handlers/view_journal_entries.ts +++ b/handlers/view_journal_entries.ts @@ -9,6 +9,6 @@ export async function view_journal_entries( reply_markup: new InlineKeyboard().text("Add beans"), }); - const otherCtx = await conversation.wait(); - await ctx.reply("Tits"); + const _otherCtx = await conversation.wait(); + await ctx.reply("Test"); } From 27a13cb0c4910489634470a846cfa06f969e6cd2 Mon Sep 17 00:00:00 2001 From: codecanna Date: Mon, 29 Dec 2025 16:47:32 -0700 Subject: [PATCH 6/6] damn deno lint --- utils/dbUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/dbUtils.ts b/utils/dbUtils.ts index 96d5d7f..11aaa42 100644 --- a/utils/dbUtils.ts +++ b/utils/dbUtils.ts @@ -7,7 +7,7 @@ import { createUserTable, } from "../db/migration.ts"; import { DatabaseSync } from "node:sqlite"; -import { dbFileBasePath, testDbFileBasePath } from "../constants/paths.ts"; +import { dbFileBasePath } from "../constants/paths.ts"; /** * @param dbFile