all files / js/ routeGenerator_spec.js

96.97% Statements 32/33
100% Branches 0/0
100% Functions 7/7
96.97% Lines 32/33
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63                                                             
'use strict';
 
let path = require('path');
let fse = require('fs-extra');
let expect = require('chai').expect;
const RouteGenerator = require('./routeGenerator');
 
const routeName = 'login';
const testPath = path.join('src', 'ts', 'app', 'routes', routeName);
 
describe('RouteGenerator functionalities', function () {
 
  before(function () {
  });
 
  it('should create the folder structure for the new route when initialized', function () {
 
    new RouteGenerator(routeName);
 
    checkIfDirectoriesExists();
  });
 
  it('should create all the files needed for the new route', function () {
    var rg = new RouteGenerator(routeName);
 
    rg._createNewFiles();
 
    chekIfFilesExistsAndAreCorrects();
  });
 
  after(function () {
    fse.removeSync('./src/ts');
  });
 
});
 
 
function checkIfDirectoriesExists() {
  var check = false;
  try {
    fse.accessSync(testPath, fse.F_OK);
    check = true;
  } catch (e) {
    check = false;
  }
 
  expect(check).to.be.true;
}
 
function chekIfFilesExistsAndAreCorrects() {
  var componentFile = fse.readFileSync(testPath + path.sep + `${routeName}.component.ts`, 'utf8');
  expect(componentFile, '[componentFile]').to.have.string(`export class ${routeName}Component`);
 
  var controllerFile = fse.readFileSync(testPath + path.sep + `${routeName}.controller.ts`, 'utf8');
  expect(controllerFile, '[controllerFile]').to.have.string(`export class ${routeName}Controller`);
 
  var moduleFile = fse.readFileSync(testPath + path.sep + `${routeName}.module.ts`, 'utf8');
  expect(moduleFile, '[moduleFile]').to.have.string(`export class ${routeName}Module`);
 
  var routeFile = fse.readFileSync(testPath + path.sep + `${routeName}.route.ts`, 'utf8');
  expect(routeFile, '[routeFile]').to.have.string(`export class ${routeName}Route`);
}