all files / src/ routeGenerator_spec.js

97.22% Statements 35/36
100% Branches 0/0
100% Functions 7/7
97.22% Lines 35/36
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 64 65 66 67                                                               
'use strict';
 
let path = require('path');
let fse = require('fs-extra');
let expect = require('chai').expect
let ConfigResolver = require('./configResolver');
let RouteGenerator = require('./routeGenerator');
 
const config = new ConfigResolver();
const routeName = 'login';
const testPath = path.join(config.getRoutesRoot(), routeName);
 
describe('RouteGenerator functionalities', function () {
 
  before(function () {
  });
 
  it('should create the folder structure for the new route when initialized', function () {
 
    new RouteGenerator(routeName, config);
 
    checkIfDirectoriesExists();
  });
 
  it('should create all the files needed for the new route', function () {
    var rg = new RouteGenerator(routeName, config);
 
    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 let ${routeName}Module`);
  expect(moduleFile, '[moduleFile]').to.have.string(`.config(${routeName}Route);`);
 
  var routeFile = fse.readFileSync(testPath + path.sep + `${routeName}.route.ts`, 'utf8');
  expect(routeFile, '[routeFile]').to.have.string(`export function ${routeName}Route`);
 
}