-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from yidinghan/1-standardise-keys-record-process
standardise req and res keys record process
- Loading branch information
Showing
4 changed files
with
161 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,5 @@ cache: | |
- node_modules | ||
before_script: | ||
- 'npm prune' | ||
- 'npm install winston' | ||
after_success: | ||
- npm run coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,82 @@ | ||
const { test } = require('ava'); | ||
const koaWinston = require('../'); | ||
const { keysRecorder } = require('../'); | ||
|
||
const testTarget = { | ||
a: 1, | ||
b: 2, | ||
c: { | ||
d: 3, | ||
e: 4, | ||
}, | ||
}; | ||
|
||
test('ok', (t) => { | ||
t.truthy(koaWinston); | ||
t.truthy(keysRecorder); | ||
}); | ||
|
||
test('keysRecorder:should get an function as return', (t) => { | ||
const recorder = keysRecorder(); | ||
|
||
t.is(typeof recorder, 'function'); | ||
}); | ||
|
||
test('keysRecorder:should get defaults keys', (t) => { | ||
const recorder = keysRecorder({ | ||
defaults: ['a'], | ||
}); | ||
const result = recorder(testTarget); | ||
|
||
t.deepEqual(result, { a: 1 }); | ||
}); | ||
|
||
test('keysRecorder:should get defaults and selects', (t) => { | ||
const recorder = keysRecorder({ | ||
defaults: ['a'], | ||
selects: ['b'], | ||
}); | ||
const result = recorder(testTarget); | ||
|
||
t.deepEqual(result, { a: 1, b: 2 }); | ||
}); | ||
|
||
test('keysRecorder:should only get c.d', (t) => { | ||
const recorder = keysRecorder({ | ||
defaults: ['c.d'], | ||
selects: ['b'], | ||
unselects: ['b'], | ||
}); | ||
const result = recorder(testTarget); | ||
|
||
t.deepEqual(result, { c: { d: 3 } }); | ||
}); | ||
|
||
test('keysRecorder:should get defaults and selects and unselects', (t) => { | ||
const recorder = keysRecorder({ | ||
defaults: ['a'], | ||
selects: ['c'], | ||
unselects: ['c.e'], | ||
}); | ||
const result = recorder(testTarget); | ||
|
||
t.deepEqual(result, { a: 1, c: { d: 3 } }); | ||
}); | ||
|
||
test('keysRecorder:should get defaults and unselects', (t) => { | ||
const recorder = keysRecorder({ | ||
defaults: ['c'], | ||
unselects: ['c.e'], | ||
}); | ||
const result = recorder(testTarget); | ||
|
||
t.deepEqual(result, { c: { d: 3 } }); | ||
}); | ||
|
||
test('keysRecorder:should get empty object without target', (t) => { | ||
const recorder = keysRecorder({ | ||
defaults: ['c'], | ||
unselects: ['c.e'], | ||
}); | ||
const result = recorder(); | ||
|
||
t.deepEqual(result, {}); | ||
}); |