forked from octokit/octokit.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreleasesTest.js
262 lines (246 loc) · 8.21 KB
/
releasesTest.js
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/*
* Copyright 2012 Cloud9 IDE, Inc.
*
* This product includes software developed by
* Cloud9 IDE, Inc (http://c9.io).
*
* Author: Mike de Boer <[email protected]>
*/
"use strict";
var Assert = require("assert");
var Client = require("./../../index");
var fs = require("fs");
var mime = require("mime");
describe("[releases]", function() {
var client;
var token = "c286e38330e15246a640c2cf32a45ea45d93b2ba";
var owner = "greggman";
var repo = "test";
var haveWriteAccess = true; // set to false if the authenticated person below does not have write access to the repo above
var releaseIdWithAsset = 393621; // Some release id from the repo above that has at least 1 asset.
var filePathToUpload = __filename;
var fileSizeToUpload = fs.statSync(filePathToUpload).size;
var releaseId; // release id found when listing releases. Used for get release
var newReleaseId; // release id created when creating release, used for edit and delete release
var assetId; // asset id found when listing assets. Used for get asset
var newAssetId; // asset id used when creating asset. Used for edit and delete asset
beforeEach(function() {
client = new Client({
version: "3.0.0"
});
client.authenticate({
type: "oauth",
token: token
});
});
it("should successfully execute GET /repos/:owner/:repo/releases (listReleases)", function(next) {
client.releases.listReleases(
{
owner: owner,
repo: repo,
},
function(err, res) {
Assert.equal(err, null);
Assert.ok(res instanceof Array);
if (res instanceof Array && res.length > 0) {
releaseId = res[0].id;
}
next();
}
);
});
it("should successfully execute GET /repos/:owner/:repo/releases/:id (getRelease)", function(next) {
if (!releaseId) {
next();
return;
}
client.releases.getRelease(
{
owner: owner,
id: releaseId,
repo: repo
},
function(err, res) {
Assert.equal(err, null);
Assert.equal(res.id, releaseId);
next();
}
);
});
it("should successfully execute POST /repos/:owner/:repo/releases (createRelease)", function(next) {
if (!haveWriteAccess) {
next();
return;
}
client.releases.createRelease(
{
owner: owner,
repo: repo,
tag_name: "node-github-tag",
target_commitish: "master",
name: "node-github-name",
body: "node-github-body",
draft: false,
prerelease: true,
},
function(err, res) {
Assert.equal(err, null);
Assert.equal(res.tag_name, "node-github-tag");
Assert.equal(res.target_commitish, "master");
Assert.equal(res.name, "node-github-name");
Assert.equal(res.body, "node-github-body");
Assert.equal(res.assets.length, 0);
Assert.ok(res.prerelease);
Assert.ok(!res.draft);
newReleaseId = res.id;
next();
}
);
});
it("should successfully execute PATCH /repos/:owner/:repo/releases/:id (editRelease)", function(next) {
if (!haveWriteAccess) {
next();
return;
}
client.releases.editRelease(
{
owner: owner,
id: newReleaseId,
repo: repo,
tag_name: "node-github-new-tag",
target_commitish: "master",
name: "node-github-new-name",
body: "node-github-new-body",
draft: true,
prerelease: true,
},
function(err, res) {
Assert.equal(err, null);
Assert.equal(res.id, newReleaseId);
Assert.equal(res.tag_name, "node-github-new-tag");
Assert.equal(res.target_commitish, "master");
Assert.equal(res.name, "node-github-new-name");
Assert.equal(res.body, "node-github-new-body");
Assert.equal(res.assets.length, 0);
Assert.ok(res.prerelease);
Assert.ok(res.draft);
next();
}
);
});
it("should successfully execute DELETE /repos/:owner/:repo/releases/:id (deleteRelease)", function(next) {
if (!haveWriteAccess) {
next();
return;
}
client.releases.deleteRelease(
{
owner: owner,
repo: repo,
id: newReleaseId,
},
function(err, res) {
Assert.equal(err, null);
next();
}
);
});
it("should successfully execute GET /repos/:owner/:repo/releases/:id/assets (listAssets)", function(next) {
client.releases.listAssets(
{
owner: owner,
id: releaseIdWithAsset,
repo: repo
},
function(err, res) {
Assert.equal(err, null);
Assert.ok(res instanceof Array);
if (res instanceof Array && res.length > 0) {
assetId = res[0].id;
}
next();
}
);
});
it("should successfully execute GET /repos/:owner/:repo/releases/assets/:id (getAsset)", function(next) {
if (!assetId) {
next();
return;
}
client.releases.getAsset(
{
owner: owner,
id: assetId,
repo: repo
},
function(err, res) {
Assert.equal(err, null);
Assert.equal(res.id, assetId);
next();
}
);
});
it("should successfully execute POST /repos/:owner/:repo/releases/:id/assets (uploadAsset)", function(next) {
var name = "somenameornot.zip";
client.releases.uploadAsset(
{
owner: owner,
id: releaseIdWithAsset,
repo: repo,
name: name,
filePath: filePathToUpload
},
function(err, res) {
Assert.equal(err, null);
Assert.equal(res.content_type, mime.lookup(name)); // matches extension of name, not filePath
Assert.equal(res.state, "uploaded");
Assert.equal(res.size, fileSizeToUpload);
Assert.equal(res.name, name);
newAssetId = res.id;
next();
}
);
});
it("should successfully execute PATCH /repos/:owner/:repo/releases/assets/:id (editAsset)", function(next) {
if (!newAssetId) {
next();
return;
}
var newName = "somenewname.zip";
client.releases.editAsset(
{
owner: owner,
id: newAssetId,
repo: repo,
name: newName,
label: "foo"
},
function(err, res) {
Assert.equal(err, null);
Assert.equal(res.state, "uploaded");
Assert.equal(res.size, fileSizeToUpload);
Assert.equal(res.name, newName);
Assert.equal(res.label, "foo");
next();
}
);
});
it("should successfully execute DELETE /repos/:owner/:repo/releases/assets/:id (deleteAsset)", function(next) {
if (!newAssetId) {
next();
return;
}
client.releases.deleteAsset(
{
owner: owner,
id: newAssetId,
repo: repo
},
function(err, res) {
Assert.equal(err, null);
// other assertions go here
next();
}
);
});
});