Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
variety
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fact-gitdep
variety
Commits
a251107c
Commit
a251107c
authored
Jun 12, 2016
by
Tomas Dvorak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests added for excludeSubkeys and arrayEscape
parent
7dc3c73c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
4 deletions
+63
-4
ExcludeSubkeysTest.js
spec/ExcludeSubkeysTest.js
+49
-0
UnnamedObjectsAnalysisTest.js
spec/UnnamedObjectsAnalysisTest.js
+13
-3
JsonValidator.js
spec/utils/JsonValidator.js
+1
-1
No files found.
spec/ExcludeSubkeysTest.js
0 → 100644
View file @
a251107c
import
assert
from
'assert'
;
import
Tester
from
'./utils/Tester.js'
;
const
test
=
new
Tester
(
'test'
,
'users'
);
const
sampleData
=
[
{
name
:
"Walter"
,
someNestedObject
:{
a
:{
b
:{
c
:{
d
:{
e
:
1
}}}}},
otherNestedObject
:{
a
:{
b
:{
c
:{
d
:{
e
:
1
}}}}}}
];
describe
(
'Exclude subkeys'
,
()
=>
{
beforeEach
(()
=>
test
.
init
(
sampleData
));
afterEach
(()
=>
test
.
cleanUp
());
it
(
'should exclude some subkeys'
,
async
()
=>
{
const
results
=
await
test
.
runJsonAnalysis
({
collection
:
'users'
,
excludeSubkeys
:[
'someNestedObject.a.b'
]},
true
);
results
.
validateResultsCount
(
11
);
results
.
validate
(
'_id'
,
1
,
100.0
,
{
ObjectId
:
1
});
results
.
validate
(
'name'
,
1
,
100.0
,
{
String
:
1
});
results
.
validate
(
'someNestedObject'
,
1
,
100.0
,
{
Object
:
1
});
results
.
validate
(
'someNestedObject.a'
,
1
,
100.0
,
{
Object
:
1
});
results
.
validate
(
'someNestedObject.a.b'
,
1
,
100.0
,
{
Object
:
1
});
// no more descendants of someNestedObject.a.b, they are excluded
results
.
validate
(
'otherNestedObject'
,
1
,
100.0
,
{
Object
:
1
});
results
.
validate
(
'otherNestedObject.a'
,
1
,
100.0
,
{
Object
:
1
});
results
.
validate
(
'otherNestedObject.a.b'
,
1
,
100.0
,
{
Object
:
1
});
results
.
validate
(
'otherNestedObject.a.b.c'
,
1
,
100.0
,
{
Object
:
1
});
results
.
validate
(
'otherNestedObject.a.b.c.d'
,
1
,
100.0
,
{
Object
:
1
});
results
.
validate
(
'otherNestedObject.a.b.c.d.e'
,
1
,
100.0
,
{
Number
:
1
});
});
it
(
'should exclude some subkeys excluding root'
,
async
()
=>
{
const
results
=
await
test
.
runJsonAnalysis
({
collection
:
'users'
,
excludeSubkeys
:[
'someNestedObject'
]},
true
);
results
.
validateResultsCount
(
9
);
results
.
validate
(
'_id'
,
1
,
100.0
,
{
ObjectId
:
1
});
results
.
validate
(
'name'
,
1
,
100.0
,
{
String
:
1
});
results
.
validate
(
'someNestedObject'
,
1
,
100.0
,
{
Object
:
1
});
// no more descendants of someNestedObject, they are excluded
results
.
validate
(
'otherNestedObject'
,
1
,
100.0
,
{
Object
:
1
});
results
.
validate
(
'otherNestedObject.a'
,
1
,
100.0
,
{
Object
:
1
});
results
.
validate
(
'otherNestedObject.a.b'
,
1
,
100.0
,
{
Object
:
1
});
results
.
validate
(
'otherNestedObject.a.b.c'
,
1
,
100.0
,
{
Object
:
1
});
results
.
validate
(
'otherNestedObject.a.b.c.d'
,
1
,
100.0
,
{
Object
:
1
});
results
.
validate
(
'otherNestedObject.a.b.c.d.e'
,
1
,
100.0
,
{
Number
:
1
});
});
});
spec/UnnamedObjectsAnalysisTest.js
View file @
a251107c
...
@@ -2,7 +2,7 @@ import Tester from './utils/Tester.js';
...
@@ -2,7 +2,7 @@ import Tester from './utils/Tester.js';
const
test
=
new
Tester
(
'test'
,
'users'
);
const
test
=
new
Tester
(
'test'
,
'users'
);
const
sampleData
=
[
const
sampleData
=
[
{
title
:
'Article 1'
,
comments
:[{
author
:
'John'
,
body
:
'it works'
,
visible
:
true
}]},
{
title
:
'Article 1'
,
comments
:[{
author
:
'John'
,
body
:
'it works'
,
visible
:
true
,
'123key'
:
'123value'
}]},
{
title
:
'Article 2'
,
comments
:[{
author
:
'Tom'
,
body
:
'thanks'
},
{
author
:
'Mark'
,
body
:
1
}]}
{
title
:
'Article 2'
,
comments
:[{
author
:
'Tom'
,
body
:
'thanks'
},
{
author
:
'Mark'
,
body
:
1
}]}
];
];
...
@@ -16,8 +16,7 @@ describe('Unnamed object analysis', () => {
...
@@ -16,8 +16,7 @@ describe('Unnamed object analysis', () => {
it
(
'should handle keys of unnamed object'
,
async
()
=>
{
it
(
'should handle keys of unnamed object'
,
async
()
=>
{
const
results
=
await
test
.
runJsonAnalysis
({
collection
:
'users'
},
true
);
const
results
=
await
test
.
runJsonAnalysis
({
collection
:
'users'
},
true
);
results
.
validateResultsCount
(
7
);
results
.
validateResultsCount
(
6
);
results
.
validate
(
'_id'
,
2
,
100.0
,
{
ObjectId
:
2
});
results
.
validate
(
'_id'
,
2
,
100.0
,
{
ObjectId
:
2
});
results
.
validate
(
'title'
,
2
,
100.0
,
{
String
:
2
});
results
.
validate
(
'title'
,
2
,
100.0
,
{
String
:
2
});
results
.
validate
(
'comments'
,
2
,
100.0
,
{
Array
:
2
});
results
.
validate
(
'comments'
,
2
,
100.0
,
{
Array
:
2
});
...
@@ -26,5 +25,16 @@ describe('Unnamed object analysis', () => {
...
@@ -26,5 +25,16 @@ describe('Unnamed object analysis', () => {
results
.
validate
(
'comments.XX.author'
,
2
,
100.0
,
{
String
:
2
});
results
.
validate
(
'comments.XX.author'
,
2
,
100.0
,
{
String
:
2
});
results
.
validate
(
'comments.XX.body'
,
2
,
100.0
,
{
String
:
2
,
Number
:
1
});
results
.
validate
(
'comments.XX.body'
,
2
,
100.0
,
{
String
:
2
,
Number
:
1
});
results
.
validate
(
'comments.XX.visible'
,
1
,
50.0
,
{
Boolean
:
1
});
results
.
validate
(
'comments.XX.visible'
,
1
,
50.0
,
{
Boolean
:
1
});
results
.
validate
(
'comments.XX.123key'
,
1
,
50.0
,
{
String
:
1
});
});
it
(
'should use different array escape key'
,
async
()
=>
{
const
results
=
await
test
.
runJsonAnalysis
({
collection
:
'users'
,
arrayEscape
:
'YY'
},
true
);
results
.
validateResultsCount
(
7
);
// unnamed objects are prefixed with .YY key
results
.
validate
(
'comments.YY.author'
,
2
,
100.0
,
{
String
:
2
});
results
.
validate
(
'comments.YY.body'
,
2
,
100.0
,
{
String
:
2
,
Number
:
1
});
results
.
validate
(
'comments.YY.visible'
,
1
,
50.0
,
{
Boolean
:
1
});
results
.
validate
(
'comments.YY.123key'
,
1
,
50.0
,
{
String
:
1
});
});
});
});
});
spec/utils/JsonValidator.js
View file @
a251107c
...
@@ -10,7 +10,7 @@ export default class JsonValidator {
...
@@ -10,7 +10,7 @@ export default class JsonValidator {
validate
(
key
,
totalOccurrences
,
percentContaining
,
types
)
{
validate
(
key
,
totalOccurrences
,
percentContaining
,
types
)
{
const
row
=
this
.
results
.
filter
(
item
=>
item
.
_id
.
key
===
key
)[
0
];
const
row
=
this
.
results
.
filter
(
item
=>
item
.
_id
.
key
===
key
)[
0
];
if
(
typeof
row
===
'undefined'
)
{
if
(
typeof
row
===
'undefined'
)
{
throw
new
Error
(
`Key '
${
key
}
'
is not present in results
`
);
throw
new
Error
(
`Key '
${
key
}
'
not present in results. Known keys are: [
${
this
.
results
.
map
(
item
=>
item
.
_id
.
key
).
join
(
','
)}
].
`
);
}
}
equal
(
row
.
totalOccurrences
,
totalOccurrences
,
`TotalOccurrences of key
${
key
}
does not match`
);
equal
(
row
.
totalOccurrences
,
totalOccurrences
,
`TotalOccurrences of key
${
key
}
does not match`
);
equal
(
row
.
percentContaining
,
percentContaining
,
`PercentContaining of key
${
key
}
does not match`
);
equal
(
row
.
percentContaining
,
percentContaining
,
`PercentContaining of key
${
key
}
does not match`
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment