Skip to content

Commit

Permalink
chore(test): Add new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lgaticaq committed Jun 18, 2016
1 parent 3757f2c commit bb64892
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"hubot-test-helper": "^1.4.4",
"istanbul": "^0.4.3",
"mocha": "^2.5.3",
"nock": "^8.0.0",
"proxyquire": "^1.7.9"
}
}
41 changes: 36 additions & 5 deletions test/test.coffee
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
Helper = require("hubot-test-helper")
expect = require("chai").expect
proxyquire = require("proxyquire")
simpleEncryptor = require("simple-encryptor")
nock = require("nock")

apiToken = "DK89YJJRktQ2X0B3i1o7N96Z75pWL2MR"
password = "19QBn1kzsKyuC9IKHz9byjCL8222wuop"
encryptor = simpleEncryptor password
apiTokenEnc = encryptor.encrypt apiToken
# process.env.TOGGL_CHANNEL = "user"

togglStub = () ->
getUserDataAsync: () ->
Expand All @@ -18,18 +23,18 @@ togglStub = () ->
{
id: 1,
duration: 100,
description: "Testing"
description: "Testing 1"
},
{
id: 2,
duration: 100,
description: "Testing"
description: "Testing 2"
},
{
id: 3,
tags: "Pagado",
duration: 100,
description: "Testing"
description: "Testing 3"
},
])
updateTimeEntriesTagsAsync: () ->
Expand All @@ -44,17 +49,43 @@ describe "hubot-toggl-payment", ->

beforeEach ->
room = helper.createRoom({name: "user"})
nock.disableNetConnect()

afterEach ->
room.destroy()
nock.cleanAll()

context "get w3w from address", ->
context "login", ->
beforeEach (done) ->
room.user.say("user", "hubot toggl login #{apiToken} #{password}")
setTimeout(done, 100)

it "should get a w3w", ->
it "should get a success message", ->
expect(room.messages).to.eql([
["user", "hubot toggl login #{apiToken} #{password}"]
["hubot", "Login success as Testing User"]
])

context "process time entries", ->
beforeEach (done) ->
nock("http://indicadoresdeldia.cl")
.get("/webservice/indicadores.json")
.reply 200, {indicador: {uf: "$26.029,52"}}
room.robot.brain.data.users.user =
toggl: {api_token: apiTokenEnc}
room: "user"
name: "user"
room.user.say("user", "hubot toggl payment 500000 0.3 #{password}")
setTimeout(done, 100)

it "should get a success message", ->
message = """Time entries to payment:
Testing 1 00:01:40
Testing 2 00:01:40
Finish. Total time is: 00:03:20"""
expect(room.messages).to.eql([
["user", "hubot toggl payment 500000 0.3 #{password}"]
["hubot", "Processing time entries..."]
["hubot", "user close tasks successfull\n#{message}"]
["hubot", message]
])

0 comments on commit bb64892

Please sign in to comment.