Skip to content

Commit c8f88e9

Browse files
committed
Add test for task-dependency
1 parent 56b589e commit c8f88e9

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

test/integration/tasks.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ describe("Tasks", function () {
9797
lossRate: { [DINERO]: 1 },
9898
assignee: appOwner.username,
9999
participants: [],
100+
dependsOn: [],
100101
})
101102
.end((err, res) => {
102103
if (err) {
@@ -110,6 +111,7 @@ describe("Tasks", function () {
110111
expect(res.body.task.createdBy).to.equal(appOwner.username);
111112
expect(res.body.task.assignee).to.equal(appOwner.username);
112113
expect(res.body.task.participants).to.be.a("array");
114+
expect(res.body.dependsOn).to.be.a("array");
113115
return done();
114116
});
115117
});

test/unit/models/tasks.test.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ const { expect } = chai;
1010
const cleanDb = require("../../utils/cleanDb");
1111
const tasksData = require("../../fixtures/tasks/tasks")();
1212
const tasks = require("../../../models/tasks");
13+
const { addDependency } = require("../../../models/tasks");
14+
const firestore = require("../../../utils/firestore");
15+
const dependencyModel = firestore.collection("TaskDependencies");
1316

1417
describe("tasks", function () {
1518
afterEach(async function () {
@@ -40,4 +43,31 @@ describe("tasks", function () {
4043
});
4144
});
4245
});
46+
47+
describe("addDependency", function () {
48+
it("should add dependencies to firestore and return dependsOn array", async function () {
49+
const data = {
50+
taskId: "taskId1",
51+
dependsOn: ["taskId2", "taskId3"],
52+
};
53+
const result = await addDependency(data);
54+
expect(result).to.deep.equal(data.dependsOn);
55+
});
56+
57+
it("should throw an error if there is an error while creating dependencies", async function () {
58+
const data = {
59+
taskId: "taskId1",
60+
dependsOn: ["taskId2", "taskId3"],
61+
};
62+
const expectedError = new Error("test error");
63+
dependencyModel.doc = () => {
64+
throw expectedError;
65+
};
66+
try {
67+
await addDependency(data);
68+
} catch (err) {
69+
expect(err).to.deep.equal(expectedError);
70+
}
71+
});
72+
});
4373
});

0 commit comments

Comments
 (0)