git ssb

0+

cel / ssb-issues



Tree: f80a890a7794675d007c3965125971a1405b295b

Files: f80a890a7794675d007c3965125971a1405b295b / test.js

2353 bytesRaw
1var test = require('tape')
2var Issues = require('.')
3var ssbKeys = require('ssb-keys')
4var pull = require('pull-stream')
5
6function awaitMsg(sbot, msg, cb) {
7 sbot.createUserStream({
8 id: msg.value.author,
9 gte: msg.value.sequence,
10 live: true,
11 limit: 1
12 })(null, cb)
13}
14
15var createSbot = require('scuttlebot')
16 .use(require('scuttlebot/plugins/master'))
17 .use(require('scuttlebot/plugins/blobs'))
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
42
43test('create an issue', function (t) {
44 var title = 'Test Title'
45 issues.new({
46 project: projectId,
47 title: title,
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, title, 'title')
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('update the issue', function (t) {
63 var title = 'New Title'
64 issues.edit(issue1.id, {title: title}, function (err, msg) {
65 t.error(err, 'edit')
66 t.ok(msg, 'msg')
67 awaitMsg(sbot, msg, function (err) {
68 t.error(err, 'await')
69 t.equals(issue1.title, title, 'new title')
70 t.notEquals(issue1.updated_at, issue1.created_at, 'updated_at is new')
71 t.ok(Date.now() - issue1.updated_at < 60e3, 'updated_at is recent')
72 t.end()
73 })
74 })
75})
76
77test('close the issue', function (t) {
78 issues.close(issue1.id, function (err, msg) {
79 t.error(err, 'close')
80 t.ok(msg, 'msg')
81 awaitMsg(sbot, msg, function (err) {
82 t.error(err, 'await')
83 t.equals(issue1.open, false, 'closed')
84 t.end()
85 })
86 })
87})
88
89test('reopen the issue', function (t) {
90 issues.reopen(issue1.id, function (err, msg) {
91 t.error(err, 'reopen')
92 t.ok(msg, 'msg')
93 awaitMsg(sbot, msg, function (err) {
94 t.error(err, 'await')
95 t.equals(issue1.open, true, 'open')
96 t.end()
97 })
98 })
99})
100

Built with git-ssb-web