'use strict';
const expect = require('chai').expect;
const fileHandler = require('../../src/common/fileHandler');
const path = require('path');
const fs = require('fs');

describe('create File', () => {
  let title, config, type, file;
  beforeEach(() => {
    config = require('../../config');
    config.post.dir = path.join(__dirname, '..', 'data', 'posts');
    config.page.dir = path.join(__dirname, '..', 'data', 'pages');
  });
  it('should exit, if the config is empty', () => {
    config = null;
    fileHandler.createFile(title, config, type, (err, result) => {
      expect(err).to.be.defined;
      expect(result).to.be.null;
    });
  });

  it('should exit, if the title is not valid', () => {
    title = null;
    fileHandler.createFile(title, config, type, (err, result) => {
      expect(err).to.be.defined;
      expect(result).to.be.null;
    });
  });

  it('should create a post, if config, title and type are valid', () => {
    title = 'This is my test post'.split(' ');
    type = 'post';
    fileHandler.createFile(title, config, type, (err, result) => {
      expect(err).to.be.null;
      expect(result).to.be.defined;
      const file = path.basename(result);
      const year = new Date().getFullYear().toString();
      expect(file.startsWith(year)).to.be.true;
      fs.unlinkSync(result); // cleanup
    });
  });

  it('should create a page, is data is valid', () => {
    title = 'This is my test post'.split(' ');
    type = 'page';
    fileHandler.createFile(title, config, type, (err, result) => {
      expect(err).to.be.null;
      expect(result).to.be.defined;
      const file = path.basename(result);
      const year = new Date().getFullYear().toString();
      expect(file.startsWith(year)).to.be.false;
      fs.unlinkSync(result); // cleanup
    });
  });
});

describe('delete File', () => {
  let title, config, type, fileTxt, fileMd;
  beforeEach(() => {
    config = require('../../config');
    config.post.dir = path.join(__dirname, '..', 'data', 'posts');
    config.page.dir = path.join(__dirname, '..', 'data', 'pages');
    fileTxt = fs.writeFileSync(path.join(config.post.dir, 'test.txt'), '');
    fileMd = fs.writeFileSync(path.join(config.post.dir, 'test.md'), '');
  });

  it('should abort, if the file is not .md', () => {
    fileHandler.deleteFile(fileTxt, config, (err, result) => {
      expect(err).to.be.defined;
      expect(result).to.be.null;
    });
  });

  it('should err out, if doesnt exist', () => {
    fileMd = 'test.md';
    fileHandler.deleteFile(fileMd, config, (err, result) => {
      expect(err).to.be.defined;
      expect(result).to.be.null;
    });
  });

  it('should delete the file, if the settings are valid', () => {
    fileHandler.deleteFile(path.join(config.post.dir, 'test.md'), config, (err, result) => {
      expect(err).to.be.null;
      expect(result).to.be.defined;
      expect(result).to.be.equal('Deleted.');
    });
  });

  afterEach(() => {
    fs.unlinkSync(path.join(config.post.dir, 'test.txt')); // cleanup
  });
});

@@ -159,16 +159,22 @@
 uire('fs
+-extra
 ');%0A%0Ades
@@ -365,35 +365,35 @@
 ');%0A    config.p
-age
+ost
 .dir = path.join
@@ -424,24 +424,96 @@
 , 'pages');%0A
+    fs.mkdirsSync(config.post.dir);%0A    fs.mkdirsSync(config.post.dir);%0A
   %7D);%0A  it('
@@ -2145,24 +2145,96 @@
 , 'pages');%0A
+    fs.mkdirsSync(config.post.dir);%0A    fs.mkdirsSync(config.post.dir);%0A
     fileTxt 

Update tests