-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
47 lines (45 loc) · 1.82 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
var test = require('tap').test
var jlDebounce = require('./index.js')
var level = require('level-mem')
test('test debouncing', function (t) {
var sessionId = "session id not"
var emailAddress = "[email protected]"
var coreThing = {
beginAuthCalls: 0,
beginAuthentication: function (sid, ea, cb) {
coreThing.beginAuthCalls++
cb(null, sid, ea)
}
}
t.equal(coreThing.beginAuthCalls, 0, 'called beginAuth 0 times')
coreThing.beginAuthentication.call(null, sessionId, emailAddress, function (e, sid, ea) {
t.equal(coreThing.beginAuthCalls, 1, 'called beginAuth 1 times')
t.notOk(e, 'no err')
coreThing.beginAuthentication(sessionId, emailAddress, function (e, sid, ea) {
t.equal(coreThing.beginAuthCalls, 2, 'called beginAuth 2 times')
t.notOk(e, 'no err')
var core = Object.create(coreThing)
var coreCopy = Object.create(coreThing)
t.deepEqual(core, coreCopy, "core and copy started equal")
var database = level('dbnc')
jlDebounce(core, database)
t.notDeepEqual(core, coreCopy, "jlDebounce modifed core")
core.beginAuthentication(sessionId, emailAddress, function (err, sid, ea) {
t.equal(coreThing.beginAuthCalls, 3, 'called beginAuth 3 times')
t.notOk(err, "no error")
t.notOk(err && err.debounce, "no debounce error")
t.equal(sid, sessionId, 'has session id')
t.equal(ea, emailAddress, 'has email address')
core.beginAuthentication(sessionId, emailAddress, function (err, details) {
t.equal(coreThing.beginAuthCalls, 3, 'called beginAuth 3 times (calls cb, bot beginAuth)')
t.ok(err, "error")
t.ok(err && err.debounce, "debounce error")
t.ok(details, 'has details')
t.ok(details && details.remaining, 'has details.remaining')
t.notOk(details && details.allowed, 'has details.allowed')
t.end()
})
})
})
})
})