Skip to content

test: add unit tests for main and db and improve coverage - #596

Open
Laertes87 wants to merge 34 commits into
mainfrom
AddMoreUnitTests
Open

test: add unit tests for main and db and improve coverage#596
Laertes87 wants to merge 34 commits into
mainfrom
AddMoreUnitTests

Conversation

@Laertes87

@Laertes87 Laertes87 commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

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_PATH and avoid flakes by importing after env setup and waiting for async callbacks.

  • Refactors
    • Exported chunks/mainConverter from src/converters/main.ts and filters/getFilters from src/converters/libreoffice.ts as @internal for tests.
    • Introduced initializeDatabase; DB setup now respects DB_PATH, creates the parent directory, enables WAL, and performs an idempotent v0→v1 migration (case-insensitive check for missing status column; only updates user_version when needed).
    • Hardened version parsing/output in src/helpers/printVersions.ts; tests verify production vs. non-production output and error paths for missing tools.
    • Added bunfig.toml to enable coverage and exclude tests/converters/helpers/commonTests.ts; tests ensure default db export works and clean up connections plus WAL/SHM files.

Written for commit ee8137b. Summary will update on new commits.

Review in cubic

@github-actions github-actions Bot added Test and removed Test labels Aug 2, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 7 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread tests/db/db.test.ts Outdated
Comment thread tests/db/db.test.ts
Comment thread tests/db/db.test.ts
Comment thread tests/converters/main.test.ts
Comment thread tests/converters/libreoffice.test.ts
@github-actions github-actions Bot added Test and removed Test labels Aug 2, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread src/db/db.ts
Comment thread tests/converters/main.test.ts Outdated
@github-actions github-actions Bot added Test and removed Test labels Aug 2, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread tests/converters/main.test.ts Outdated
@github-actions github-actions Bot added Test and removed Test labels Aug 2, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread src/db/db.ts Outdated
@github-actions github-actions Bot added Test and removed Test labels Aug 2, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread tests/converters/main.test.ts Outdated
@github-actions github-actions Bot added Test and removed Test labels Aug 2, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread tests/converters/xelatex.test.ts Outdated
Comment thread tests/converters/potrace.test.ts Outdated
@github-actions github-actions Bot removed the Test label Aug 2, 2026
@github-actions github-actions Bot added Test and removed Test labels Aug 4, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread tests/converters/main.test.ts
Comment thread tests/converters/main.test.ts Outdated
@github-actions github-actions Bot added Test and removed Test labels Aug 4, 2026
@Laertes87

Copy link
Copy Markdown
Collaborator Author

@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 env.ts and the tailwind.ts. Those don't contain relevant program logic that would need testing, though.

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.

Comment thread tests/helpers/printVersions.test.ts Outdated
delete process.env.MOCK_EXEC_ERROR;
});

test("druckt nur die Version und beendet sich sofort, wenn NODE_ENV nicht production ist", async () => {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

english would be nice :)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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. 😆

Comment thread tests/helpers/printVersions.test.ts Outdated
expect(readFile).not.toHaveBeenCalled();
});

test("druckt System-Infos und Tool-Versionen im Production-Modus", async () => {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Comment thread tests/helpers/printVersions.test.ts Outdated
expect(exec).toHaveBeenCalledTimes(17); // Entspricht exakt der Anzahl der exec-Aufrufe im Quellcode
});

test("loggt Fehlerpfade wenn Tools fehlen", async () => {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here

Comment thread tests/helpers/printVersions.test.ts Outdated
expect(consoleErrorSpy).toHaveBeenCalledWith("Bun is not installed. wait what");
});

test("verarbeitet Ausgabe-Parsing korrekt und loggt keine Fehler im Erfolgsfall", async () => {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here

Comment thread src/db/db.ts Outdated
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;");

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wont this reset user version to 1 every time?

@Laertes87 Laertes87 Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, that statement needs to be in the else if branch as well.

@github-actions github-actions Bot added Test and removed Test labels Aug 4, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread src/db/db.ts Outdated
@github-actions github-actions Bot added Test and removed Test labels Aug 4, 2026
@Laertes87

Copy link
Copy Markdown
Collaborator Author

@C4illin I addressed your comments. I hope that is fine now. The db initialization and update should also be a bit more robust now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants