From 594d3770b2f4be4866a15388cb32054ae230a95b Mon Sep 17 00:00:00 2001 From: coderaiser Date: Wed, 16 Aug 2017 14:23:53 +0300 Subject: [PATCH] test(markdown) coverage --- server/markdown.js | 4 ++-- test/server/markdown.js | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/server/markdown.js b/server/markdown.js index 651e7495..7c9cd1d5 100644 --- a/server/markdown.js +++ b/server/markdown.js @@ -10,11 +10,11 @@ const markdown = require('markdown-it')(); const root = require('./root'); module.exports = (name, request, callback) => { + check(name, request, callback); + const method = request.method; const query = ponse.getQuery(request); - check(name, request, callback); - switch(method) { case 'GET': name = name.replace('/markdown', ''); diff --git a/test/server/markdown.js b/test/server/markdown.js index 17760792..780d548f 100644 --- a/test/server/markdown.js +++ b/test/server/markdown.js @@ -5,6 +5,8 @@ const promisify = require('es6-promisify'); const pullout = require('pullout'); const request = require('request'); +const markdown = require('../../server/markdown'); + const before = require('../before'); const warp = (fn, ...a) => (...b) => fn(...b, ...a); @@ -44,3 +46,22 @@ test('cloudcmd: markdown: relative', (t) => { }); }); +test('cloudcmd: markdown: no name', (t) => { + t.throws(markdown, /name should be string!/, 'should throw when no name'); + t.end(); +}); + +test('cloudcmd: markdown: no request', (t) => { + const fn = () => markdown('hello'); + + t.throws(fn, /request could not be empty!/, 'should throw when no request'); + t.end(); +}); + +test('cloudcmd: markdown: no function', (t) => { + const fn = () => markdown('hello', {}); + + t.throws(fn, /callback should be function!/, 'should throw when no callback'); + t.end(); +}); +