Skip to content

Commit

Permalink
chore(tests): Complete tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lgaticaq committed Dec 6, 2016
1 parent 0fe9977 commit cf878d8
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 12 deletions.
37 changes: 37 additions & 0 deletions test/found2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"status": "found",
"query": "anon@ymo.us",
"results": 2,
"data": [
{
"source_id": "4033",
"source_url": "http://siph0n.net/exploits.php?id=4033",
"source_lines": 19265,
"source_size": 2721878,
"source_network": "clearnet",
"source_provider": "siph0n",
"is_vrf": false,
"title": "Multiple Dating/Marriage Websites (9)",
"author": "smitz",
"date_created": "2015-09-04T20:02:48+02:00",
"date_leaked": "2015-09-04T00:00:00+02:00",
"emails_count": 7744,
"details": "https://hesidohackeado.com/leak/siph0n-4033"
},
{
"source_id": "4033",
"source_url": "http://siph0n.net/exploits.php?id=4033",
"source_lines": 19265,
"source_size": 2721878,
"source_network": "clearnet",
"source_provider": "siph0n",
"is_vrf": false,
"title": "Other",
"author": "smitz",
"date_created": "2015-09-04T20:02:48+02:00",
"date_leaked": "2015-09-04T00:00:00+02:00",
"emails_count": 7744,
"details": "https://hesidohackeado.com/leak/siph0n-4033"
}
]
}
78 changes: 66 additions & 12 deletions test/test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ nock = require("nock")
helper = new Helper("./../src/index.coffee")

describe "hesidohackeado", ->
room = null

beforeEach ->
room = helper.createRoom()
@room = helper.createRoom()
@room.robot.adapter.client =
web:
chat:
postMessage: (channel, text, options) =>
@postMessage =
channel: channel
text: text
options: options

afterEach ->
room.destroy()
@room.destroy()

context "email valido con registros", ->
email = "anon@ymo.us"
Expand All @@ -23,13 +29,44 @@ describe "hesidohackeado", ->
.get("/api")
.query({q: email})
.replyWithFile(200, path.join(__dirname, "found.json"))
room.user.say("pepito", "hubot hesidohackeado #{email}")
@room.user.say("pepito", "hubot hesidohackeado #{email}")
setTimeout(done, 100)

it "se espera que obtenga registros", ->
expect(@room.messages).to.eql([
["pepito", "hubot hesidohackeado #{email}"]
])
expect(@postMessage.options.attachments[0].fields).to.eql([
title: "Multiple Dating/Marriage Websites (9)"
value: "Fecha: 2015-09-04"
short: true
])

context "email valido con multiples registros", ->
email = "anon@ymo.us"
format = "YYYY-MM-DD HH:mm:ss"

beforeEach (done) ->
nock("https://hesidohackeado.com")
.get("/api")
.query({q: email})
.replyWithFile(200, path.join(__dirname, "found2.json"))
@room.user.say("pepito", "hubot hesidohackeado #{email}")
setTimeout(done, 100)

it "se espera que obtenga registros", ->
expect(room.messages).to.eql([
expect(@room.messages).to.eql([
["pepito", "hubot hesidohackeado #{email}"]
])
expect(@postMessage.options.attachments[0].fields).to.eql([
title: "Multiple Dating/Marriage Websites (9)"
value: "Fecha: 2015-09-04"
short: true
,
title: "Other"
value: "Fecha: 2015-09-04"
short: true
])

context "email valido sin registros", ->
email = "anon@ymo.us"
Expand All @@ -39,11 +76,11 @@ describe "hesidohackeado", ->
.get("/api")
.query({q: email})
.replyWithFile(200, path.join(__dirname, "notfound.json"))
room.user.say("pepito", "hubot hesidohackeado #{email}")
@room.user.say("pepito", "hubot hesidohackeado #{email}")
setTimeout(done, 100)

it "se espera que no obtenga registros", ->
expect(room.messages).to.eql([
expect(@room.messages).to.eql([
["pepito", "hubot hesidohackeado #{email}"],
["hubot", ":tada: ¡Felicidades! No hay registros para #{email} :tada:"]
])
Expand All @@ -56,11 +93,11 @@ describe "hesidohackeado", ->
.get("/api")
.query({q: email})
.replyWithFile(200, path.join(__dirname, "badsintax.json"))
room.user.say("pepito", "hubot hesidohackeado #{email}")
@room.user.say("pepito", "hubot hesidohackeado #{email}")
setTimeout(done, 100)

it "se espera no obtener respuesta", ->
expect(room.messages).to.eql([
expect(@room.messages).to.eql([
["pepito", "hubot hesidohackeado #{email}"]
])

Expand All @@ -72,11 +109,28 @@ describe "hesidohackeado", ->
.get("/api")
.query({q: email})
.replyWithError("something awful happened")
room.user.say("pepito", "hubot hesidohackeado #{email}")
@room.user.say("pepito", "hubot hesidohackeado #{email}")
setTimeout(done, 100)

it "se espera obtener error", ->
expect(room.messages).to.eql([
expect(@room.messages).to.eql([
["pepito", "hubot hesidohackeado #{email}"]
["hubot", "@pepito ocurrio un error al consultar el email"]
])

context "respuesta inesperada", ->
email = "anon@ymo.us"

beforeEach (done) ->
nock("https://hesidohackeado.com")
.get("/api")
.query({q: email})
.reply(200, {status: "asdasd"})
@room.user.say("pepito", "hubot hesidohackeado #{email}")
setTimeout(done, 100)

it "se espera obtener error", ->
expect(@room.messages).to.eql([
["pepito", "hubot hesidohackeado #{email}"]
["hubot", "@pepito la respuesta no es la esperada"]
])

0 comments on commit cf878d8

Please sign in to comment.