Skip to content

Commit 80ac442

Browse files
committed
some initial tests
1 parent 902ef80 commit 80ac442

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,4 @@ public/
139139

140140
# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)
141141

142+
testfiles

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "redis-task-queue",
3-
"version": "1.0.0",
4-
"description": "",
3+
"version": "0.0.1",
4+
"description": "Simplest possible implementation to put, pop and bury jobs with Redis as backend.",
55
"main": "index.js",
66
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
7+
"test": "jest --watch"
88
},
99
"keywords": [],
1010
"author": "",

tests/helpers/utils.test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const utils = require("../../src/helpers/utils");
2+
3+
describe("utils", () => {
4+
let jsonData;
5+
let stringData;
6+
7+
beforeEach(() => {
8+
jsonData = { name: "hej", mock: true };
9+
stringData = JSON.stringify({ name: "hej", mock: true });
10+
});
11+
describe("storeData", () => {
12+
it("should return stringified data if received json", () => {
13+
expect(typeof utils.storeObject(jsonData) === "string").toBeTruthy();
14+
});
15+
it("should return stringied data if received string", () => {
16+
17+
expect(typeof stringData === "string").toBeTruthy();
18+
});
19+
it("should append id if not existing in the object", () => {
20+
expect(jsonData.id).not.toBeDefined();
21+
expect(JSON.parse(stringData).id).not.toBeDefined();
22+
const jsonBase = utils.storeObject(jsonData);
23+
expect(JSON.parse(jsonBase).id).toBeDefined();
24+
const stringBase = utils.storeObject(stringData);
25+
expect(JSON.parse(stringBase).id).toBeDefined();
26+
});
27+
it("should not touch the id if already exists", () => {
28+
const dataContainingId = jsonData;
29+
dataContainingId.id = "123";
30+
const storeData = utils.storeObject(dataContainingId);
31+
expect(JSON.parse(storeData).id).toEqual(dataContainingId.id);
32+
});
33+
});
34+
});

tests/index.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const RedisTaskQueue = require("../index");
2+
3+
describe("index", () => {
4+
const instance = new RedisTaskQueue();
5+
it("should be instance of a class", () => {
6+
expect(instance).toBeInstanceOf(RedisTaskQueue);
7+
});
8+
});

0 commit comments

Comments
 (0)