Files: 230fe608ef1516dbdc57be322b43aa7d33813625 / test.js
2353 bytesRaw
1 | var test = require('tape') |
2 | var Issues = require('.') |
3 | var ssbKeys = require('ssb-keys') |
4 | var pull = require('pull-stream') |
5 | |
6 | function 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 | |
15 | var createSbot = require('scuttlebot') |
16 | .use(require('scuttlebot/plugins/master')) |
17 | .use(require('scuttlebot/plugins/blobs')) |
18 | |
19 | var sbot = createSbot({ |
20 | temp: 'test-ssb-issues', timeout: 200, |
21 | allowPrivate: true, |
22 | keys: ssbKeys.generate() |
23 | }) |
24 | |
25 | var issues = Issues.init(sbot) |
26 | |
27 | test.onFinish(function () { |
28 | sbot.close(true) |
29 | }) |
30 | |
31 | var projectId |
32 | |
33 | test('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 | |
41 | var issue1 |
42 | |
43 | test('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 | |
62 | test('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 | |
77 | test('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 | |
89 | test('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