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')) .use(require('scuttlebot/plugins/blobs')) 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) { var title = 'Test Title' issues.new({ project: projectId, title: title, 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, title, 'title') t.equals(issue.open, true, 'open') t.equals(~~(issue.created_at/1e5), ~~(Date.now()/1e5), 'created_at') issue1 = issue t.end() }) }) test('update the issue', function (t) { var title = 'New Title' issues.edit(issue1.id, {title: title}, function (err, msg) { t.error(err, 'edit') t.ok(msg, 'msg') awaitMsg(sbot, msg, function (err) { t.error(err, 'await') t.equals(issue1.title, title, 'new title') t.notEquals(issue1.updated_at, issue1.created_at, 'updated_at is new') t.ok(Date.now() - issue1.updated_at < 60e3, 'updated_at is recent') 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() }) }) })