1 | const test = require('ava')
|
2 | const _ = require('lodash')
|
3 | const header = require('../src/header')
|
4 |
|
5 | test('do not parse link header', (t) => {
|
6 | const links = {}
|
7 |
|
8 | t.is(header.getLink(links), undefined)
|
9 | })
|
10 |
|
11 | test('parse the related link header', (t) => {
|
12 | const links = {
|
13 | 'prev': { href: 'foo' },
|
14 | 'last': { href: 'bar' }
|
15 | }
|
16 |
|
17 | const splitLinks = _.map(header.getLink(links).split(','), _.trim)
|
18 | const matchedEntities = header.getLink(links).match(/<.*?>/g)
|
19 | const result = _.every(splitLinks, splitLink => splitLink.match(/<.*>; rel=".*"/))
|
20 |
|
21 | t.is(splitLinks.length, 2)
|
22 | t.deepEqual(matchedEntities, ['<foo>', '<bar>'])
|
23 | t.truthy(result)
|
24 | })
|