UNPKG

gpii-universal

Version:

Cross platform, core components of the GPII personalization infrastructure.

161 lines (147 loc) 5.97 kB
/* * WebSockets Settings Handler Tests * * Copyright 2013, 2014 Emergya * * Licensed under the New BSD license. You may not use this file except in * compliance with this License. * * The research leading to these results has received funding from the European Union's * Seventh Framework Programme (FP7/2007-2013) * under grant agreement no. 289016. * * You may obtain a copy of the License at * https://github.com/GPII/universal/blob/master/LICENSE.txt */ "use strict"; var fluid = require("infusion"), gpii = fluid.registerNamespace("gpii"), jqUnit = fluid.require("node-jqunit", require, "jqUnit"); fluid.require("%gpii-universal"); var webSocketsTests = fluid.registerNamespace("gpii.tests.settingsHandlers.webSockets"); webSocketsTests.payloads = { getPayload: { "net.gpii.test": [ { settings: { dog: null, cat: null, amount: null, cheese: null, "beers.trappiste": null, "beers.blanche": null, "beers.scotch": null }, options: { path: "net.gpii.test" } } ] }, expectedGetPayload: { "net.gpii.test": [ { settings: { dog: undefined, cat: undefined, amount: undefined, cheese: undefined, "beers.trappiste": undefined, "beers.blanche": undefined, "beers.scotch": undefined } } ] }, setPayload: { "net.gpii.test": [ { settings: { dog: "woof", cat: "meow", amount: 3, cheese: ["gouda", "brugge"], "beers.trappiste": "Chimay", "beers.blanche": "Hoegaarden", "beers.scotch": "Achouffe McChouffe" }, options: { path: "net.gpii.test" } } ] }, expectedSetReturnPayload: { "net.gpii.test": [ { settings: { dog: { oldValue: undefined, newValue: "woof" }, cat: { oldValue: undefined, newValue: "meow" }, amount: { oldValue: undefined, newValue: 3 }, cheese: { oldValue: undefined, newValue: ["gouda", "brugge"] }, "beers.trappiste": {oldValue: undefined, newValue: "Chimay" }, "beers.blanche": {oldValue: undefined, newValue: "Hoegaarden" }, "beers.scotch": {oldValue: undefined, newValue: "Achouffe McChouffe" } } } ] }, restorePayload: { "net.gpii.test": [ { settings: { dog: undefined, cat: undefined, amount: undefined, cheese: undefined, "beers.trappiste": undefined, "beers.blanche": undefined, "beers.scotch": undefined }, options: { path: "net.gpii.test" } } ] }, expectedRestoreReturnPayload: { "net.gpii.test": [ { settings: { dog: { newValue: undefined, oldValue: "woof" }, cat: { newValue: undefined, oldValue: "meow" }, amount: { newValue: undefined, oldValue: 3 }, cheese: { newValue: undefined, oldValue: ["gouda", "brugge"] }, "beers.trappiste": {newValue: undefined, oldValue: "Chimay" }, "beers.blanche": {newValue: undefined, oldValue: "Hoegaarden" }, "beers.scotch": {newValue: undefined, oldValue: "Achouffe McChouffe" } } } ] } }; jqUnit.module("WebSockets settings handler test module"); jqUnit.test("Checking wsSettingsHandler object before doing anything", function () { var that = gpii.settingsHandlers.webSockets.component(); jqUnit.assertTrue("There are an object to store the settings", that.model.settings); jqUnit.assertTrue("There are an object to store the clients", that.clients); jqUnit.assertDeepEq("wsSettingsHandler.settings is empty", {}, that.model.settings); jqUnit.assertDeepEq("wsSettingsHandler.clients is empty", {}, that.clients); }); jqUnit.test("Checking wsSettingsHandler's get/set methods", function () { gpii.settingsHandlers.webSockets.instance = gpii.settingsHandlers.webSockets.component(); jqUnit.assertDeepEq("There aren't settings yet for 'net.gpii.test'", webSocketsTests.payloads.expectedGetPayload, gpii.resolveSync(gpii.settingsHandlers.webSockets.get(webSocketsTests.payloads.getPayload))); var setReturnPayload = gpii.resolveSync(gpii.settingsHandlers.webSockets.set(webSocketsTests.payloads.setPayload)); jqUnit.assertDeepEq("Set function returns the expected payload", webSocketsTests.payloads.expectedSetReturnPayload, setReturnPayload); var restoreReturnPayload = gpii.resolveSync(gpii.settingsHandlers.webSockets.set(webSocketsTests.payloads.restorePayload)); jqUnit.assertDeepEq("Restore returns the expected payload", webSocketsTests.payloads.expectedRestoreReturnPayload, restoreReturnPayload); jqUnit.assertDeepEq("After restoring, model.settings should be {}", {}, gpii.settingsHandlers.webSockets.instance.model.settings); delete gpii.settingsHandlers.webSockets.instance; });