Files: c71a980e347ca450e31d2edd03ce812e22a8304e / test.js
2481 bytesRaw
1 | var test = require('tape') |
2 | var Issues = require('.') |
3 | var ssbKeys = require('ssb-keys') |
4 | var pull = require('pull-stream') |
5 | var schemas = require('ssb-msg-schemas') |
6 | |
7 | function 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 | |
16 | var createSbot = require('scuttlebot') |
17 | .use(require('scuttlebot/plugins/master')) |
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 | var updated_at |
43 | |
44 | test('create an issue', function (t) { |
45 | issues.new({ |
46 | project: projectId, |
47 | text: 'Test Text' |
48 | }, function (err, issue) { |
49 | t.error(err, 'new issue') |
50 | t.ok(issue.id, 'id') |
51 | t.equals(issue.project, projectId, 'project') |
52 | t.equals(issue.author, sbot.id, 'author') |
53 | t.equals(issue.title, 'Test Text', 'title/text') |
54 | t.equals(issue.open, true, 'open') |
55 | t.equals(~~(issue.created_at/1e5), ~~(Date.now()/1e5), 'created_at') |
56 | issue1 = issue |
57 | t.end() |
58 | }) |
59 | }) |
60 | |
61 | test('close the issue', function (t) { |
62 | issues.close(issue1.id, function (err, msg) { |
63 | t.error(err, 'close') |
64 | t.ok(msg, 'msg') |
65 | awaitMsg(sbot, msg, function (err) { |
66 | t.error(err, 'await') |
67 | t.equals(issue1.open, false, 'closed') |
68 | t.end() |
69 | }) |
70 | }) |
71 | }) |
72 | |
73 | test('reopen the issue', function (t) { |
74 | issues.reopen(issue1.id, function (err, msg) { |
75 | t.error(err, 'reopen') |
76 | t.ok(msg, 'msg') |
77 | awaitMsg(sbot, msg, function (err) { |
78 | t.error(err, 'await') |
79 | t.equals(issue1.open, true, 'open') |
80 | var mention = issues.getMention(msg, issue1) |
81 | t.equals(mention && mention.open, true, 'mention') |
82 | updated_at = issue1.updated_at |
83 | t.end() |
84 | }) |
85 | }) |
86 | }) |
87 | |
88 | test('close the issue via a post', function (t) { |
89 | var msg = schemas.post('I like closing issues') |
90 | Issues.schemas.closes(msg, issue1.id) |
91 | sbot.publish(msg, function (err, msg) { |
92 | t.error(err, 'publish') |
93 | t.equals(issues.isStatusChanged(msg, issue1), false) |
94 | awaitMsg(sbot, msg, function (err) { |
95 | t.error(err, 'await') |
96 | t.equals(issue1.open, false, 'closed') |
97 | t.ok(issue1.updated_at > updated_at, 'updated_at is updated') |
98 | t.end() |
99 | }) |
100 | }) |
101 | }) |
102 |
Built with git-ssb-web