1
1
import { Response } from 'express' ;
2
- import { BridgeRequest , FollowUpWithIntegrationEntities } from '../models' ;
2
+ import {
3
+ BridgeRequest ,
4
+ FollowUpWithIntegrationEntities ,
5
+ IdBridgeRequest ,
6
+ Task ,
7
+ } from '../models' ;
3
8
import { TaskController } from './task.controller' ;
4
9
5
10
describe ( 'Task Controller' , ( ) => {
6
11
const mockAdapter = {
7
- getTasks : jest . fn ( ) ,
8
- findAllByQuery : jest . fn ( ) ,
12
+ getTask : jest . fn ( ) ,
13
+ findById : jest . fn ( ) ,
9
14
createFollowUp : jest . fn ( ) ,
10
15
} ;
11
16
const mockNext = jest . fn ( ) ;
12
17
13
- describe ( 'findAllByQuery ' , ( ) => {
18
+ describe ( 'findById ' , ( ) => {
14
19
beforeEach ( ( ) => jest . clearAllMocks ( ) ) ;
15
20
16
21
it ( 'Should check for providerConfig' , async ( ) => {
17
22
const controller = new TaskController ( mockAdapter ) ;
18
23
19
- const result = await controller . findAllByQuery (
20
- { } as BridgeRequest < void > ,
24
+ const result = await controller . findById (
25
+ { params : { id : '123' } } as IdBridgeRequest < Task > ,
21
26
{ } as Response ,
22
27
mockNext ,
23
28
) ;
@@ -26,11 +31,11 @@ describe('Task Controller', () => {
26
31
expect ( mockNext ) . toHaveBeenCalled ( ) ;
27
32
} ) ;
28
33
29
- it ( 'Should check if adapter.getTasks is implemented' , async ( ) => {
34
+ it ( 'Should check if adapter.getTask is implemented' , async ( ) => {
30
35
const controller = new TaskController ( { } ) ;
31
36
32
- const result = await controller . findAllByQuery (
33
- { } as BridgeRequest < void > ,
37
+ const result = await controller . findById (
38
+ { params : { id : '123' } } as IdBridgeRequest < Task > ,
34
39
{ } as Response ,
35
40
mockNext ,
36
41
) ;
@@ -39,20 +44,21 @@ describe('Task Controller', () => {
39
44
expect ( mockNext ) . toHaveBeenCalled ( ) ;
40
45
} ) ;
41
46
42
- it ( 'Should handle erroneous adapter.getTasks call' , async ( ) => {
47
+ it ( 'Should handle erroneous adapter.getTask call' , async ( ) => {
43
48
const controller = new TaskController ( mockAdapter ) ;
44
49
45
- mockAdapter . getTasks . mockRejectedValue ( null ) ;
50
+ mockAdapter . getTask . mockRejectedValue ( null ) ;
46
51
47
- const result = await controller . findAllByQuery (
52
+ const result = await controller . findById (
48
53
{
49
54
providerConfig : {
50
55
userId : '123' ,
51
56
apiKey : '123123123' ,
52
57
apiUrl : ':)' ,
53
58
locale : 'de-DE' ,
54
59
} ,
55
- } as BridgeRequest < void > ,
60
+ params : { id : '123' } ,
61
+ } as IdBridgeRequest < Task > ,
56
62
{ } as Response ,
57
63
mockNext ,
58
64
) ;
@@ -65,7 +71,15 @@ describe('Task Controller', () => {
65
71
const controller = new TaskController ( mockAdapter ) ;
66
72
const mockResponse = { json : jest . fn ( ) } ;
67
73
68
- mockAdapter . getTasks . mockResolvedValue ( [ ] ) ;
74
+ const mockTask : Task = {
75
+ id : '123' ,
76
+ content : 'string' ,
77
+ createdAt : 12345678 ,
78
+ dueAt : 12345678 ,
79
+ title : 'string' ,
80
+ type : 'string' ,
81
+ } ;
82
+ mockAdapter . getTask . mockResolvedValue ( mockTask ) ;
69
83
70
84
const req = {
71
85
providerConfig : {
@@ -74,20 +88,21 @@ describe('Task Controller', () => {
74
88
apiUrl : ':)' ,
75
89
locale : 'de-DE' ,
76
90
} ,
77
- } as BridgeRequest < void > ;
91
+ params : { id : '123' } ,
92
+ } as IdBridgeRequest < Task > ;
78
93
79
- const result = await controller . findAllByQuery (
94
+ const result = await controller . findById (
80
95
req ,
81
96
mockResponse as unknown as Response ,
82
97
mockNext ,
83
98
) ;
84
99
85
100
expect ( result ) . toBeUndefined ( ) ;
86
- expect ( mockAdapter . getTasks ) . toHaveBeenCalledWith (
87
- req ,
101
+ expect ( mockAdapter . getTask ) . toHaveBeenCalledWith (
88
102
req . providerConfig ,
103
+ req . params . id ,
89
104
) ;
90
- expect ( mockResponse . json ) . toHaveBeenCalledWith ( [ ] ) ;
105
+ expect ( mockResponse . json ) . toHaveBeenCalledWith ( mockTask ) ;
91
106
} ) ;
92
107
} ) ;
93
108
0 commit comments