From b8864af5aa3a6a8760d1c2c97a69b2b39ed72175 Mon Sep 17 00:00:00 2001 From: Matt Youill Date: Tue, 28 Nov 2017 11:41:26 +1100 Subject: [PATCH] Add an index so volt client can be imported using the module mechanisms --- lib/index.js | 22 +++++++++ test/cases/module-test.js | 94 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 lib/index.js create mode 100644 test/cases/module-test.js diff --git a/lib/index.js b/lib/index.js new file mode 100644 index 0000000..86f0870 --- /dev/null +++ b/lib/index.js @@ -0,0 +1,22 @@ +!(function(global) { // eslint-disable-line no-unused-vars + + "use strict"; + + const VoltClient = require("./client"); + const VoltConfiguration = require("./configuration"); + const VoltConstants = require("./voltconstants"); + + /* + * AFAICT VoltQuery used to be exported from query.js but is deprecated and + * now query exports VoltProcedure which should be used instead. + */ + const VoltProcedure = require("./query"); + + module.exports = { + VoltClient : VoltClient, + VoltConfiguration : VoltConfiguration, + VoltConstants : VoltConstants, + VoltProcedure : VoltProcedure + }; + +})(); \ No newline at end of file diff --git a/test/cases/module-test.js b/test/cases/module-test.js new file mode 100644 index 0000000..999fc4c --- /dev/null +++ b/test/cases/module-test.js @@ -0,0 +1,94 @@ +!(function(global) { // eslint-disable-line no-unused-vars + + "use strict"; + + require("nodeunit"); + const debug = require("debug")("voltdb-client-nodejs:ModuleTest"); + + // Exports + module.exports = { + setUp : function(callback) { + callback(); + }, + tearDown : function(callback) { + callback(); + }, + requireTest : function(test) { + + /** + * Just test if the expected members are there and that they are in fact + * what they should be. + */ + + debug("requireTest"); + + test.expect(18); + + /* + * Module tests + */ + const voltdb = require("../../lib/"); + test.notEqual(typeof voltdb.VoltClient, "undefined", + "VoltClient member not present"); + test.equal(typeof voltdb.VoltClient, "function", + "VoltClient is present but not a function"); + + test.notEqual(typeof voltdb.VoltConfiguration, "undefined", + "VoltClient function not present"); + test.equal(typeof voltdb.VoltConfiguration, "function", + "VoltConfiguration is present but not a function"); + + test.notEqual(typeof voltdb.VoltConstants, "undefined", + "VoltClient function not present"); + test.equal(typeof voltdb.VoltConstants, "object", + "VoltConstants is present but not an object"); + + test.notEqual(typeof voltdb.VoltProcedure, "undefined", + "VoltClient function not present"); + test.equal(typeof voltdb.VoltProcedure, "function", + "VoltProcedure is present but not a function"); + + /* + * VoltClient + */ + const voltClient = new voltdb.VoltClient(); + test.notEqual(typeof voltClient.connect, "undefined", + "VoltClient.connect member not present"); + test.equal(typeof voltClient.connect, "function", + "VoltClient.connect is present but not a function"); + + /* + * VoltConfiguration + */ + const voltConfiguration = new voltdb.VoltConfiguration(); + test.notEqual(typeof voltConfiguration.host, "undefined", + "VoltConfiguration.host member not present"); + test.equal(typeof voltConfiguration.host, "string", + "VoltConfiguration.host is present but not a string"); + + /* + * VoltConstants + */ + const voltConstants = voltdb.VoltConstants; + test.notEqual(typeof voltConstants.STATUS_CODES, "undefined", + "VoltConstants.STATUS_CODES member not present"); + test.equal(typeof voltConstants.STATUS_CODES, "object", + "VoltConstants.STATUS_CODES is present but not an object"); + test.notEqual(typeof voltConstants.STATUS_CODES.SUCCESS, "undefined", + "VoltConstants.STATUS_CODES.SUCCESS member not present"); + test.equal(voltConstants.STATUS_CODES.SUCCESS, null, + "VoltConstants.STATUS_CODES.SUCCESS is present but not null"); + + /* + * VoltProcedure + */ + const voltProcedure = new voltdb.VoltProcedure(); + test.notEqual(typeof voltProcedure.getQuery, "undefined", + "VoltProcedure.getQuery member not present"); + test.equals(typeof voltProcedure.getQuery, "function", + "VoltProcedure.getQuery is present but not a function"); + + test.done(); + } + }; +})(); \ No newline at end of file