2016-01-29 20:23:57 +00:00
|
|
|
/**
|
2016-02-11 17:08:11 +00:00
|
|
|
High-level API test routines for HackMyResume. Test HackMyResume verbs such
|
|
|
|
as build, new, peek, etc., by creating and invoking a Verb object.
|
|
|
|
@module test-verbs.js
|
|
|
|
@license MIT. See LICENSE.md for details.
|
2016-01-29 20:23:57 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
var chai = require('chai')
|
2018-01-29 03:34:05 +00:00
|
|
|
, chaiAsPromised = require("chai-as-promised")
|
2016-01-29 20:23:57 +00:00
|
|
|
, path = require('path')
|
|
|
|
, _ = require('underscore')
|
2018-02-14 15:13:48 +00:00
|
|
|
, FRESHResume = require('../../src/core/fresh-resume')
|
|
|
|
, FCMD = require( '../../src/index')
|
2016-01-29 20:23:57 +00:00
|
|
|
, validator = require('is-my-json-valid')
|
|
|
|
, EXTEND = require('extend');
|
|
|
|
|
2018-01-29 03:34:05 +00:00
|
|
|
// Initialize Chai As Promised
|
|
|
|
chai.use(chaiAsPromised);
|
|
|
|
expect = chai.expect;
|
|
|
|
assert = chai.assert;
|
|
|
|
should = chai.should();
|
2016-01-29 20:23:57 +00:00
|
|
|
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/';
|
|
|
|
|
2018-01-29 03:34:05 +00:00
|
|
|
// Assemble an array of tests, taking the form of parameters we'll pass to
|
|
|
|
// each of the defined HackMyResume verbs.
|
2016-01-29 20:23:57 +00:00
|
|
|
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)'
|
|
|
|
],
|
|
|
|
|
2018-01-29 03:34:05 +00:00
|
|
|
[ '!new',
|
2016-01-29 20:23:57 +00:00
|
|
|
[],
|
|
|
|
[],
|
|
|
|
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',
|
2018-02-01 10:58:35 +00:00
|
|
|
['node_modules/fresh-test-resumes/src/jrs/richard-hendriks.json'],
|
2016-01-29 20:23:57 +00:00
|
|
|
[],
|
|
|
|
opts2,
|
|
|
|
' (richard-hendriks.json|JRS)'
|
|
|
|
],
|
|
|
|
|
|
|
|
[ 'validate',
|
2018-02-01 10:58:35 +00:00
|
|
|
['node_modules/fresh-test-resumes/src/jrs/jane-incomplete.json'],
|
2016-01-29 20:23:57 +00:00
|
|
|
[],
|
|
|
|
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',
|
2018-02-01 10:58:35 +00:00
|
|
|
['node_modules/fresh-test-resumes/src/jrs/richard-hendriks.json'],
|
2016-01-29 20:23:57 +00:00
|
|
|
[],
|
|
|
|
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'
|
|
|
|
];
|
2018-01-29 03:34:05 +00:00
|
|
|
|
|
|
|
Object.keys( _.pick( r, expected ) ).length
|
|
|
|
.should.equal( expected.length );
|
2016-01-29 20:23:57 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
|
2018-01-29 03:34:05 +00:00
|
|
|
[ '!build',
|
2016-01-29 20:23:57 +00:00
|
|
|
[ ft + 'jane-fullstacker.json'],
|
|
|
|
[ sb + 'shouldnt-exist.pdf' ],
|
|
|
|
EXTEND(true, {}, opts, { theme: 'awesome' }),
|
|
|
|
' (jane-q-fullstacker + Awesome + PDF|FRESH)'
|
|
|
|
]
|
|
|
|
|
|
|
|
];
|
|
|
|
|
2018-01-29 03:34:05 +00:00
|
|
|
// Set up the main test suite for the API interface
|
2016-01-29 20:23:57 +00:00
|
|
|
describe('Testing API interface', function () {
|
|
|
|
|
2018-01-29 03:34:05 +00:00
|
|
|
this.timeout(5000);
|
2016-01-29 20:23:57 +00:00
|
|
|
|
2018-01-29 03:34:05 +00:00
|
|
|
function run( verb, src, dst, opts, msg, fnTest ) {
|
|
|
|
|
|
|
|
msg = msg || '.';
|
|
|
|
var shouldSucceed = true;
|
|
|
|
if( verb[0] === '!' ) {
|
|
|
|
verb = verb.substr(1);
|
|
|
|
shouldSucceed = false;
|
|
|
|
}
|
2016-01-29 20:23:57 +00:00
|
|
|
|
2018-01-29 03:34:05 +00:00
|
|
|
it( 'The ' + verb.toUpperCase() + ' command should ' +
|
|
|
|
(shouldSucceed ? ' SUCCEED' : ' FAIL') + msg, function (done) {
|
|
|
|
|
|
|
|
var v = new FCMD.verbs[verb]();
|
|
|
|
v.on('hmr:error', function(ex) {
|
|
|
|
assert(false);
|
2016-01-29 20:23:57 +00:00
|
|
|
});
|
2018-01-29 03:34:05 +00:00
|
|
|
var prom = v.invoke( src, dst, opts );
|
|
|
|
var fulfillMethod = shouldSucceed ? 'fulfilled' : 'rejected';
|
2016-01-29 20:23:57 +00:00
|
|
|
|
2018-01-29 03:34:05 +00:00
|
|
|
if( fnTest ) {
|
|
|
|
prom.should.be[ fulfillMethod ].then( function( obj ) {
|
|
|
|
fnTest(obj.sheet);
|
|
|
|
}).should.notify(done);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
prom.should.be[fulfillMethod].notify(done);
|
|
|
|
}
|
2016-01-29 20:23:57 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2018-01-29 03:34:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tests.forEach( function(a) {
|
|
|
|
run.apply( /* The players of */ null, a );
|
|
|
|
});
|
|
|
|
|
2016-01-29 20:23:57 +00:00
|
|
|
});
|