forked from finos/git-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestParseAction.test.js
More file actions
83 lines (73 loc) · 2.88 KB
/
testParseAction.test.js
File metadata and controls
83 lines (73 loc) · 2.88 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
// Import the dependencies for testing
const chai = require('chai');
chai.should();
const expect = chai.expect;
const preprocessor = require('../src/proxy/processors/pre-processor/parseAction');
const db = require('../src/db');
let testRepo = null;
const TEST_REPO = {
url: 'https://github.com/finos/git-proxy.git',
name: 'git-proxy',
project: 'finos',
};
describe('Pre-processor: parseAction', async () => {
before(async function () {
// make sure the test repo exists as the presence of the repo makes a difference to handling of urls
testRepo = await db.getRepoByUrl(TEST_REPO.url);
if (!testRepo) {
testRepo = await db.createRepo(TEST_REPO);
}
});
after(async function () {
// clean up test DB
await db.deleteRepo(testRepo._id);
});
it('should be able to parse a pull request into an action', async function () {
const req = {
originalUrl: '/github.com/finos/git-proxy.git/git-upload-pack',
method: 'GET',
headers: { 'content-type': 'application/x-git-upload-pack-request' },
};
const action = await preprocessor.exec(req);
expect(action.timestamp).is.greaterThan(0);
expect(action.id).to.not.be.false;
expect(action.type).to.equal('pull');
expect(action.url).to.equal('https://github.com/finos/git-proxy.git');
});
it('should be able to parse a pull request with a legacy path into an action', async function () {
const req = {
originalUrl: '/finos/git-proxy.git/git-upload-pack',
method: 'GET',
headers: { 'content-type': 'application/x-git-upload-pack-request' },
};
const action = await preprocessor.exec(req);
expect(action.timestamp).is.greaterThan(0);
expect(action.id).to.not.be.false;
expect(action.type).to.equal('pull');
expect(action.url).to.equal('https://github.com/finos/git-proxy.git');
});
it('should be able to parse a push request into an action', async function () {
const req = {
originalUrl: '/github.com/finos/git-proxy.git/git-receive-pack',
method: 'POST',
headers: { 'content-type': 'application/x-git-receive-pack-request' },
};
const action = await preprocessor.exec(req);
expect(action.timestamp).is.greaterThan(0);
expect(action.id).to.not.be.false;
expect(action.type).to.equal('push');
expect(action.url).to.equal('https://github.com/finos/git-proxy.git');
});
it('should be able to parse a push request with a legacy path into an action', async function () {
const req = {
originalUrl: '/finos/git-proxy.git/git-receive-pack',
method: 'POST',
headers: { 'content-type': 'application/x-git-receive-pack-request' },
};
const action = await preprocessor.exec(req);
expect(action.timestamp).is.greaterThan(0);
expect(action.id).to.not.be.false;
expect(action.type).to.equal('push');
expect(action.url).to.equal('https://github.com/finos/git-proxy.git');
});
});