Skip to content

Commit

Permalink
test(data-point): remove duplicate tests (#147)
Browse files Browse the repository at this point in the history
Corrected and clarified descriptions of tests

Closes #105
  • Loading branch information
Victor Singh authored and paulmolluzzo committed Jan 24, 2018
1 parent 02efbf9 commit c123a11
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 66 deletions.
6 changes: 3 additions & 3 deletions packages/data-point-express/lib/middleware.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ describe('buildTransformOptions', () => {
})

describe('getErrorOwnKeys', () => {
test('It should get own keys from object', () => {
test('It should get own keys from object | where error is an error object, should omit name and message', () => {
const err = new Error('message')
err.name = 'name'
err.test = 'test'
expect(Middleware.getErrorOwnKeys(err)).toEqual({
test: 'test'
})
})
test('It should get own keys from object', () => {
test('It should get own keys from object | where error is an regular object should pass enumerable keys ', () => {
expect(
Middleware.getErrorOwnKeys({
a: 1,
Expand All @@ -139,7 +139,7 @@ describe('getErrorOwnKeys', () => {
b: 2
})
})
test('It should handle circular references', () => {
test('It should handle circular references, bad keys contain its error instance', () => {
const object = {
a: 1,
b: 2
Expand Down
4 changes: 2 additions & 2 deletions packages/data-point-express/lib/route-map.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('toCollection', () => {
})

describe('sortByPriority', () => {
test('sorts routes in prioroty order', () => {
test('it sorts routes in prioroty order according to priority', () => {
const result = RouteMap.sortByPriority([
{
id: 'a',
Expand Down Expand Up @@ -110,7 +110,7 @@ describe('filterEnabled', () => {
})

describe('normalizeRoutesMiddleware', () => {
test('sorts routes in prioroty order', () => {
test('it will create an array of normalized routes', () => {
const result = RouteMap.normalizeRoutesMiddleware([
{ middleware: 'a' },
{ middleware: ['a'] }
Expand Down
4 changes: 2 additions & 2 deletions packages/data-point-service/lib/setup-middleware.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('before', () => {
expect(next).toBeCalled()
})

test('It should call next if there is no ttl', () => {
test('It should call next if there is no ttl | case where local.resetCache is false', () => {
const ctx = {}
_.set(ctx, 'locals.resetCache', false)
_.set(ctx, 'context.params.ttl', null)
Expand Down Expand Up @@ -77,7 +77,7 @@ describe('after', () => {
}
}

test('It should call next if there is no ttl', done => {
test('SetupMiddleware is called and returns next if there is no ttl', done => {
const ctx = {}
_.set(ctx, 'context.params.ttl', null)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('ResolveEntity.createCurrentAccumulator', () => {
foo: 'bar'
})
})
test('It should initialValue acc.value', () => {
test('It should set an initialValue for acc.params', () => {
expect(acc).toHaveProperty('params', {
base: true
})
Expand All @@ -112,7 +112,7 @@ describe('ResolveEntity.resolveMiddleware', () => {
})
})

test('It should execute a middleware', () => {
test('It should execute a middleware that forces an error to bypass the promise chain', () => {
dataPoint.middleware.use('request:before', (acc, next) => {
acc.resolve('bar')
next(null)
Expand Down Expand Up @@ -186,7 +186,7 @@ describe('ResolveEntity.resolveEntity', () => {
})
})

test('It should resolve through bypass', () => {
test('it should catch errors from middleware', () => {
dataPoint.middleware.use('hash:before', (acc, next) => {
const err = new Error('test')
throw err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const helpers = require('../../helpers')

test('modelFactory#create default', () => {
const result = modelFactory.create({})

expect(result).not.toHaveProperty('error')
expect(result).not.toHaveProperty('before')
expect(result).not.toHaveProperty('after')
Expand All @@ -16,7 +15,7 @@ test('modelFactory#create default', () => {
})

describe('parse loose modifiers', () => {
test('modelFactory#create default', () => {
test('modelFactory#create default | checks that an entitiy containing one reducer has that respective property', () => {
const result = modelFactory.create({
map: '$a'
})
Expand All @@ -26,7 +25,7 @@ describe('parse loose modifiers', () => {
expect(result.compose.reducer).toHaveProperty('type', 'ReducerPath')
})

test('modelFactory#create default', () => {
test('modelFactory#create default | checks multiple reducers in an entitiy to have matching properties', () => {
const result = modelFactory.create({
map: '$a',
find: '$a',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ describe('entity.collection.filter', () => {
})
})

test('should resolve filter Transform', () => {
test('it should resolve filter transform for collection containing filter property', () => {
return transform('collection:c.2', testData).then(acc => {
expect(acc.value).toEqual([1, 3])
})
})

// NOTE: to skip map execution when filter is empty
test('should skip Filter Transform if empty', () => {
test('it should skip filter transform if empty', () => {
return transform('collection:c.3', testData).then(acc => {
expect(acc.value).toEqual([1, 2, 3])
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe('entity.hash.addKeys', () => {
})
})
})
test('do nothing if addKeys is empty', () => {
test('it should do nothing if addKeys is empty', () => {
return transform('hash:c.2', testData).then(acc => {
expect(acc.value).toEqual({ g1: 1 })
})
Expand All @@ -101,7 +101,7 @@ describe('entity.hash.omitKeys', () => {
})
})
})
test('do nothing if mapKeys is empty', () => {
test('it should do nothing if omitKeys is empty', () => {
return transform('hash:d.2', testData).then(acc => {
expect(acc.value).toEqual({ g1: 1 })
})
Expand All @@ -117,7 +117,7 @@ describe('entity.hash.pickKeys', () => {
})
})
})
test('do nothing if mapKeys is empty', () => {
test('it should do nothing if pickKeys is empty', () => {
return transform('hash:e.2', testData).then(acc => {
expect(acc.value).toEqual({ g1: 1 })
})
Expand All @@ -135,7 +135,7 @@ describe('entity.hash.addValues', () => {
})
})
})
test('do nothing if mapKeys is empty', () => {
test('it should do nothing if addValues is empty', () => {
return transform('hash:f.2', testData).then(acc => {
expect(acc.value).toEqual({ g1: 1 })
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ describe('resolve', () => {
})
})

test('inject locals value with string template', () => {
test('it should inject locals value with string template', () => {
nock('http://remote.test')
.get('/source1')
.reply(200, {
Expand All @@ -378,7 +378,7 @@ describe('resolve', () => {
})
})

test('inject locals value with string template', () => {
test('it should use options.baseURL to create a request URL', () => {
nock('http://remote.test')
.get('/source1')
.reply(200, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('createComposeReducer', () => {
})

describe('parseModifierSpec', () => {
test('parses a modifier spec', () => {
test('it should parse a modifier spec', () => {
const result = parseCompose.parseModifierSpec({
map: '$a'
})
Expand All @@ -24,12 +24,13 @@ describe('parseModifierSpec', () => {
})

describe('parseComposeSpecProperty', () => {
test('parses a modifier spec', () => {
test('it should parse a single modifier spec', () => {
const result = parseCompose.parseComposeSpecProperty([
{
map: '$a'
}
])

expect(result).toHaveLength(1)
result.forEach(expectModifier)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('factory#create', () => {
expect(reducer.asCollection).toBe(true)
})

test('factory#create context with reducers', () => {
test('it should create a ReducerList with reducers using a piped reducer', () => {
const result = factory.create(createReducer, [
'$foo.bar | reducer:add',
() => true
Expand All @@ -45,7 +45,7 @@ describe('factory#create', () => {
expect(result.reducers[2].type).toBe('ReducerFunction')
})

test('factory#create context with reducers', () => {
test('It should create a ReducerList with reducers using an array of reducers', () => {
const result = factory.create(createReducer, [
'$foo.bar',
'reducer:add',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('resolve#reducer.resolve - reducer model', () => {
).then(result => expect(result.value).toEqual(testData))
})

test('multiple models', () => {
test('it returns original input after piping through hash:asIs', () => {
const accumulator = AccumulatorFactory.create({
value: testData
})
Expand All @@ -92,7 +92,9 @@ describe('resolve#reducer.resolve - reducer model', () => {
resolveReducer,
accumulator,
reducerList
).then(result => expect(result.value).toEqual(testData.a.h))
).then(result => {
expect(result.value).toEqual(testData.a.h)
})
})
})

Expand Down Expand Up @@ -122,7 +124,7 @@ describe('resolve#reducer.resolve - reducer request', () => {
)
})

test('multiple models', () => {
test('multiple models for reducer request', () => {
nock('http://remote.test')
.get('/source1')
.reply(200, {
Expand All @@ -146,10 +148,10 @@ describe('resolve#reducer.resolve - reducer request', () => {
resolveReducer,
accumulator,
reducer
).then(result =>
).then(result => {
expect(result.value).toEqual({
ok: true
})
)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@ describe('resolve#reducerObject.resolve', () => {
})
})

it('should resolve a reducer object', () => {
const reducer = createReducerObject(createReducer, {
y: '$x.y',
zPlusOne: ['$x.y.z', acc => acc.value + 1]
})

it('should resolve a reducer object for reducer that changes value', () => {
const accumulator = AccumulatorFactory.create({
value: {
x: {
Expand All @@ -53,6 +48,11 @@ describe('resolve#reducerObject.resolve', () => {
}
})

const reducer = createReducerObject(createReducer, {
y: '$x.y',
zPlusOne: ['$x.y.z', acc => acc.value + 1]
})

return resolveReducerObject(
dataPoint,
resolveReducer,
Expand All @@ -68,17 +68,9 @@ describe('resolve#reducerObject.resolve', () => {
})
})

it('should resolve a reducer object', () => {
const reducer = createReducerObject(createReducer, {
x: '$c.x',
y: '$c.y',
z: {
a: '$a',
b: '$b'
}
})

it('should resolve a reducer object that has reducer object inside reducer', () => {
const accumulator = AccumulatorFactory.create({
// this is the input
value: {
a: 'A',
b: 'B',
Expand All @@ -89,6 +81,16 @@ describe('resolve#reducerObject.resolve', () => {
}
})

const reducer = createReducerObject(createReducer, {
// this is the function itself
x: '$c.x',
y: '$c.y',
z: {
a: '$a',
b: '$b'
}
})

return resolveReducerObject(
dataPoint,
resolveReducer,
Expand All @@ -106,7 +108,16 @@ describe('resolve#reducerObject.resolve', () => {
})
})

it('should resolve a reducer object', () => {
it('it should resolve a reducer object whose value follows input schematics', () => {
const accumulator = AccumulatorFactory.create({
value: {
a: {
a: 1,
b: 2
}
}
})

const reducer = createReducerObject(createReducer, {
x: [
'$a',
Expand All @@ -122,15 +133,6 @@ describe('resolve#reducerObject.resolve', () => {
]
})

const accumulator = AccumulatorFactory.create({
value: {
a: {
a: 1,
b: 2
}
}
})

return resolveReducerObject(
dataPoint,
resolveReducer,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`add It should throw error with information if item already exist 1`] = `[Foo: Bar]`;

exports[`add It should throw error with information if item already exist 2`] = `
exports[`add It should throw error with information if item already exist | error containing spec will return and entitiy containing spec object 1`] = `
[Error: factory error
Entity "id1": {
"spec": "mySpec"
}]
`;

exports[`add It should throw error with information if item already exist 1`] = `[Foo: Bar]`;
Loading

0 comments on commit c123a11

Please sign in to comment.