-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathArticle.spec.ts
More file actions
60 lines (44 loc) · 2.02 KB
/
Article.spec.ts
File metadata and controls
60 lines (44 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { join } from "node:path";
import { describe, it, expect } from "vitest";
import { Markdown } from "@/cms/lib/Markdown";
import { Article } from "./Article";
import { Collection } from "./Collection";
describe("Article", () => {
describe(".fromMarkdown", () => {
it("throws an exception if the metadata is invalid", async () => {
const markdown = await Markdown.fromFile(
join(process.cwd(), "tests/fixtures/cms/models/Article/invalid-metadata.md"),
);
await expect(() => Article.fromMarkdown(markdown)).rejects.toThrow();
});
it("returns an article", async () => {
const markdown = await Markdown.fromFile(join(process.cwd(), "tests/fixtures/cms/models/Article/valid.md"));
const article = Article.fromMarkdown(markdown);
await expect(article).resolves.toBeInstanceOf(Article);
});
describe("handling collections", () => {
it("throws an exception if the collection does not exist", async () => {
const markdown = await Markdown.fromFile(
join(process.cwd(), "tests/fixtures/cms/models/Article/invalid-collection.md"),
);
await expect(() => Article.fromMarkdown(markdown)).rejects.toThrow(
"Invalid collection: 'non-existing-collection'",
);
});
it("returns the article with the collections", async () => {
const markdown = await Markdown.fromFile(
join(process.cwd(), "tests/fixtures/cms/models/Article/valid-collection.md"),
);
const article = await Article.fromMarkdown(markdown);
expect(article.getCollections()).toEqual([new Collection("books", "Books")]);
});
it("does not return duplicated collections", async () => {
const markdown = await Markdown.fromFile(
join(process.cwd(), "tests/fixtures/cms/models/Article/duplicated-collections.md"),
);
const article = await Article.fromMarkdown(markdown);
expect(article.getCollections()).toEqual([new Collection("books", "Books")]);
});
});
});
});