@@ -10,6 +10,9 @@ const { expect } = chai;
10
10
const cleanDb = require ( "../../utils/cleanDb" ) ;
11
11
const tasksData = require ( "../../fixtures/tasks/tasks" ) ( ) ;
12
12
const tasks = require ( "../../../models/tasks" ) ;
13
+ const { addDependency } = require ( "../../../models/tasks" ) ;
14
+ const firestore = require ( "../../../utils/firestore" ) ;
15
+ const dependencyModel = firestore . collection ( "TaskDependencies" ) ;
13
16
14
17
describe ( "tasks" , function ( ) {
15
18
afterEach ( async function ( ) {
@@ -40,4 +43,31 @@ describe("tasks", function () {
40
43
} ) ;
41
44
} ) ;
42
45
} ) ;
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
+ } ) ;
43
73
} ) ;
0 commit comments