Skip to content
Permalink
Browse files

refactor(tests): switch from insist to chai for assertions

  • Loading branch information...
philbooth committed May 15, 2019
1 parent cbb4af4 commit e93fdf9aa117a602681140ec53e47166866f7864

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -3,7 +3,7 @@

'use strict'

const assert = require('insist')
const { assert } = require('chai')
const sinon = require('sinon')

describe('bufferize', () => {
@@ -12,19 +12,19 @@ describe('bufferize', () => {
() => {

var bufferize = require('../../lib/bufferize')
assert.equal(typeof bufferize, 'object', 'bufferize exports object')
assert.equal(Object.keys(bufferize).length, 4, 'bufferize exports four functions')
assert.equal(typeof bufferize.unbuffer, 'function', 'bufferize exports unbuffer function')
assert.equal(typeof bufferize.bufferize, 'function', 'bufferize exports bufferize function')
assert.equal(typeof bufferize.bufferizeRequest, 'function', 'bufferize exports bufferizeRequest function')
assert.equal(typeof bufferize.hexToUtf8, 'function', 'bufferize exports hexToUtf8 function')
assert.isObject(bufferize)
assert.lengthOf(Object.keys(bufferize), 4)
assert.isFunction(bufferize.unbuffer)
assert.isFunction(bufferize.bufferize)
assert.isFunction(bufferize.bufferizeRequest)
assert.isFunction(bufferize.hexToUtf8)

var result = bufferize.unbuffer({
foo: Buffer.from('42', 'hex'),
bar: '42'
})
assert.equal(typeof result, 'object', 'bufferize.unbuffer returned object')
assert.equal(Object.keys(result).length, 2, 'bufferize.unbuffer returned correct number of properties')
assert.isObject(result)
assert.lengthOf(Object.keys(result), 2)
assert.equal(result.foo, '42', 'bufferize.unbuffer unbuffered correctly')
assert.equal(result.foo, '42', 'bufferize.unbuffer preserved string')

@@ -33,13 +33,13 @@ describe('bufferize', () => {
bar: 'ffff',
})

assert.equal(typeof result, 'object', 'bufferize.bufferize returned object')
assert.equal(Object.keys(result).length, 2, 'bufferize.bufferize returned correct number of properties')
assert.isObject(result)
assert.lengthOf(Object.keys(result), 2)
assert(Buffer.isBuffer(result.foo), 'bufferize.bufferize returned buffer for 00')
assert.equal(result.foo.length, 1, 'bufferize.bufferize returned correct length for 00')
assert.lengthOf(result.foo, 1)
assert.equal(result.foo[0], 0x00, 'bufferize.bufferize returned correct data for 00')
assert(Buffer.isBuffer(result.bar), 'bufferize.bufferize returned buffer for ffff')
assert.equal(result.bar.length, 2, 'bufferize.bufferize returned correct length for ffff')
assert.lengthOf(result.bar, 2)
assert.equal(result.bar[0], 0xff, 'bufferize.bufferize returned correct first byte for ffff')
assert.equal(result.bar[1], 0xff, 'bufferize.bufferize returned correct second byte for ffff')

@@ -49,13 +49,13 @@ describe('bufferize', () => {
wibble: '00'
}, new Set(['foo', 'bar']))

assert.equal(typeof result, 'object', 'bufferize.bufferize returned object')
assert.equal(Object.keys(result).length, 3, 'bufferize.bufferize returned correct number of properties')
assert.isObject(result)
assert.lengthOf(Object.keys(result), 3)
assert(Buffer.isBuffer(result.foo), 'bufferize.bufferize returned buffer for 00')
assert.equal(result.foo.length, 1, 'bufferize.bufferize returned correct length for 00')
assert.lengthOf(result.foo, 1)
assert.equal(result.foo[0], 0x00, 'bufferize.bufferize returned correct data for 00')
assert(Buffer.isBuffer(result.bar), 'bufferize.bufferize returned buffer for ffff')
assert.equal(result.bar.length, 2, 'bufferize.bufferize returned correct length for ffff')
assert.lengthOf(result.bar, 2)
assert.equal(result.bar[0], 0xff, 'bufferize.bufferize returned correct first byte for ffff')
assert.equal(result.bar[1], 0xff, 'bufferize.bufferize returned correct second byte for ffff')
assert.equal(result.wibble, '00', 'bufferize.bufferize ignored property not in match list')
@@ -66,13 +66,13 @@ describe('bufferize', () => {
baz: undefined
}, new Set(['foo', 'bar', 'baz']))

assert.equal(typeof result, 'object', 'bufferize.bufferize returned object')
assert.equal(Object.keys(result).length, 3, 'bufferize.bufferize returned correct number of properties')
assert.isObject(result)
assert.lengthOf(Object.keys(result), 3)
assert(Buffer.isBuffer(result.foo), 'bufferize.bufferize returned buffer for 00')
assert.equal(result.foo.length, 1, 'bufferize.bufferize returned correct length for 00')
assert.lengthOf(result.foo, 1)
assert.equal(result.foo[0], 0x00, 'bufferize.bufferize returned correct data for 00')
assert.equal(result.bar, null, 'bufferize.bufferize ignored property that was set to null')
assert.equal(result.baz, undefined, 'bufferize.bufferize ignored property that was undefined')
assert.isNull(result.bar)
assert.isUndefined(result.baz)

var request = {
body: {
@@ -89,26 +89,26 @@ describe('bufferize', () => {
var keys = new Set(['yes', 'y'])
bufferize.bufferizeRequest(keys, request, {}, next)

assert.equal(Object.keys(request).length, 2, 'bufferize.bufferizeRequest did not mess with request')
assert.lengthOf(Object.keys(request), 2)

assert.equal(Object.keys(request.body).length, 3, 'bufferize.bufferizeRequest did not mess with request.body')
assert.lengthOf(Object.keys(request.body), 3)
assert.equal(request.body.no, 'badf00d', 'bufferize.bufferizeRequest preserved body string badf00d')
assert.equal(request.body.nope, 'f00d', 'bufferize.bufferizeRequest ignored body property not in matchlist')
assert(Buffer.isBuffer(request.body.yes), 'bufferize.bufferizeRequest returned buffer for body f00d')
assert.equal(request.body.yes.length, 2, 'bufferize.bufferizeRequest returned correct length for body f00d')
assert.lengthOf(request.body.yes, 2)
assert.equal(request.body.yes[0], 0xf0, 'bufferize.bufferizeRequest returned correct first byte for body f00d')
assert.equal(request.body.yes[1], 0x0d, 'bufferize.bufferizeRequest returned correct second byte for body f00d')

assert.equal(Object.keys(request.params).length, 2, 'bufferize.bufferizeRequest did not mess with request.params')
assert.lengthOf(Object.keys(request.params), 2)
assert(Buffer.isBuffer(request.params.y), 'bufferize.bufferizeRequest returned buffer for params deadbeef')
assert.equal(request.params.y.length, 4, 'bufferize.bufferizeRequest returned correct length for params deadbeef')
assert.lengthOf(request.params.y, 4)
assert.equal(request.params.y[0], 0xde, 'bufferize.bufferizeRequest returned correct first byte for params deadbeef')
assert.equal(request.params.y[1], 0xad, 'bufferize.bufferizeRequest returned correct second byte for params deadbeef')
assert.equal(request.params.y[2], 0xbe, 'bufferize.bufferizeRequest returned correct third byte for params deadbeef')
assert.equal(request.params.y[3], 0xef, 'bufferize.bufferizeRequest returned correct fourth byte for params deadbeef')
assert.equal(request.params.n, 'deadbeef', 'bufferize.bufferizeRequest ignored params not in matchlist')
assert(next.calledOnce, 'bufferize.bufferizeRequest called next')
assert.equal(next.getCall(0).args.length, 0, 'bufferize.bufferizeRequest called next with no arguments')
assert.lengthOf(next.getCall(0).args, 0)

request = {
body: {
@@ -118,11 +118,11 @@ describe('bufferize', () => {
next = sinon.spy()
bufferize.bufferizeRequest(null, request, {}, next)

assert.equal(Object.keys(request).length, 1, 'bufferize.bufferizeRequest did not mess with request')
assert.equal(Object.keys(request.body).length, 1, 'bufferize.bufferizeRequest did not mess with request.body')
assert.lengthOf(Object.keys(request), 1)
assert.lengthOf(Object.keys(request.body), 1)
assert.equal(request.body.buf, 'invalid', 'bufferize.bufferizeRequest did not overwrite invalid field in body')
assert(next.calledOnce, 'bufferize.bufferizeRequest called next')
assert.equal(next.getCall(0).args.length, 1, 'bufferize.bufferizeRequest called next with one argument')
assert.lengthOf(next.getCall(0).args, 1)
assert.equal(next.getCall(0).args[0].statusCode, 400, 'bufferize.bufferizeRequest called next with a 400 error')
}
)
@@ -3,17 +3,17 @@

'use strict'

const assert = require('insist')
const { assert } = require('chai')

describe('error', () => {
it(
'error module',
() => {
const error = require('../../lib/error')
assert.equal(typeof error, 'function', 'error module returns a function')
assert.isFunction(error)

const duplicate = error.duplicate()
assert.equal(typeof duplicate, 'object', 'duplicate returns an object')
assert.isObject(duplicate)
assert(duplicate instanceof error, 'is an instance of error')
assert.equal(duplicate.code, 409)
assert.equal(duplicate.errno, 101)
@@ -22,7 +22,7 @@ describe('error', () => {
assert.equal(duplicate.toString(), 'Error: Record already exists')

const notFound = error.notFound()
assert.equal(typeof notFound, 'object', 'notFound returns an object')
assert.isObject(notFound)
assert(notFound instanceof error, 'is an instance of error')
assert.equal(notFound.code, 404)
assert.equal(notFound.errno, 116)
@@ -34,7 +34,7 @@ describe('error', () => {
err.code = 'ER_QUERY_INTERRUPTED'
err.errno = 1317
const wrap = error.wrap(err)
assert.equal(typeof wrap, 'object', 'wrap returns an object')
assert.isObject(wrap)
assert(wrap instanceof error, 'is an instance of error')
assert.equal(wrap.code, 500)
assert.equal(wrap.errno, 1317)
@@ -3,12 +3,12 @@

'use strict'

const assert = require('insist')
const { assert } = require('chai')
const safeJsonFormatter = require('../../lib/safeJsonFormatter')

describe('safeJsonFormatter module', () => {
it('safeJsonFormatter function exported', () => {
assert.equal(typeof safeJsonFormatter === 'function', true)
assert.isFunction(safeJsonFormatter)
})

it('escapes input', () => {
Oops, something went wrong.

0 comments on commit e93fdf9

Please sign in to comment.
You can’t perform that action at this time.