jqUnit.test("Testing `jsonToQuery` and `queryToJson` static functions...", function() {
    // String data
    var stringData        = "simple test";
    var stringObject      = { myString: stringData };
    var stringQueryString = gpii.locationBar.jsonToQuery(stringObject);
    jqUnit.assertEquals("A string should be correctly encoded...", "myString=simple%20test", stringQueryString);

    var parsedStringData = gpii.locationBar.queryToJson(stringQueryString);
    jqUnit.assertDeepEq("The reconstituted string data should be the same as the original...", stringObject, parsedStringData);

    // Array data
    var arrayData        =  ["one potato", "two potatoes"];
    var arrayObject      = {myArray: arrayData};
    var arrayQueryString = gpii.locationBar.jsonToQuery(arrayObject);
    var parsedArrayData  = gpii.locationBar.queryToJson(arrayQueryString);
    jqUnit.assertDeepEq("The reconstituted array data should be the same as the original...", arrayObject, parsedArrayData);

    // Object data
    var objectData        = { foo: { bar: "baz" } };
    var objectObject      = {myObject: objectData};
    var objectQueryString = gpii.locationBar.jsonToQuery(objectObject);
    var parsedObjectData  = gpii.locationBar.queryToJson(objectQueryString);

    jqUnit.assertDeepEq("The reconstituted object data should be the same as the original...", objectObject, parsedObjectData);

    // Mixed data with all types
    var mixedData = {
        myString: stringData,
        myArray:  arrayData,
        myObject: objectData
    };
    var mixedQueryString = gpii.locationBar.jsonToQuery(mixedData);
    var parsedMixedData  = gpii.locationBar.queryToJson(mixedQueryString);

    jqUnit.assertDeepEq("The reconstituted mixed data should be the same as the original...", mixedData, parsedMixedData);

    var withQuestion          = "?foo=bar";
    var parsedWithQuestion    = gpii.locationBar.queryToJson(withQuestion);
    var withoutQuestion       = "foo=bar";
    var parsedWithoutQuestion = gpii.locationBar.queryToJson(withoutQuestion);
    jqUnit.assertDeepEq("A query string should be parsed the same whether or not it has a question mark...", parsedWithQuestion, parsedWithoutQuestion);
});
"use strict";
var fluid = fluid || require("infusion");
var gpii  = fluid.registerNamespace("gpii");
var jqUnit = require("jqUnit");

// TODO: Update this once the refactor of the PUT api is complete
var loader = require("../../../../../config/lib/config-loader");
var config = loader.loadConfig(require("../../../../../config/test-pouch.json"));

require("../index.js")(config);

jqUnit.test("An object with no empty entries should be preserved...", function() {
    var start    = { foo: "bar", baz: { qux: "quux"} };

    // We make a copy to ensure that the array has not been mangled (which we will test later).
    var expected = fluid.copy(start);

    var stripped = gpii.ul.product.put.removeEmptyEntries(start);

    jqUnit.assertDeepEq("The stripped object should still contain all entries...", expected, stripped);
});

jqUnit.test("An object with empty entries should be stripped...", function() {
    var start    = { foo: "bar", bar: null, baz: { qux: "quux", quux: null} };
    var copy     = fluid.copy(start);
    var expected = { foo: "bar", baz: { qux: "quux"} };

    var stripped = gpii.ul.product.put.removeEmptyEntries(start);

    jqUnit.assertDeepEq("The stripped object should still match the expected results...", expected, stripped);

    jqUnit.assertDeepEq("The original object should not have been modified...", copy, start);
// Tests for the "hash helper"...
"use strict";
var fluid = fluid || require("infusion");
var gpii  = fluid.registerNamespace("gpii");

var jqUnit = require("jqUnit");

// The code we are testing
require("../../lib/hash-helper");

jqUnit.module("Testing hash helper function(s)...");

jqUnit.test("Testing filtering using a single key...", function () {
    var original = { foo: "bar", baz: "qux"};
    var expected = { foo: "bar"};

    var filtered = gpii.ul.api.helpers.hash.omit(original, "baz");

    jqUnit.assertDeepEq("The results should have been filtered as expected...", expected, filtered);
});

jqUnit.test("Testing filtering using multiple keys (as individual arguments)...", function () {
    var original = { foo: "bar", baz: "qux", quux: "corge"};
    var expected = { foo: "bar"};

    var filtered = gpii.ul.api.helpers.hash.omit(original, "quux", "baz");

    jqUnit.assertDeepEq("The results should have been filtered as expected...", expected, filtered);
});

jqUnit.test("Testing filtering using multiple keys (as an array)...", function () {
    var original = { foo: "bar", baz: "qux", quux: "corge"};