forked from github-tools/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgist.spec.js
More file actions
150 lines (128 loc) · 4.55 KB
/
gist.spec.js
File metadata and controls
150 lines (128 loc) · 4.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import expect from 'must';
import Github from '../lib/GitHub';
import testUser from './fixtures/user.js';
import testGist from './fixtures/gist.json';
import {assertSuccessful} from './helpers/callbacks';
describe('Gist', function() {
let gist;
let gistId;
let github;
let commentId;
let revisionId;
before(function() {
github = new Github({
username: testUser.USERNAME,
password: testUser.PASSWORD,
auth: 'basic',
});
});
describe('reading', function() {
before(function() {
gist = github.getGist('0ac3ef3451f4bdc9efec660ffce3e336');
});
it('should read a gist', function(done) {
gist.read(assertSuccessful(done, function(err, gist) {
expect(gist).to.have.own('description', testGist.description);
expect(gist.files).to.have.keys(Object.keys(testGist.files));
expect(gist.files['README.md']).to.have.own('content', testGist.files['README.md'].content);
done();
}));
});
});
describe('creating/modifiying', function() {
before(function() {
gist = github.getGist();
});
// 200ms between tests so that Github has a chance to settle
beforeEach(function(done) {
setTimeout(done, 200);
});
it('should create gist', function(done) {
gist.create(testGist, assertSuccessful(done, function(err, gist) {
expect(gist).to.have.own('id');
expect(gist).to.have.own('public', testGist.public);
expect(gist).to.have.own('description', testGist.description);
gistId = gist.id;
revisionId = gist.history[0].version;
done();
}));
});
it('should star a gist', function(done) {
gist = github.getGist(gistId);
gist.star(assertSuccessful(done, function() {
gist.isStarred(assertSuccessful(done, function(err, result) {
expect(result).to.be(true);
done();
}));
}));
});
it('should create a comment a gist', function(done) {
gist.createComment('Comment test', assertSuccessful(done, function(err, comment) {
expect(comment).to.have.own('body', 'Comment test');
commentId = comment.id;
done();
}));
});
it('should list comments', function(done) {
gist.listComments(assertSuccessful(done, function(err, comments) {
expect(comments).to.be.an.array();
done();
}));
});
it('should get comment', function(done) {
gist.getComment(commentId, assertSuccessful(done, function(err, issue) {
expect(issue).to.have.own('id', commentId);
done();
}));
});
it('should edit comment', function(done) {
const newComment = 'new comment test';
gist.editComment(commentId, newComment, assertSuccessful(done, function(err, comment) {
expect(comment).to.have.own('body', newComment);
done();
}));
});
it('should delete comment', function(done) {
gist.deleteComment(commentId, assertSuccessful(done));
});
it('should update gist', function(done) {
const newGist = {
files: {
'README.md': {
content: 'README updated',
},
},
};
gist.update(newGist, assertSuccessful(done, function(err, gist) {
expect(gist.history.length).to.be(2);
expect(gist.files['README.md']).to.have.own('content', newGist.files['README.md'].content);
done();
}));
});
it('should list commits', function(done) {
gist.listCommits(assertSuccessful(done, function(err, commits) {
expect(commits).to.be.an.array();
done();
}));
});
it('should get revision', function(done) {
gist.getRevision(revisionId, assertSuccessful(done, function(err, gist) {
expect(gist.history.length).to.be(1);
expect(gist.files['README.md']).to.have.own('content', testGist.files['README.md'].content);
done();
}));
});
});
describe('deleting', function() {
before(function() {
gist = github.getGist(gistId);
});
// 200ms between tests so that Github has a chance to settle
beforeEach(function(done) {
setTimeout(done, 200);
});
it('should delete gist', function(done) {
gist.delete(assertSuccessful(done));
});
});
});