var test = require('tape') var Issues = require('.') var ssbKeys = require('ssb-keys') var pull = require('pull-stream') var schemas = require('ssb-msg-schemas') function awaitMsg(sbot, msg, cb) { sbot.createUserStream({ id: msg.value.author, gte: msg.value.sequence, live: true, limit: 1 })(null, cb) } var createSbot = require('scuttlebot') .use(require('scuttlebot/plugins/master')) var sbot = createSbot({ temp: 'test-ssb-issues', timeout: 200, allowPrivate: true, keys: ssbKeys.generate() }) var issues = Issues.init(sbot) test.onFinish(function () { sbot.close(true) }) var projectId test('create project', function (t) { sbot.publish({type: 'foo'}, function (err, msg) { t.error(err, 'publish') projectId = msg.key t.end() }) }) var issue1 var updated_at test('create an issue', function (t) { issues.new({ project: projectId, text: 'Test Text' }, function (err, issue) { t.error(err, 'new issue') t.ok(issue.id, 'id') t.equals(issue.project, projectId, 'project') t.equals(issue.author, sbot.id, 'author') t.equals(issue.title, 'Test Text', 'title/text') t.equals(issue.open, true, 'open') t.equals(~~(issue.created_at/1e5), ~~(Date.now()/1e5), 'created_at') issue1 = issue t.end() }) }) test('close the issue', function (t) { issues.close(issue1.id, function (err, msg) { t.error(err, 'close') t.ok(msg, 'msg') awaitMsg(sbot, msg, function (err) { t.error(err, 'await') t.equals(issue1.open, false, 'closed') t.end() }) }) }) test('reopen the issue', function (t) { issues.reopen(issue1.id, function (err, msg) { t.error(err, 'reopen') t.ok(msg, 'msg') awaitMsg(sbot, msg, function (err) { t.error(err, 'await') t.equals(issue1.open, true, 'open') var mention = issues.getMention(msg, issue1) t.equals(mention && mention.open, true, 'mention') updated_at = issue1.updated_at t.end() }) }) }) test('close the issue via a post', function (t) { var msg = schemas.post('I like closing issues') Issues.schemas.closes(msg, issue1.id) sbot.publish(msg, function (err, msg) { t.error(err, 'publish') t.equals(issues.isStatusChanged(msg, issue1), false) awaitMsg(sbot, msg, function (err) { t.error(err, 'await') t.equals(issue1.open, false, 'closed') t.ok(issue1.updated_at > updated_at, 'updated_at is updated') t.end() }) }) })