Skip to content

Commit f4e93b0

Browse files
committed
test(gitlab): add gitlab parser tests
1 parent 466995f commit f4e93b0

File tree

2 files changed

+122
-2
lines changed

2 files changed

+122
-2
lines changed

tests/github.js

-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ var test = require('tape'),
33

44

55
var options = common.options;
6-
options.headers['x-github-delivery'] = 1;
7-
86
var config = common.config;
97
var request = common.request;
108
var gen_sig = common.github_sig;

tests/gitlab.js

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
var test = require('tape'),
2+
common = require('./common')();
3+
4+
5+
var options = common.options;
6+
var request = common.request;
7+
8+
function createPayload() {
9+
return {
10+
repository: {
11+
git_ssh_url: '[email protected]:example/repo.git',
12+
homepage: 'http://github.com/example/repo'
13+
},
14+
ref: 'refs/heads/master',
15+
total_commits_count: 1,
16+
commits: [{
17+
message: 'Example commit'
18+
}]
19+
};
20+
}
21+
22+
23+
test('BEGIN GITLAB PAYLOAD TESTS', function (t) { t.end(); });
24+
25+
test('pass invalid payload', function (t) {
26+
27+
t.test('pass string as payload', function (st) {
28+
var payload = 'asdf';
29+
30+
request(payload, function (res, data) {
31+
st.equal(data.err, 'Error: Invalid payload', 'correct server response');
32+
st.equal(res.statusCode, 400, 'correct status code');
33+
st.end();
34+
});
35+
});
36+
37+
test('pass invalid JSON object: missing repository', function (t) {
38+
var payload = createPayload();
39+
payload.repository = undefined;
40+
41+
request(JSON.stringify(payload), function (res, data) {
42+
t.equal(data.err, 'Error: Invalid data', 'correct server response');
43+
t.equal(res.statusCode, 400, 'correct status code');
44+
t.end();
45+
});
46+
});
47+
48+
test('pass invalid JSON object: missing ref', function (t) {
49+
var payload = createPayload();
50+
payload.ref = undefined;
51+
52+
request(JSON.stringify(payload), function (res, data) {
53+
t.equal(data.err, 'Error: Invalid data', 'correct server response');
54+
t.equal(res.statusCode, 400, 'correct status code');
55+
t.end();
56+
});
57+
});
58+
59+
test('pass invalid JSON object: missing commits', function (t) {
60+
var payload = createPayload();
61+
payload.commits = undefined;
62+
63+
request(JSON.stringify(payload), function (res, data) {
64+
t.equal(data.err, 'Error: Invalid data', 'correct server response');
65+
t.equal(res.statusCode, 400, 'correct status code');
66+
t.end();
67+
});
68+
});
69+
70+
});
71+
72+
test('pass valid payload and valid signature', function (t) {
73+
74+
t.test('valid data but mismatching branch', function (st) {
75+
var payload = createPayload();
76+
payload.ref = 'refs/heads/branch';
77+
78+
request(JSON.stringify(payload), function (res, data) {
79+
st.equal(data.err, 'Branches do not match', 'correct server response');
80+
st.equal(res.statusCode, 400, 'correct status code');
81+
st.end();
82+
});
83+
});
84+
85+
t.test('valid data and matching branch', function (st) {
86+
var payload = createPayload();
87+
88+
request(JSON.stringify(payload), function (res, data) {
89+
st.equal(data.msg, 'Build queued', 'correct server response');
90+
st.equal(res.statusCode, 202, 'correct status code');
91+
st.end();
92+
});
93+
});
94+
95+
});
96+
97+
test('pass custom branch name', function (t) {
98+
99+
t.test('mismatching branch in path and branch in payload', function (st) {
100+
var payload = createPayload();
101+
options.query.branch = 'dev';
102+
103+
request(JSON.stringify(payload), function (res, data) {
104+
st.equal(data.err, 'Branches do not match', 'correct server response');
105+
st.equal(res.statusCode, 400, 'correct status code');
106+
st.end();
107+
});
108+
});
109+
110+
t.test('matching branch in path and branch in payload', function (st) {
111+
var payload = createPayload();
112+
payload.ref = 'refs/heads/dev';
113+
options.query.branch = 'dev';
114+
115+
request(JSON.stringify(payload), function (res, data) {
116+
st.equal(data.msg, 'Build queued', 'correct server response');
117+
st.equal(res.statusCode, 202, 'correct status code');
118+
st.end();
119+
});
120+
});
121+
122+
});

0 commit comments

Comments
 (0)