Skip to content

Commit bb64892

Browse files
committed
chore(test): Add new tests
1 parent 3757f2c commit bb64892

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"hubot-test-helper": "^1.4.4",
4646
"istanbul": "^0.4.3",
4747
"mocha": "^2.5.3",
48+
"nock": "^8.0.0",
4849
"proxyquire": "^1.7.9"
4950
}
5051
}

test/test.coffee

+36-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
Helper = require("hubot-test-helper")
22
expect = require("chai").expect
33
proxyquire = require("proxyquire")
4+
simpleEncryptor = require("simple-encryptor")
5+
nock = require("nock")
46

57
apiToken = "DK89YJJRktQ2X0B3i1o7N96Z75pWL2MR"
68
password = "19QBn1kzsKyuC9IKHz9byjCL8222wuop"
9+
encryptor = simpleEncryptor password
10+
apiTokenEnc = encryptor.encrypt apiToken
11+
# process.env.TOGGL_CHANNEL = "user"
712

813
togglStub = () ->
914
getUserDataAsync: () ->
@@ -18,18 +23,18 @@ togglStub = () ->
1823
{
1924
id: 1,
2025
duration: 100,
21-
description: "Testing"
26+
description: "Testing 1"
2227
},
2328
{
2429
id: 2,
2530
duration: 100,
26-
description: "Testing"
31+
description: "Testing 2"
2732
},
2833
{
2934
id: 3,
3035
tags: "Pagado",
3136
duration: 100,
32-
description: "Testing"
37+
description: "Testing 3"
3338
},
3439
])
3540
updateTimeEntriesTagsAsync: () ->
@@ -44,17 +49,43 @@ describe "hubot-toggl-payment", ->
4449

4550
beforeEach ->
4651
room = helper.createRoom({name: "user"})
52+
nock.disableNetConnect()
4753

4854
afterEach ->
4955
room.destroy()
56+
nock.cleanAll()
5057

51-
context "get w3w from address", ->
58+
context "login", ->
5259
beforeEach (done) ->
5360
room.user.say("user", "hubot toggl login #{apiToken} #{password}")
5461
setTimeout(done, 100)
5562

56-
it "should get a w3w", ->
63+
it "should get a success message", ->
5764
expect(room.messages).to.eql([
5865
["user", "hubot toggl login #{apiToken} #{password}"]
5966
["hubot", "Login success as Testing User"]
6067
])
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

Comments
 (0)