git ssb

0+

cel / ssb-issues



Tree: 198bcc47ef2f962b2651764b7938ffcc875b4cb3

Files: 198bcc47ef2f962b2651764b7938ffcc875b4cb3 / test.js

3033 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 allowPrivate: 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 var title = 'Test Title'
47 issues.new({
48 project: projectId,
49 title: title,
50 text: 'Test Text'
51 }, function (err, issue) {
52 t.error(err, 'new issue')
53 t.ok(issue.id, 'id')
54 t.equals(issue.project, projectId, 'project')
55 t.equals(issue.author, sbot.id, 'author')
56 t.equals(issue.title, title, 'title')
57 t.equals(issue.open, true, 'open')
58 t.equals(~~(issue.created_at/1e5), ~~(Date.now()/1e5), 'created_at')
59 issue1 = issue
60 t.end()
61 })
62})
63
64test('update the issue', function (t) {
65 var title = 'New Title'
66 issues.edit(issue1.id, {title: title}, function (err, msg) {
67 t.error(err, 'edit')
68 t.ok(msg, 'msg')
69 awaitMsg(sbot, msg, function (err) {
70 t.error(err, 'await')
71 t.equals(issue1.title, title, 'new title')
72 t.notEquals(issue1.updated_at, issue1.created_at, 'updated_at is new')
73 t.ok(Date.now() - issue1.updated_at < 60e3, 'updated_at is recent')
74 t.end()
75 })
76 })
77})
78
79test('close the issue', function (t) {
80 issues.close(issue1.id, function (err, msg) {
81 t.error(err, 'close')
82 t.ok(msg, 'msg')
83 awaitMsg(sbot, msg, function (err) {
84 t.error(err, 'await')
85 t.equals(issue1.open, false, 'closed')
86 t.end()
87 })
88 })
89})
90
91test('reopen the issue', function (t) {
92 issues.reopen(issue1.id, function (err, msg) {
93 t.error(err, 'reopen')
94 t.ok(msg, 'msg')
95 awaitMsg(sbot, msg, function (err) {
96 t.error(err, 'await')
97 t.equals(issue1.open, true, 'open')
98 var mention = issues.getMention(msg, issue1)
99 t.equals(mention && mention.open, true, 'mention')
100 updated_at = issue1.updated_at
101 t.end()
102 })
103 })
104})
105
106test('close the issue via a post', function (t) {
107 var msg = schemas.post('I like closing issues')
108 Issues.schemas.closes(msg, issue1.id)
109 sbot.publish(msg, function (err, msg) {
110 t.error(err, 'publish')
111 t.equals(issues.isStatusChanged(msg, issue1), false)
112 awaitMsg(sbot, msg, function (err) {
113 t.error(err, 'await')
114 t.equals(issue1.open, false, 'closed')
115 t.ok(issue1.updated_at > updated_at, 'updated_at is updated')
116 t.end()
117 })
118 })
119})
120

Built with git-ssb-web