summary refs log tree commit diff stats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/data/testfile.md5
-rw-r--r--test/index.test.js9
-rw-r--r--test/modules/metadata.test.js33
3 files changed, 44 insertions, 3 deletions
diff --git a/test/data/testfile.md b/test/data/testfile.md
new file mode 100644
index 0000000..6899d52
--- /dev/null
+++ b/test/data/testfile.md
@@ -0,0 +1,5 @@
++++
+Title = "This is a test"
+Description = "Test file"
+Tags = ["a", "b"]
++++
diff --git a/test/index.test.js b/test/index.test.js
index 2e55b2c..ebac87d 100644
--- a/test/index.test.js
+++ b/test/index.test.js
@@ -1,12 +1,15 @@
 const test = require('ava')
+const path = require('path')
 const request = require('supertest')
 
+process.env.POST_DIR = path.resolve(__dirname, '../test/data/')
 const app = require('../src/index.js')
 
-test(t =>
-  request(app.listen())
+test(t => {
+  return request(app.listen())
     .get('/')
     .expect(200)
     .expect(/hello world/)
+    .expect(/This is a test/)
     .then(() => t.pass())
-)
+})
diff --git a/test/modules/metadata.test.js b/test/modules/metadata.test.js
new file mode 100644
index 0000000..139de60
--- /dev/null
+++ b/test/modules/metadata.test.js
@@ -0,0 +1,33 @@
+const test = require('ava')
+const path = require('path')
+
+const metadata = require('../../src/modules/metadata.js')
+
+test('getFileMetadata', t => {
+  const expected = new Map(
+    Object.entries({
+      title: 'This is a test',
+      description: 'Test file',
+      tags: ['a', 'b']
+    })
+  )
+  t.deepEqual(
+    metadata.getFileMetadata(path.resolve(__dirname, '../data/testfile.md')),
+    expected
+  )
+})
+
+test('getFolderMetadata', t => {
+  const expected = new Map(
+    Object.entries({
+      title: 'This is a test',
+      description: 'Test file',
+      tags: ['a', 'b']
+    })
+  )
+  const actual = metadata.getFolderMetadata(path.resolve(__dirname, '../data/'))
+  t.true(Array.isArray(actual), 'must return an array')
+  t.true(actual.length > 0, 'must return a non-empty array')
+  t.is(actual[0].path, path.resolve(__dirname, '../data/testfile.md'))
+  t.deepEqual(actual[0].data, expected)
+})