Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedsalem401 committed Feb 7, 2024
1 parent 46297c4 commit 9ed8d05
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 60 deletions.
Empty file added __mocks__/content/hi.canvas
Empty file.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions src/lib/indexFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ export function indexFolder(
"Validation Failed: Unable to validate files against the specified scheme. Ensure that the file formats and content adhere to the specified scheme."
);
}
throw new Error(
"Validation Failed: Unable to validate files against the specified scheme. Ensure that the file formats and content adhere to the specified scheme."
);
}

files.push(fileObject);
Expand Down
107 changes: 52 additions & 55 deletions src/tests/documentTypes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,63 +4,60 @@ import { MarkdownDB } from "../lib/markdowndb";
import { z } from "zod";

describe("Document Types Schema Validate Testing", () => {
const pathToContentFixture = "__mocks__/content";
let mddb: MarkdownDB;
const pathToContentFixture = "__mocks__/content";
let mddb: MarkdownDB;

beforeAll(async () => {
const dbConfig = {
client: "sqlite3",
connection: {
filename: "markdown.db",
},
};
mddb = new MarkdownDB(dbConfig);
await mddb.init();
});
beforeAll(async () => {
const dbConfig = {
client: "sqlite3",
connection: {
filename: "markdown.db",
},
};
mddb = new MarkdownDB(dbConfig);
await mddb.init();
});

afterAll(async () => {
await mddb.db.destroy();
afterAll(async () => {
await mddb.db.destroy();
});

test("Should check if the title field is created and save in db", async () => {
await mddb.indexFolder({
folderPath: pathToContentFixture,
customConfig: {
computedFields: [
(fileInfo: FileInfo, ast: Root) => {
fileInfo.title = "Hello";
},
],
schemas: {
blog: z.object({
title: z.string(),
}),
},
},
});
const dbFiles = await mddb.getFiles({ filetypes: ["blog"] });
for (const file of dbFiles) {
expect(file.title).toBe("Hello");
}
});

test("Test that the 'indexFolder' function throws a validation error for a missing field in the blog schema.", async () => {
try {
await mddb.indexFolder({
folderPath: pathToContentFixture,
customConfig: {
schemas: {
blog: z.object({
missingField: z.string(),
}),
},
},
});

fail("Expected a validation error due to a missing field in the blog schema, but none was thrown.");
} catch (error: any) {
expect(error).toBeInstanceOf(Error);
expect(error.message).toContain("Validation Failed: Unable to validate files against the specified scheme.");
;
}
});
test("Should check if the title field is created and save in db", async () => {
await mddb.indexFolder({
folderPath: pathToContentFixture,
customConfig: {
computedFields: [
(fileInfo: FileInfo, ast: Root) => {
fileInfo.title = "Hello";
},
],
schemas: {
blog: z.object({
title: z.string(),
}),
},
},
});
const dbFiles = await mddb.getFiles({ filetypes: ["blog"] });
for (const file of dbFiles) {
expect(file.title).toBe("Hello");
}
});
test("Test that the 'indexFolder' function throws a validation error for a missing field in the blog schema.", async () => {
await expect(
mddb.indexFolder({
folderPath: pathToContentFixture,
customConfig: {
schemas: {
blog: z.object({
missingField: z.string(),
}),
},
},
})
).rejects.toThrow(
"Validation Failed: Unable to validate files against the specified scheme."
);
});
});

0 comments on commit 9ed8d05

Please sign in to comment.