1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2025-05-02 12:27:08 +01:00

Relocate internal sources to HackMyAPI.

Move internal sources and related tests to:

https://github.com/hacksalot/HackMyAPI
This commit is contained in:
hacksalot
2016-01-24 09:55:04 -05:00
parent fa29f9794d
commit d3194fba19
61 changed files with 15 additions and 6109 deletions

View File

@ -1,207 +0,0 @@
/**
@module test-api.js
*/
var chai = require('chai')
, expect = chai.expect
, should = chai.should()
, path = require('path')
, _ = require('underscore')
, FRESHResume = require('../src/core/fresh-resume')
, FCMD = require( '../src/hackmyapi')
, validator = require('is-my-json-valid')
, HMRMAIN = require('../src/cli/main')
, EXTEND = require('extend');
chai.config.includeStack = false;
var _sheet;
var opts = {
format: 'FRESH',
prettify: true,
silent: false,
assert: true // Causes validation errors to throw exceptions
};
var opts2 = {
format: 'JRS',
prettify: true,
silent: true
};
var sb = 'test/sandbox/';
var ft = 'node_modules/fresh-test-resumes/src/fresh/';
var tests = [
[ 'new',
[sb + 'new-fresh-resume.json'],
[],
opts,
' (FRESH format)'
],
[ 'new',
[sb + 'new-jrs-resume.json'],
[],
opts2,
' (JRS format)'
],
[
'new',
[sb + 'new-1.json', sb + 'new-2.json', sb + 'new-3.json'],
[],
opts,
' (multiple FRESH resumes)'
],
[ 'new',
[sb + 'new-jrs-1.json', sb + 'new-jrs-2.json', sb + 'new-jrs-3.json'],
[],
opts,
' (multiple JRS resumes)'
],
[ '!new',
[],
[],
opts,
" (when a filename isn't specified)"
],
[ 'validate',
[ft + 'jane-fullstacker.json'],
[],
opts,
' (jane-q-fullstacker|FRESH)'
],
[ 'validate',
[ft + 'johnny-trouble.json'],
[],
opts,
' (johnny-trouble|FRESH)'
],
[ 'validate',
[sb + 'new-fresh-resume.json'],
[],
opts,
' (new-fresh-resume|FRESH)'
],
[ 'validate',
['test/resumes/jrs-0.0.0/richard-hendriks.json'],
[],
opts2,
' (richard-hendriks.json|JRS)'
],
[ 'validate',
['test/resumes/jrs-0.0.0/jane-incomplete.json'],
[],
opts2,
' (jane-incomplete.json|JRS)'
],
[ 'validate',
[sb + 'new-1.json', sb + 'new-jrs-resume.json', sb + 'new-1.json',
sb + 'new-2.json', sb + 'new-3.json'],
[],
opts,
' (5|BOTH)'
],
[ 'analyze',
[ft + 'jane-fullstacker.json'],
[],
opts,
' (jane-q-fullstacker|FRESH)'
],
[ 'analyze',
['test/resumes/jrs-0.0.0/richard-hendriks.json'],
[],
opts2,
' (richard-hendriks|JRS)'
],
[ 'build',
[ ft + 'jane-fullstacker.json', ft + 'override/jane-fullstacker-override.fresh.json' ],
[ sb + 'merged/jane-fullstacker-gamedev.fresh.all'],
opts,
' (jane-q-fullstacker w/ override|FRESH)'
],
[ 'build',
[ ft + 'override/jane-partial-a.json', ft + 'override/jane-partial-b.json',
ft + 'override/jane-partial-c.json' ],
[ sb + 'merged/jane-abc.fresh.all'],
opts,
' (jane merge A + B + C|FRESH)',
function( r ) {
var expected = [
'name','meta','info', 'contact', 'location', 'projects', 'social',
'employment', 'education', 'affiliation', 'service', 'skills',
'samples', 'writing', 'reading', 'speaking', 'recognition',
'references', 'testimonials', 'languages', 'interests',
'extracurricular', 'governance'
];
return Object.keys( _.pick( r, expected ) ).length === expected.length;
}
],
[ '!build',
[ ft + 'jane-fullstacker.json'],
[ sb + 'shouldnt-exist.pdf' ],
EXTEND(true, {}, opts, { theme: 'awesome' }),
' (jane-q-fullstacker + Awesome + PDF|FRESH)'
]
];
describe('Testing API interface', function () {
function run( verb, src, dst, opts, msg, fnTest ) {
msg = msg || '.';
var shouldSucceed = true;
if( verb[0] === '!' ) {
verb = verb.substr(1);
shouldSucceed = false;
}
it( 'The ' + verb.toUpperCase() + ' command should ' + (shouldSucceed ? ' SUCCEED' : ' FAIL') + msg, function () {
function runIt() {
try {
var v = new FCMD.verbs[verb]();
v.on('hmr:error', function(ex) { throw ex; });
var r = v.invoke( src, dst, opts );
if( fnTest )
if( !fnTest( r.sheet ) )
throw "Test: Unexpected API result.";
}
catch(ex) {
console.error(ex);
if( ex.stack || (ex.inner && ex.inner.stack))
console.error( ex.stack || ex.inner.stack );
throw ex;
}
}
if( shouldSucceed )
runIt.should.not.Throw();
else
runIt.should.Throw();
});
}
tests.forEach( function(a) {
run.apply( /* The players of */ null, a );
});
});

View File

@ -1,71 +0,0 @@
var chai = require('chai')
, expect = chai.expect
, should = chai.should()
, path = require('path')
, _ = require('underscore')
, FRESHResume = require('../src/core/fresh-resume')
, validator = require('is-my-json-valid');
chai.config.includeStack = false;
function testResume(opts) {
describe( opts.title + ' (FRESH)', function () {
var _sheet;
it('should open without throwing an exception', function () {
function tryOpen() {
_sheet = new FRESHResume().open( opts.path );
}
tryOpen.should.not.Throw();
});
it('should have one or more of each section', function() {
var newObj = _.pick( _sheet, opts.sections );
expect( Object.keys(newObj).length ).to.equal( opts.sections.length );
});
it('should have a work duration of ' + opts.duration + ' years', function() {
_sheet.computed.numYears.should.equal( opts.duration );
});
it('should save without throwing an exception', function(){
function trySave() {
_sheet.save( 'test/sandbox/' + opts.title + '.json' );
}
trySave.should.not.Throw();
});
it('should not be modified after saving', function() {
var savedSheet = new FRESHResume().open('test/sandbox/' + opts.title + '.json');
_sheet.stringify().should.equal( savedSheet.stringify() );
});
it('should validate against the FRESH resume schema', function() {
var result = _sheet.isValid();
// var schemaJson = require('fresca');
// var validate = validator( schemaJson, { verbose: true } );
// var result = validate( JSON.parse( _sheet.imp.raw ) );
result || console.log("\n\nOops, resume didn't validate. " +
"Validation errors:\n\n", _sheet.imp.validationErrors, "\n\n");
result.should.equal( true );
});
});
}
var sects = [ 'info', 'employment', 'service', 'skills', 'education', 'writing', 'recognition', 'references' ];
testResume({ title: 'jane-q-fullstacker', path: 'node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json', duration: 7, sections: sects });
testResume({ title: 'johnny-trouble-resume', path: 'node_modules/fresh-test-resumes/src/fresh/johnny-trouble.json', duration: 4, sections: sects });
sects = [ 'info', 'contact', 'location' ];
testResume({ title: 'jane-q-fullstacker A', path: 'node_modules/fresh-test-resumes/src/fresh/override/jane-partial-a.json', duration: 0, sections: sects });
sects = [ 'projects', 'social', 'employment', 'education', 'affiliation' ];
testResume({ title: 'jane-q-fullstacker B', path: 'node_modules/fresh-test-resumes/src/fresh/override/jane-partial-b.json', duration: 7, sections: sects });
sects = [ 'service', 'skills', 'samples', 'writing', 'reading', 'speaking', 'recognition', 'references', 'testimonials', 'languages', 'interests', 'extracurricular', 'governance' ];
testResume({ title: 'jane-q-fullstacker C', path: 'node_modules/fresh-test-resumes/src/fresh/override/jane-partial-c.json', duration: 0, sections: sects });

View File

@ -1,69 +0,0 @@
var chai = require('chai')
, expect = chai.expect
, should = chai.should()
, path = require('path')
, _ = require('underscore')
, JRSResume = require('../src/core/jrs-resume')
, validator = require('is-my-json-valid');
chai.config.includeStack = false;
function testResume( opts ) {
describe( opts.title + ' (JRS)', function() {
opts.isValid = opts.isValid !== false;
var _sheet;
it('should open without throwing an exception', function () {
var that = this;
function tryOpen() {
_sheet = new JRSResume().open(
path.join( __dirname, 'resumes/jrs-0.0.0/' + opts.title + '.json' ) );
}
tryOpen.should.not.Throw();
});
it('should have one or more of each section', function() {
var newObj = _.pick( _sheet, opts.sections );
expect( Object.keys(newObj).length ).to.equal( opts.sections.length );
});
it('should have a work duration of ' + opts.duration + ' years', function() {
_sheet.basics.computed.numYears.should.equal( opts.duration );
});
it('should save without throwing an exception', function() {
var that = this;
function trySave() {
_sheet.save( 'test/sandbox/' + opts.title + '.json' );
}
trySave.should.not.Throw();
});
it('should not be modified after saving', function() {
var savedSheet = new JRSResume().open( 'test/sandbox/' + opts.title + '.json' );
_sheet.stringify().should.equal( savedSheet.stringify() );
});
it('should ' + (opts.isValid ? '' : 'NOT ') + 'validate against the JSON Resume schema', function() {
var result = _sheet.isValid();
// var schemaJson = require('../src/core/resume.json');
// var validate = validator( schemaJson, { verbose: true } );
// var result = validate( JSON.parse( _sheet.imp.raw ) );
result || console.log("\n\nOops, resume didn't validate. " +
"Validation errors:\n\n", _sheet.basics.imp.validationErrors, "\n\n");
result.should.equal( opts.isValid );
});
});
}
var sects = [ 'basics', 'work', 'volunteer', 'skills', 'education', 'publications', 'awards', 'references' ];
testResume({ title: 'jane-q-fullstacker', duration: 7, sections: sects });
testResume({ title: 'jane-incomplete', duration: 0, sections: _.without(sects, 'awards', 'work') });
testResume({ title: 'richard-hendriks', duration: 1, sections: sects });
testResume({ title: 'empty', duration: 0, sections: [], isValid: false });

View File

@ -1,86 +0,0 @@
var chai = require('chai')
, expect = chai.expect
, should = chai.should()
, path = require('path')
, _ = require('underscore')
, FRESHResume = require('../src/core/fresh-resume')
, HMR = require( '../src/hackmyapi')
, validator = require('is-my-json-valid')
, READFILES = require('recursive-readdir-sync')
, fileContains = require('../src/utils/file-contains')
, FS = require('fs')
, CHALK = require('chalk');
chai.config.includeStack = true;
function genThemes( title, src, fmt ) {
describe('Testing themes against ' + title.toUpperCase() + ' resume ' + '(' + fmt + ')' , function () {
var _sheet;
function genTheme( fmt, src, themeName, themeLoc, testTitle ) {
themeLoc = themeLoc || themeName;
testTitle = themeName.toUpperCase() + ' theme (' + fmt + ') should generate without throwing an exception';
it( testTitle, function () {
function tryOpen() {
//var src = ['node_modules/jane-q-fullstacker/resume/jane-resume.json'];
var dst = ['test/sandbox/' + fmt + '/' + title + '/' + themeName + '/resume.all'];
var opts = {
theme: themeLoc,
format: fmt,
prettify: true,
silent: false,
css: 'embed',
debug: true
};
try {
var v = new HMR.verbs.build();
v.invoke( src, dst, opts );
}
catch(ex) {
console.error( ex );
console.error( ex.stack );
throw ex;
}
}
tryOpen.should.not.Throw();
});
}
genTheme(fmt, src, 'hello-world');
genTheme(fmt, src, 'compact');
genTheme(fmt, src, 'modern');
genTheme(fmt, src, 'underscore');
genTheme(fmt, src, 'awesome');
genTheme(fmt, src, 'positive');
genTheme(fmt, src, 'jsonresume-theme-boilerplate', 'node_modules/jsonresume-theme-boilerplate' );
genTheme(fmt, src, 'jsonresume-theme-sceptile', 'node_modules/jsonresume-theme-sceptile' );
genTheme(fmt, src, 'jsonresume-theme-modern', 'node_modules/jsonresume-theme-modern' );
genTheme(fmt, src, 'jsonresume-theme-classy', 'node_modules/jsonresume-theme-classy' );
});
}
function folderContains( needle, haystack ) {
return _.some( READFILES( path.join(__dirname, haystack) ), function( absPath ) {
if( FS.lstatSync( absPath ).isFile() ) {
if( fileContains( absPath, needle ) ) {
console.error('Found invalid metadata in ' + absPath);
return true;
}
}
});
}
genThemes( 'jane-q-fullstacker', ['node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json'], 'FRESH' );
genThemes( 'johnny-trouble', ['node_modules/fresh-test-resumes/src/fresh/johnny-trouble.json'], 'FRESH' );
genThemes( 'richard-hendriks', ['test/resumes/jrs-0.0.0/richard-hendriks.json'], 'JRS' );
describe('Verifying generated theme files...', function() {
it('Generated files should not contain ICE.', function() {
expect( folderContains('@@@@', 'sandbox') ).to.be.false;
});
});