git ssb

0+

Kira / %V53yIAO6ZNGv1Lx9tCP…



forked from cel / ssb-issues

Tree: 3c22ce4d98f464c79fdf6f300fb6a9de9165ab3a

Files: 3c22ce4d98f464c79fdf6f300fb6a9de9165ab3a / test.js

2925 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 updated_at = issue1.updated_at
99 t.end()
100 })
101 })
102})
103
104test('close the issue via a post', function (t) {
105 var msg = schemas.post('I like closing issues')
106 Issues.schemas.closes(msg, issue1.id)
107 sbot.publish(msg, function (err, msg) {
108 t.error(err, 'publish')
109 t.equals(issues.isStatusChanged(msg, issue1), false)
110 awaitMsg(sbot, msg, function (err) {
111 t.error(err, 'await')
112 t.equals(issue1.open, false, 'closed')
113 t.ok(issue1.updated_at > updated_at, 'updated_at is updated')
114 t.end()
115 })
116 })
117})
118

Built with git-ssb-web