1
1
Helper = require (" hubot-test-helper" )
2
2
expect = require (" chai" ).expect
3
3
proxyquire = require (" proxyquire" )
4
+ simpleEncryptor = require (" simple-encryptor" )
5
+ nock = require (" nock" )
4
6
5
7
apiToken = " DK89YJJRktQ2X0B3i1o7N96Z75pWL2MR"
6
8
password = " 19QBn1kzsKyuC9IKHz9byjCL8222wuop"
9
+ encryptor = simpleEncryptor password
10
+ apiTokenEnc = encryptor .encrypt apiToken
11
+ # process.env.TOGGL_CHANNEL = "user"
7
12
8
13
togglStub = () ->
9
14
getUserDataAsync : () ->
@@ -18,18 +23,18 @@ togglStub = () ->
18
23
{
19
24
id : 1 ,
20
25
duration : 100 ,
21
- description : " Testing"
26
+ description : " Testing 1 "
22
27
},
23
28
{
24
29
id : 2 ,
25
30
duration : 100 ,
26
- description : " Testing"
31
+ description : " Testing 2 "
27
32
},
28
33
{
29
34
id : 3 ,
30
35
tags : " Pagado" ,
31
36
duration : 100 ,
32
- description : " Testing"
37
+ description : " Testing 3 "
33
38
},
34
39
])
35
40
updateTimeEntriesTagsAsync : () ->
@@ -44,17 +49,43 @@ describe "hubot-toggl-payment", ->
44
49
45
50
beforeEach ->
46
51
room = helper .createRoom ({name : " user" })
52
+ nock .disableNetConnect ()
47
53
48
54
afterEach ->
49
55
room .destroy ()
56
+ nock .cleanAll ()
50
57
51
- context " get w3w from address " , ->
58
+ context " login " , ->
52
59
beforeEach (done ) ->
53
60
room .user .say (" user" , " hubot toggl login #{ apiToken} #{ password} " )
54
61
setTimeout (done, 100 )
55
62
56
- it " should get a w3w " , ->
63
+ it " should get a success message " , ->
57
64
expect (room .messages ).to .eql ([
58
65
[" user" , " hubot toggl login #{ apiToken} #{ password} " ]
59
66
[" hubot" , " Login success as Testing User" ]
60
67
])
68
+
69
+ context " process time entries" , ->
70
+ beforeEach (done ) ->
71
+ nock (" http://indicadoresdeldia.cl" )
72
+ .get (" /webservice/indicadores.json" )
73
+ .reply 200 , {indicador : {uf : " $26.029,52" }}
74
+ room .robot .brain .data .users .user =
75
+ toggl : {api_token : apiTokenEnc}
76
+ room : " user"
77
+ name : " user"
78
+ room .user .say (" user" , " hubot toggl payment 500000 0.3 #{ password} " )
79
+ setTimeout (done, 100 )
80
+
81
+ it " should get a success message" , ->
82
+ message = """ Time entries to payment:
83
+ Testing 1 00:01:40
84
+ Testing 2 00:01:40
85
+ Finish. Total time is: 00:03:20"""
86
+ expect (room .messages ).to .eql ([
87
+ [" user" , " hubot toggl payment 500000 0.3 #{ password} " ]
88
+ [" hubot" , " Processing time entries..." ]
89
+ [" hubot" , " user close tasks successfull\n #{ message} " ]
90
+ [" hubot" , message]
91
+ ])
0 commit comments