2 * Copyright 2014 IBM Corp.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 var should = require("should");
17 var when = require("when");
19 var settings = require("../../red/settings");
22 describe("red/settings", function() {
24 afterEach(function() {
28 it('wraps the user settings as read-only properties', function() {
34 settings.init(userSettings);
36 settings.available().should.be.false;
38 settings.a.should.equal(123);
39 settings.b.should.equal("test");
40 settings.c.should.be.an.Array.with.lengthOf(3);
42 settings.get("a").should.equal(123);
43 settings.get("b").should.equal("test");
44 settings.get("c").should.be.an.Array.with.lengthOf(3);
46 /*jshint immed: false */
52 settings.c.should.be.an.Array.with.lengthOf(4);
54 /*jshint immed: false */
56 settings.set("a",456);
59 /*jshint immed: false */
61 settings.set("a",456);
64 /*jshint immed: false */
66 settings.get("unknown");
69 /*jshint immed: false */
71 settings.set("unknown",456);
76 it('loads global settings from storage', function(done) {
82 var savedSettings = null;
84 getSettings: function() {
85 return when.resolve({globalA:789});
87 saveSettings: function(settings) {
88 savedSettings = settings;
89 return when.resolve();
92 settings.init(userSettings);
94 settings.available().should.be.false;
96 /*jshint immed: false */
98 settings.get("unknown");
101 settings.load(storage).then(function() {
102 settings.available().should.be.true;
103 settings.get("globalA").should.equal(789);
104 settings.set("globalA","abc").then(function() {
105 savedSettings.globalA.should.equal("abc");
108 }).otherwise(function(err) {