git ssb

0+

Kira / %V53yIAO6ZNGv1Lx9tCP…



forked from cel / ssb-issues

Tree: 43d017788d2f57c366a1d4ccb85142ebba4ade90

Files: 43d017788d2f57c366a1d4ccb85142ebba4ade90 / test.js

2481 bytesRaw
1var test = require('tape')
2var Issues = require('.')
3var ssbKeys = require('ssb-keys')
4var pull = require('pull-stream')
5var schemas = require('ssb-msg-schemas')
6
7function awaitMsg(sbot, msg, cb) {
8 sbot.createUserStream({
9 id: msg.value.author,
10 gte: msg.value.sequence,
11 live: true,
12 limit: 1
13 })(null, cb)
14}
15
16var createSbot = require('scuttlebot')
17 .use(require('scuttlebot/plugins/master'))
18
19var sbot = createSbot({
20 temp: 'test-ssb-issues', timeout: 200,
21 allowPrivate: true,
22 keys: ssbKeys.generate()
23})
24
25var issues = Issues.init(sbot)
26
27test.onFinish(function () {
28 sbot.close(true)
29})
30
31var projectId
32
33test('create project', function (t) {
34 sbot.publish({type: 'foo'}, function (err, msg) {
35 t.error(err, 'publish')
36 projectId = msg.key
37 t.end()
38 })
39})
40
41var issue1
42var updated_at
43
44test('create an issue', function (t) {
45 issues.new({
46 project: projectId,
47 text: 'Test Text'
48 }, function (err, issue) {
49 t.error(err, 'new issue')
50 t.ok(issue.id, 'id')
51 t.equals(issue.project, projectId, 'project')
52 t.equals(issue.author, sbot.id, 'author')
53 t.equals(issue.title, 'Test Text', 'title/text')
54 t.equals(issue.open, true, 'open')
55 t.equals(~~(issue.created_at/1e5), ~~(Date.now()/1e5), 'created_at')
56 issue1 = issue
57 t.end()
58 })
59})
60
61test('close the issue', function (t) {
62 issues.close(issue1.id, function (err, msg) {
63 t.error(err, 'close')
64 t.ok(msg, 'msg')
65 awaitMsg(sbot, msg, function (err) {
66 t.error(err, 'await')
67 t.equals(issue1.open, false, 'closed')
68 t.end()
69 })
70 })
71})
72
73test('reopen the issue', function (t) {
74 issues.reopen(issue1.id, function (err, msg) {
75 t.error(err, 'reopen')
76 t.ok(msg, 'msg')
77 awaitMsg(sbot, msg, function (err) {
78 t.error(err, 'await')
79 t.equals(issue1.open, true, 'open')
80 var mention = issues.getMention(msg, issue1)
81 t.equals(mention && mention.open, true, 'mention')
82 updated_at = issue1.updated_at
83 t.end()
84 })
85 })
86})
87
88test('close the issue via a post', function (t) {
89 var msg = schemas.post('I like closing issues')
90 Issues.schemas.closes(msg, issue1.id)
91 sbot.publish(msg, function (err, msg) {
92 t.error(err, 'publish')
93 t.equals(issues.isStatusChanged(msg, issue1), false)
94 awaitMsg(sbot, msg, function (err) {
95 t.error(err, 'await')
96 t.equals(issue1.open, false, 'closed')
97 t.ok(issue1.updated_at > updated_at, 'updated_at is updated')
98 t.end()
99 })
100 })
101})
102

Built with git-ssb-web