Skip to content

Commit

Permalink
Start working on CLI and implement JSON test data generator.
Browse files Browse the repository at this point in the history
  • Loading branch information
daern91 committed Feb 3, 2018
1 parent e724336 commit d247610
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ build/Release
# Dependency directories
node_modules/
jspm_packages/
.vscode/

# Typescript v1 declaration files
typings/
Expand All @@ -57,3 +58,5 @@ typings/
# dotenv environment variables file
.env

# test data
testCustomers/
14 changes: 14 additions & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env node

const program = require('commander');
const lib = require('../src');

program
.version('1.0.0')
.command('greet [name]')
.action(name => {
const greeting = lib.sayHello(name);
console.log(greeting);
});

program.parse(process.argv);
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
"version": "0.0.3",
"description": "",
"main": "lib/index.js",
"bin": {
"clitest": "bin/cli.js"
},
"scripts": {
"test": "mocha --reporter spec",
"cover": "node_modules/istanbul/lib/cli.js cover node_modules/mocha/bin/_mocha -- -R spec test/*"
"cover": "node_modules/istanbul/lib/cli.js cover node_modules/mocha/bin/_mocha -- -R spec test/*",
"generate-data": "node scripts/generateData.js"
},
"repository": {
"type": "git",
Expand All @@ -20,7 +24,9 @@
"devDependencies": {
"chai": "^4.1.2",
"coveralls": "^3.0.0",
"faker": "^4.1.0",
"istanbul": "^0.4.5",
"make-dir": "^1.1.0",
"mocha": "^5.0.0"
},
"dependencies": {
Expand Down
12 changes: 12 additions & 0 deletions scripts/generateData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const createCustomer = require('../test/fixtures');
const makeDir = require('make-dir');
const fs = require('fs');

makeDir('testCustomers').then(path => {
const customers = [];
for (let i = 0; i < 10; i++) {
customers.push(createCustomer());
}

fs.writeFileSync('testCustomers/data.json', JSON.stringify(customers, null, 2));
});
3 changes: 2 additions & 1 deletion test/buildActions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

const expect = require('chai').expect,
buildActions = require('../src/buildActions');
buildActions = require('../src/buildActions'),
createCustomer = require('./fictures');

describe('#buildActions', function() {
//TODO: Add generator for test objects
Expand Down
26 changes: 26 additions & 0 deletions test/fixtures.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

const faker = require('faker');

module.exports = function createCustomer() {
const addresses = [];
const amount = Math.ceil(Math.random() * 3);

for (let i = 0; i < amount; i++) {
addresses.push({
address: faker.address.streetAddress(),
addressId: faker.random.uuid()
});
}

return {
id: faker.random.uuid(),
email: faker.internet.email(),
firstName: faker.name.firstName(),
lastName: faker.name.lastName(),
middleName: faker.name.firstName(),
customerGroup: faker.commerce.department(),
companyName: faker.company.companyName(),
address: addresses
};
};

0 comments on commit d247610

Please sign in to comment.