test: add unit tests for main and db and improve coverage - #596
test: add unit tests for main and db and improve coverage#596Laertes87 wants to merge 34 commits into
Conversation
There was a problem hiding this comment.
All reported issues were addressed across 7 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 4 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 1 file (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 14 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 2 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
|
@C4illin I think this PR is done for now. Every converter and every helper is covered by unit tests now. The only files not covered in those subdirectories now are types, the I guess the next step woould be tests for the frontend components and pages. But that's a task for a different PR. The backend should be covered for now. |
| delete process.env.MOCK_EXEC_ERROR; | ||
| }); | ||
|
|
||
| test("druckt nur die Version und beendet sich sofort, wenn NODE_ENV nicht production ist", async () => { |
There was a problem hiding this comment.
Awww man, I should not write code when I'm already half asleep. I was on a voice call with an American friend once and I wasn't really awake anymore at 4 am. I just defaulted to German at one point. 😆
| expect(readFile).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| test("druckt System-Infos und Tool-Versionen im Production-Modus", async () => { |
| expect(exec).toHaveBeenCalledTimes(17); // Entspricht exakt der Anzahl der exec-Aufrufe im Quellcode | ||
| }); | ||
|
|
||
| test("loggt Fehlerpfade wenn Tools fehlen", async () => { |
| expect(consoleErrorSpy).toHaveBeenCalledWith("Bun is not installed. wait what"); | ||
| }); | ||
|
|
||
| test("verarbeitet Ausgabe-Parsing korrekt und loggt keine Fehler im Erfolgsfall", async () => { |
| const dbVersion = (db.query("PRAGMA user_version").get() as { user_version?: number }).user_version; | ||
| if (dbVersion === 0) { | ||
| db.exec("ALTER TABLE file_names ADD COLUMN status TEXT DEFAULT 'not started';"); | ||
| db.exec("PRAGMA user_version = 1;"); |
There was a problem hiding this comment.
Wont this reset user version to 1 every time?
There was a problem hiding this comment.
You are right, that statement needs to be in the else if branch as well.
There was a problem hiding this comment.
All reported issues were addressed across 4 files (changes from recent commits).
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
|
@C4illin I addressed your comments. I hope that is fine now. The db initialization and update should also be a bit more robust now. |
Summary by cubic
Added comprehensive unit tests for converter discovery/chunking, DB init/migration, file-type normalization/output mapping, and version logging to improve coverage and ensure stable behavior. Tests run against an isolated temp SQLite DB via
DB_PATHand avoid flakes by importing after env setup and waiting for async callbacks.chunks/mainConverterfromsrc/converters/main.tsandfilters/getFiltersfromsrc/converters/libreoffice.tsas@internalfor tests.initializeDatabase; DB setup now respectsDB_PATH, creates the parent directory, enables WAL, and performs an idempotent v0→v1 migration (case-insensitive check for missingstatuscolumn; only updatesuser_versionwhen needed).src/helpers/printVersions.ts; tests verify production vs. non-production output and error paths for missing tools.bunfig.tomlto enable coverage and excludetests/converters/helpers/commonTests.ts; tests ensure defaultdbexport works and clean up connections plus WAL/SHM files.Written for commit ee8137b. Summary will update on new commits.