diff options
author | Patryk Niedźwiedziński <pniedzwiedzinski19@gmail.com> | 2020-01-28 18:16:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-28 18:16:03 +0100 |
commit | 42c089293fed2db9c8a09d8e55f046169b5f0844 (patch) | |
tree | 18a053fe7f1e03fc5419a8c3d2a8bc8193cb27f0 /test | |
parent | 7b8d75cd87e392d9ffb3defa538a041c4f7e0f0c (diff) | |
parent | acfd4d0c722ceeca6aad51be64baf117e73f286c (diff) | |
download | kronikarz-42c089293fed2db9c8a09d8e55f046169b5f0844.tar.gz kronikarz-42c089293fed2db9c8a09d8e55f046169b5f0844.zip |
Merge pull request #8 from pniedzwiedzinski/feature/generateApi v2.0
Feature/generate api
Diffstat (limited to 'test')
-rw-r--r-- | test/generateApi.spec.ts | 22 | ||||
-rw-r--r-- | test/getPost.spec.ts | 5 | ||||
-rw-r--r-- | test/index.spec.ts | 2 | ||||
-rw-r--r-- | test/samples/2019/12/12/category.md | 13 |
4 files changed, 39 insertions, 3 deletions
diff --git a/test/generateApi.spec.ts b/test/generateApi.spec.ts new file mode 100644 index 0000000..f22c8e4 --- /dev/null +++ b/test/generateApi.spec.ts @@ -0,0 +1,22 @@ +import * as fs from "fs"; +import Kronikarz from "../dist"; + +const k = new Kronikarz(__dirname + "/samples"); +const dir = "./tmp"; + +test("generate single file", () => { + k.generateApi(dir); + fs.readFile("./tmp/api/posts/2019/12/12/test.json", "utf-8", (err, data) => { + const parsedPost = JSON.parse(data); + expect(parsedPost.title).toBe("Test"); + }); +}); + +test("categories", () => { + k.generateApi(dir) + fs.readFile(`${dir}/api/category/test-category.json`, "utf-8", (err, data) => { + const posts = JSON.parse(data) + expect(posts.length).toBe(1) + expect(posts[0].content).toBe(undefined) + }) +}) diff --git a/test/getPost.spec.ts b/test/getPost.spec.ts index 6a5e4e0..080bfbd 100644 --- a/test/getPost.spec.ts +++ b/test/getPost.spec.ts @@ -3,6 +3,7 @@ import Kronikarz from "../dist"; const k = new Kronikarz(__dirname + "/samples"); test("simple get", () => { - const post = k.getPost("2019", "12", "12", "test"); - expect(post.content.meta["title"]).toBe("Test"); + const p = k.getPost("2019", "12", "12", "test"); + const post = p.toApi(); + expect(post.title).toBe("Test"); }); diff --git a/test/index.spec.ts b/test/index.spec.ts index 4fd65e1..4622724 100644 --- a/test/index.spec.ts +++ b/test/index.spec.ts @@ -2,5 +2,5 @@ import Kronikarz from "../dist"; test("basic", () => { const k = new Kronikarz(__dirname + "/samples"); - expect(k.getPosts().length).toBe(1); + expect(k.getPosts().length).toBe(2); }); diff --git a/test/samples/2019/12/12/category.md b/test/samples/2019/12/12/category.md new file mode 100644 index 0000000..e7f04e7 --- /dev/null +++ b/test/samples/2019/12/12/category.md @@ -0,0 +1,13 @@ +--- +title: Category +author: Tester +category: + - test-category +--- + +# Category + +01-01-2020 | Tester + +This file is for testing categories + |