Add unit test

This commit is contained in:
Niklas Mischkulnig 2023-07-22 19:32:39 +02:00
parent 6f5b9fd796
commit a3fdfeda8c
No known key found for this signature in database
GPG Key ID: C029B9EB62230BB0
1 changed files with 31 additions and 0 deletions

View File

@ -10,6 +10,7 @@ const Attribute = require('@ldapjs/attribute')
const Change = require('@ldapjs/change')
const messages = require('@ldapjs/messages')
const controls = require('@ldapjs/controls')
const dn = require('@ldapjs/dn')
const ldap = require('../lib')
const {
@ -761,6 +762,36 @@ tap.test('search basic', function (t) {
})
})
tap.test('search basic with DN', function (t) {
const { SearchResultEntry, SearchResultDone } = messages
t.context.client.search(dn.DN.fromString('cn=test, ' + SUFFIX, '(objectclass=*)'), function (err, res) {
t.error(err)
t.ok(res)
let gotEntry = 0
res.on('searchEntry', function (entry) {
t.ok(entry)
t.ok(entry instanceof SearchResultEntry)
t.equal(entry.dn.toString(), 'cn=test,' + SUFFIX)
t.ok(entry.attributes)
t.ok(entry.attributes.length)
t.equal(entry.attributes[0].type, 'cn')
t.equal(entry.attributes[1].type, 'SN')
gotEntry++
})
res.on('error', function (err) {
t.fail(err)
})
res.on('end', function (res) {
t.ok(res)
t.ok(res instanceof SearchResultDone)
t.equal(res.status, 0)
t.equal(gotEntry, 2)
t.end()
})
})
})
tap.test('GH-602 search basic with delayed event listener binding', function (t) {
t.context.client.search('cn=test, ' + SUFFIX, '(objectclass=*)', function (err, res) {
t.error(err)