Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22399454
config-manager.test.js
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
config-manager.test.js
View Options
const
ConfigManager
=
require
(
"./config-manager"
);
const
assert
=
require
(
"assert"
);
const
sinon
=
require
(
"sinon"
);
describe
(
"config-manager"
,
function
()
{
let
config
=
null
;
before
(()
=>
{
config
=
new
ConfigManager
();
config
.
setDefault
(
"foo.bar"
,
"baz"
);
});
it
(
"should get the default value if it's not overwritten"
,
()
=>
{
assert
.
deepEqual
(
config
.
get
(
"foo"
),
{
bar
:
"baz"
});
});
it
(
"should get the custom value if it's overwritten"
,
()
=>
{
config
.
set
(
"foo.bar"
,
"poo"
);
assert
.
equal
(
config
.
get
(
"foo.bar"
),
"poo"
);
});
it
(
"shouldn't overwrite the default values when setting partial keys"
,
()
=>
{
config
.
setDefault
(
"foo2"
,
{
bar
:
"baz"
,
seal
:
"deal"
});
config
.
set
(
"foo2.bar"
,
"newbaz"
);
assert
.
deepEqual
(
config
.
get
(
"foo2"
),
{
bar
:
"newbaz"
,
seal
:
"deal"
});
});
it
(
"should correctly apply new values when setting multiple keys"
,
()
=>
{
config
.
setRoot
({
poo
:
25
,
foo
:
{
seal
:
"deal"
}
});
assert
.
equal
(
config
.
get
(
"poo"
),
25
);
assert
.
deepEqual
(
config
.
get
(
"foo"
),
{
bar
:
"poo"
,
seal
:
"deal"
});
});
it
(
"shouldn't warn when is not locked "
,
()
=>
{
sinon
.
spy
(
console
,
"warn"
);
config
.
set
(
"foo.bar"
,
"poo"
);
config
.
setDefault
(
"foo.bar"
,
""
);
config
.
setRoot
({
poo
:
"foo"
});
assertCalled
(
0
);
});
it
(
"should warn when is locked "
,
()
=>
{
sinon
.
spy
(
console
,
"warn"
);
config
.
lock
();
config
.
set
(
"foo.bar"
,
"poo"
);
config
.
setDefault
(
"foo.bar"
,
""
);
config
.
setRoot
({
poo
:
"foo"
});
assertCalled
(
3
);
});
});
function
assertCalled
(
noOfExpectedCalls
)
{
const
actualCalls
=
console
.
warn
.
getCalls
();
assert
.
equal
(
actualCalls
.
length
,
noOfExpectedCalls
);
console
.
warn
.
restore
();
}
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Fri, Nov 27, 17:33 (1 d, 14 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1229266
Default Alt Text
config-manager.test.js (1 KB)
Attached To
Mode
rSREWRITE Sealious-rewrite
Attached
Detach File
Event Timeline