-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
197 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,21 @@ | ||
describe("globals", function () { | ||
it("should have sinon defined", function () { | ||
expect(sinon).to.be.ok; | ||
}); | ||
it("should have sinon defined", function () { | ||
expect(sinon).to.be.ok; | ||
}); | ||
|
||
it("should have expect defined", function () { | ||
expect(expect).to.be.ok; | ||
}); | ||
it("should have expect defined", function () { | ||
expect(expect).to.be.ok; | ||
}); | ||
|
||
it("should have underscore defined", function () { | ||
expect(_).to.be.ok; | ||
}); | ||
it("should have underscore defined", function () { | ||
expect(_).to.be.ok; | ||
}); | ||
|
||
it("should set timezone [0]", function () { | ||
joolaio.timezone(0); | ||
}); | ||
|
||
it("should set timezone [2]", function () { | ||
joolaio.timezone(2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
describe("api", function () { | ||
before(function () { | ||
this._enabled = joolaio.options.debug.enabled; | ||
joolaio.options.debug.enabled = true; | ||
}); | ||
|
||
it("should fetch api", function (done) { | ||
joolaio.api.fetch('/api/system/nodeDetails', {}, function (err, result) { | ||
console.log(err, result); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("should fail to fetch api w/ wrong token", function (done) { | ||
joolaio.api.fetch('/api/system/nodeDetails?token=1234', {}, function (err, result) { | ||
console.log(err, result); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("should test stringify of different types", function (done) { | ||
var options = { | ||
ajax: true | ||
}; | ||
var objOptions = { | ||
a: 'test', | ||
b: 123, | ||
c: true, | ||
d: { | ||
a: 1 | ||
}, | ||
e: [] | ||
}; | ||
joolaio.api.getJSON(options, objOptions, function (err, result) { | ||
console.log(err, result); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("should test stringify of different string", function (done) { | ||
var options = { | ||
ajax: true | ||
}; | ||
var objOptions = 'test'; | ||
joolaio.api.getJSON(options, objOptions, function (err, result) { | ||
console.log(err, result); | ||
done(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* joola.io | ||
* | ||
* Copyright Joola Smart Solutions, Ltd. <[email protected]> | ||
* | ||
* Licensed under GNU General Public License 3.0 or later. | ||
* Some rights reserved. See LICENSE, AUTHORS. | ||
* | ||
* @license GPL-3.0+ <http://spdx.org/licenses/GPL-3.0+> | ||
*/ | ||
|
||
|
||
describe("common-dateformat", function () { | ||
it("should format a date correctly yyyy-mm-dd", function () { | ||
var date = new Date(); | ||
|
||
var yyyy = date.getFullYear(), m = (date.getMonth() + 1), d = date.getDate(); | ||
|
||
var mm = m < 10 ? "0" + m : m; | ||
var dd = d < 10 ? "0" + d : d; | ||
|
||
var expected = yyyy + '-' + mm + '-' + dd; | ||
var actual = date.format('yyyy-mm-dd'); | ||
expect(actual).to.equal(expected); | ||
}); | ||
|
||
it("should format a date correctly yyyy-mm-dd hh:nn:ss", function () { | ||
var date = new Date(); | ||
|
||
var yyyy = date.getFullYear(), m = (date.getMonth() + 1), d = date.getDate(), h = date.getHours(), n = date.getMinutes(), s = date.getSeconds(); | ||
|
||
var mm = m < 10 ? "0" + m : m; | ||
var dd = d < 10 ? "0" + d : d; | ||
var hh = h < 10 ? "0" + h : h; | ||
var nn = n < 10 ? "0" + n : n; | ||
var ss = s < 10 ? "0" + s : s; | ||
|
||
var expected = yyyy + '-' + mm + '-' + dd + ' ' + hh + ':' + nn + ':' + ss; | ||
var actual = date.format('yyyy-mm-dd hh:nn:ss'); | ||
expect(actual).to.equal(expected); | ||
}); | ||
|
||
it("should format a date correctly yyyy-mm-dd hh:nn:ss.fff", function () { | ||
var date = new Date(); | ||
|
||
var yyyy = date.getFullYear(), m = (date.getMonth() + 1), d = date.getDate(), h = date.getHours(), n = date.getMinutes(), s = date.getSeconds(), f = date.getMilliseconds(); | ||
|
||
var mm = m < 10 ? "0" + m : m; | ||
var dd = d < 10 ? "0" + d : d; | ||
var hh = h < 10 ? "0" + h : h; | ||
var nn = n < 10 ? "0" + n : n; | ||
var ss = s < 10 ? "0" + s : s; | ||
var ff = f < 10 ? "0" + f : f; | ||
var fff = ff < 100 ? "0" + ff : ff; | ||
|
||
var expected = yyyy + '-' + mm + '-' + dd + ' ' + hh + ':' + nn + ':' + ss + '.' + fff; | ||
var actual = date.format('yyyy-mm-dd hh:nn:ss.fff'); | ||
expect(actual).to.equal(expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
describe("common", function () { | ||
it("should async stringify objects", function (done) { | ||
var obj = { | ||
a: 1, | ||
b: 2 | ||
}; | ||
|
||
joola.common.stringify(obj, function (err, str) { | ||
expect(str).to.equal(JSON.stringify(obj)); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("should async parse json string", function (done) { | ||
var obj = { | ||
a: 1, | ||
b: 2 | ||
}; | ||
var str = JSON.stringify(obj); | ||
|
||
joola.common.parse(str, function (err, _obj) { | ||
expect(str).to.equal(JSON.stringify(_obj)); | ||
done(); | ||
}); | ||
}); | ||
|
||
it("should hash strings correctly", function () { | ||
var expected = '26207976637e23e1bed51683c33a6d73'; | ||
var actual = joola.common.hash('thisisatestforhash'); | ||
expect(actual).to.equal(expected); | ||
}); | ||
|
||
it("should generate uuid - 9 chars long", function () { | ||
var expected = 9; | ||
var actual = joola.common.uuid().length; | ||
expect(actual).to.equal(expected); | ||
}); | ||
|
||
it("should generate uuid - unique", function (done) { | ||
var ids = []; | ||
|
||
for (var i = 0; i < 3200; i++) { | ||
var uuid = joola.common.uuid(); | ||
if (ids.indexOf(uuid) > -1) { | ||
return done(new Error('Found duplicate uuid [' + uuid + ']')); | ||
} | ||
ids.push(uuid); | ||
} | ||
|
||
return done(); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
describe("modifiers", function () { | ||
it("should format toJSON", function (done) { | ||
var err = new Error('This is a test error'); | ||
console.log(err.toJSON()); | ||
done(); | ||
}); | ||
}); |