about summary refs log tree commit diff stats
path: root/test/modules/posts.test.js
blob: 454488fbf0a970c3f80bdd2894afa26c1c3edd0d (plain)
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
const test = require('ava')
const path = require('path')

const Posts = require('../../src/modules/posts.js')

test('get', t => {
  const expected = new Map(
    Object.entries({
      title: 'This is a test',
      description: 'Test file',
      tags: ['a', 'b']
    })
  )
  const post = Posts.get(path.resolve(__dirname, '../data/testfile.md'))
  t.deepEqual(post.data, expected)
  t.is(post.basename, 'testfile', 'must include basename')
})

test('getFolder', t => {
  const expected = new Map(
    Object.entries({
      title: 'This is a test',
      description: 'Test file',
      tags: ['a', 'b']
    })
  )
  const actual = Posts.getFolder(path.resolve(__dirname, '../data/'))
  t.true(actual.size > 0, 'must return a non-empty map')
  t.is(
    actual.get('testfile').path,
    path.resolve(__dirname, '../data/testfile.md')
  )
  t.deepEqual(actual.get('testfile').data, expected)
})

test('toTags', t => {
  const posts = new Map([
    [
      'testfile',
      {
        data: new Map([['title', 'Test Post'], ['tags', ['a', 'b']]])
      }
    ]
  ])
  const actual = Posts.toTags(posts)
  t.is(actual.size, 2)
  t.is(actual.get('a')[0].data.get('title'), 'Test Post')
  t.deepEqual(actual.get('a'), actual.get('b'))
})