Skip to content

Commit

Permalink
Update dependencies and tests for stable release (#692)
Browse files Browse the repository at this point in the history
* npm audit fix to fix vulnerabilities

* fix publish test

* fix render test

* silence logs that we are expecting

* fix composer tests
  • Loading branch information
jpope19 authored Jan 21, 2021
1 parent 99250ad commit cbc05ed
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 88 deletions.
4 changes: 2 additions & 2 deletions lib/render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ describe(_.startCase(filename), function () {
};

// when we find the new reference
db.get.returns(bluebird.resolve('domain.com/_uris/' + new Buffer(resultRef).toString('base64')));
db.get.returns(bluebird.resolve('domain.com/_uris/' + Buffer.from(resultRef).toString('base64')));

return fn('/_uris/asdf', requestObj, mockRes).then(function () {
expect(mockRes.redirect.callCount).to.equal(1);
Expand All @@ -254,7 +254,7 @@ describe(_.startCase(filename), function () {
mockRes.req.protocol = 'http';

// when we find the new reference
db.get.returns(bluebird.resolve('example.com/_uris/' + new Buffer(resultRef).toString('base64')));
db.get.returns(bluebird.resolve('example.com/_uris/' + Buffer.from(resultRef).toString('base64')));

return fn('/_uris/asdf', requestObj, mockRes).then(function () {
expect(mockRes.redirect.calledWith(301, `${mockRes.req.protocol}://${resultRef}${requestObj._parsedUrl.search}`)).to.be.true;
Expand Down
32 changes: 14 additions & 18 deletions lib/services/composer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,43 +95,41 @@ describe(_.startCase(filename), function () {
});
});

it('adds additional reference information to any errors that occur', function (done) {
it('adds additional reference information to any errors that occur', function () {
const data = {
a: {_ref: '/c/b'},
c: {d: {_ref: '/c/e'}}
},
myError = new Error('hello!');
errorMessage = 'hello 1!',
myError = new Error(errorMessage);

components.get.withArgs('/c/b').returns(bluebird.resolve({g: 'h'}));
components.get.withArgs('/c/e').returns(bluebird.resolve({i: 'j', k: {_ref: '/c/m'}}));
components.get.withArgs('/c/m').returns(bluebird.reject(myError));

// use done() rather than returning the promise, so we can catch and test errors
fn(data).then(done).catch((error) => {
return fn(data).catch((error) => {
sinon.assert.calledOnce(logSpy);
expect(error.message).to.equal('hello!');
done();
expect(error.message).to.equal(errorMessage);
});
});

it('adds the status to the error message if it one is defined', function (done) {
it('adds the status to the error message if it one is defined', function () {
const data = {
a: {_ref: '/c/b'},
c: {d: {_ref: '/c/e'}}
},
myError = new Error('hello!');
errorMessage = 'hello 2!',
myError = new Error(errorMessage);

myError.status = 404;
components.get.withArgs('/c/b').returns(bluebird.resolve({g: 'h'}));
components.get.withArgs('/c/e').returns(bluebird.resolve({i: 'j', k: {_ref: '/c/m'}}));
components.get.withArgs('/c/m').returns(bluebird.reject(myError));

// use done() rather than returning the promise, so we can catch and test errors
fn(data).then(done).catch((error) => {
return fn(data).catch((error) => {
sinon.assert.calledOnce(logSpy);
expect(error.message).to.equal('hello!');
sinon.assert.calledWith(logSpy, 'error', 'hello!', { status: myError.status, cmpt: '/c/e', stack: myError.stack });
done();
expect(error.message).to.equal(errorMessage);
sinon.assert.calledWith(logSpy, 'error', errorMessage, { status: myError.status, cmpt: '/c/e', stack: myError.stack });
});
});
});
Expand Down Expand Up @@ -159,15 +157,15 @@ describe(_.startCase(filename), function () {

});

it('composes pages', function (done) {
it('composes pages', function () {
const pageData = {
head: [
'/a/b'
],
layout: '/some/layout'
};

fn(pageData)
return fn(pageData)
.then((result) => {
expect(result).to.deep.equal({
head: [{
Expand All @@ -179,9 +177,7 @@ describe(_.startCase(filename), function () {
g: 'h'
}]
});
})
.then(done)
.catch(done);
});
});

it('throws errors if page data is not defined', function () {
Expand Down
12 changes: 6 additions & 6 deletions lib/services/publish.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ describe(_.startCase(filename), function () {
const fn = lib[this.title];

it('does not process all rules once one resolves', function () {
rule1.returns(Promise.reject(new Error(0)));
rule2.returns(Promise.resolve('foo.com/bar/baz'));
rule1.rejects(new Error(0));
rule2.resolves('foo.com/bar/baz');

const uri = 'http://example.com/uri@published';

db.getMeta.returns(Promise.resolve({ archived: false }));
db.getMeta.resolves({ archived: false });

return fn([ () => Promise.reject(new Error(0)), rule2, rule3 ], uri)
.then(() => {
Expand All @@ -68,12 +68,12 @@ describe(_.startCase(filename), function () {
});

it('does not process if archived is true', function () {
rule1.returns(Promise.reject(new Error(0)));
rule2.returns(Promise.resolve('foo.com/bar/baz'));
rule1.rejects(new Error(0));
rule2.resolves('foo.com/bar/baz');

const uri = 'http://example.com/uri@published';

db.getMeta.returns(Promise.resolve({ archived: true }));
db.getMeta.resolves({ archived: true });

return fn([ rule1, rule2, rule3 ], uri)
.then(() => {
Expand Down
110 changes: 50 additions & 60 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
"express-flash": "0.0.2",
"express-session": "^1.14.1",
"glob": "^7.0.0",
"handlebars": "^4.0.5",
"handlebars": "^4.7.6",
"highland": "^2.11.1",
"ioredis": "^4.0.0",
"js-yaml": "^3.2.0",
"lodash": "^4.14.2",
"lodash": "^4.17.20",
"node-fetch": "^1.3.0",
"passport": "^0.3.2",
"passport-google-oauth": "^1.0.0",
Expand Down
4 changes: 4 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const glob = require('glob'),
chai.config.showDiff = true;
chai.config.truncateThreshold = 0;

// when we are testing to make sure errors are being thrown,
// we don't want to log errors because it makes it seem like the test is failing
process.env.LOG = process.env.LOG || 'silent';

// make sure the index file can be loaded at least
require('..');
// The DB service gets a little borked because of how we have
Expand Down

0 comments on commit cbc05ed

Please sign in to comment.