Skip to content

Commit

Permalink
fix skipped failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
substack committed May 23, 2020
1 parent e231a73 commit e233483
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
6 changes: 2 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,14 @@ function Cabal (storage, key, opts) {
}

this.maxFeeds = opts.maxFeeds
this.modKeys = []
this.adminKeys = []
this.modKeys = opts.modKeys || []
this.adminKeys = opts.adminKeys || []

if (!key) this.key = generateKeyHex()
else {
if (Buffer.isBuffer(key)) key = key.toString('hex')
if (!key.startsWith('cabal://')) key = 'cabal://' + key
this.key = sanitizeKey(key)
this.modKeys = opts.modKeys || []
this.adminKeys = opts.adminKeys || []
}
if (!isHypercoreKey(this.key)) throw new Error('invalid cabal key')

Expand Down
40 changes: 24 additions & 16 deletions test/mod.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@ test('can publish ban message', function (t) {
})
})

// fails
test.skip("possible to ban self. affects subscribers not self", function (t) {
test("possible to ban self. affects subscribers not self", function (t) {
// This way you can prevent others from subscribing to your mod key.
// Or you can remove yourself from moderation duties without needing to change
// a key that many people are using.
Expand All @@ -226,16 +225,18 @@ test.skip("possible to ban self. affects subscribers not self", function (t) {
t.error(err)
cabal1.moderation.setFlags({ id: keys[0], flags: ['admin'] })
cabal0.moderation.setFlags({ id: keys[0], flags: ['block'] })
sync([cabal0,cabal1], function (err) {
t.error(err)
cabal0.moderation.getFlags({ id: keys[0] }, function (err, flags) {
allReady([cabal0,cabal1], function () {
sync([cabal0,cabal1], function (err) {
t.error(err)
t.deepEqual(flags, ['admin']) // blocking self has no local effect
})
cabal1.ready(function () {
cabal1.moderation.getFlags({ id: keys[0] }, function (err, flags) {
cabal0.moderation.getFlags({ id: keys[0] }, function (err, flags) {
t.error(err)
t.deepEqual(flags, ['block'])
t.deepEqual(flags, ['admin']) // blocking self has no local effect
})
cabal1.ready(function () {
cabal1.moderation.getFlags({ id: keys[0] }, function (err, flags) {
t.error(err)
t.deepEqual(flags, ['block'])
})
})
})
})
Expand Down Expand Up @@ -425,8 +426,7 @@ test('block and then unblock', function (t) {
}
})

// fails
test.skip('multiple admins and mods', function (t) {
test('multiple admins and mods', function (t) {
t.plan(14)
var addr = randomBytes(32).toString('hex')
var cabals = []
Expand All @@ -435,10 +435,17 @@ test.skip('multiple admins and mods', function (t) {
}
getKeys(cabals, function (err, keys) {
t.error(err)
cabals.push(Cabal(ram, addr
+ `?admin=${keys[0]}&admin=${keys[1]}&mod=${keys[2]}&mod=${keys[3]}`))
cabals.push(Cabal(ram, addr+`?admin=${keys[3]}&mod=${keys[1]}`))
cabals.push(Cabal(ram, addr+`?mod=${keys[2]}`))
cabals.push(Cabal(ram, addr, {
adminKeys: [keys[0],keys[1]],
modKeys: [keys[2],keys[3]]
}))
cabals.push(Cabal(ram, addr, {
adminKeys: [keys[3]],
modKeys: [keys[1]]
}))
cabals.push(Cabal(ram, addr, {
modKeys: [keys[2]]
}))
allReady(cabals, function () {
getKeys(cabals, function (err, keys) {
t.error(err)
Expand Down Expand Up @@ -550,6 +557,7 @@ function getKeys (cabals, cb) {
function allReady (cabals, cb) {
var pending = 1
cabals.forEach(function (cabal) {
pending++
cabal.ready(function () {
if (--pending === 0) cb()
})
Expand Down

0 comments on commit e233483

Please sign in to comment.