git ssb

0+

cel / ssb-issues



Tree: 3c92db173ab8661c8ac76098857639346343f9c4

Files: 3c92db173ab8661c8ac76098857639346343f9c4 / test.js

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

Built with git-ssb-web