зеркало из https://github.com/microsoft/ghcrawler.git
Added tests. Corrected url for events invisible in the timeline. Corrected MembershipEvent.
This commit is contained in:
Родитель
745635a9f0
Коммит
214ca4bd2e
|
@ -431,7 +431,7 @@ class GitHubProcessor {
|
|||
} else {
|
||||
const type = this._getTranslatedEventType(request.payload.type);
|
||||
const newContext = extend(true, {}, { history: request.context.history });
|
||||
const newRequest = new Request(type, request.url, newContext);
|
||||
const newRequest = new Request(type, request.url + '/' + request.payload.guid, newContext);
|
||||
newRequest.payload = request.payload;
|
||||
request.queueRequests(newRequest, 'immediate');
|
||||
}
|
||||
|
@ -606,9 +606,12 @@ class GitHubProcessor {
|
|||
}
|
||||
|
||||
MembershipEvent(request) {
|
||||
this._addEventBasics(request);
|
||||
let [document, , payload] = this._addEventBasics(request);
|
||||
const userPolicy = TraversalPolicy.reload('user');
|
||||
this._addEventResource(request, null, 'member', 'user', null, {}, userPolicy);
|
||||
if (payload.team && payload.team.deleted) {
|
||||
return document;
|
||||
}
|
||||
const teamPolicy = TraversalPolicy.reload('team');
|
||||
return this._addEventResource(request, null, 'team', 'team', null, {}, teamPolicy);
|
||||
}
|
||||
|
|
|
@ -970,7 +970,7 @@ describe('Member processing', () => {
|
|||
{ type: 'repo', url: 'http://repo/4', path: '/repo' },
|
||||
{ type: 'repo', url: 'http://repo/4', path: '/repo' },
|
||||
{ type: 'org', url: 'http://org/5', path: '/org' },
|
||||
{ type: 'user', url: 'http://member/7', path: '/member' },
|
||||
{ type: 'user', url: 'http://member/7', path: '/member' }
|
||||
];
|
||||
expectQueued(queue, expected);
|
||||
});
|
||||
|
@ -1008,6 +1008,76 @@ describe('Member processing', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('Membership processing', () => {
|
||||
it('should link and queue added MembershipEvent', () => {
|
||||
const request = createRequest('MembershipEvent', 'http://foo/');
|
||||
const queue = [];
|
||||
request.crawler = { queue: sinon.spy(request => { queue.push.apply(queue, request) }) };
|
||||
const payload = {
|
||||
action: 'added',
|
||||
member: { id: 7, url: 'http://member/7' },
|
||||
team: { id: 14, url: 'http://member/14' }
|
||||
}
|
||||
request.document = createEvent('MembershipEvent', payload);
|
||||
|
||||
const processor = new GitHubProcessor();
|
||||
const document = processor.MembershipEvent(request);
|
||||
|
||||
const links = {
|
||||
self: { href: 'urn:repo:4:MembershipEvent:12345', type: 'resource' },
|
||||
siblings: { href: 'urn:repo:4:MembershipEvents', type: 'collection' },
|
||||
actor: { href: 'urn:user:3', type: 'resource' },
|
||||
repo: { href: 'urn:repo:4', type: 'resource' },
|
||||
org: { href: 'urn:org:5', type: 'resource' },
|
||||
member: { href: 'urn:user:7', type: 'resource' },
|
||||
team: { href: 'urn:team:14', type: 'resource' }
|
||||
}
|
||||
expectLinks(document._metadata.links, links);
|
||||
|
||||
const expected = [
|
||||
{ type: 'user', url: 'http://user/3', path: '/actor' },
|
||||
{ type: 'repo', url: 'http://repo/4', path: '/repo' },
|
||||
{ type: 'org', url: 'http://org/5', path: '/org' },
|
||||
{ type: 'user', url: 'http://member/7', path: '/' },
|
||||
{ type: 'team', url: 'http://member/14', path: '/' }
|
||||
];
|
||||
expectQueued(queue, expected);
|
||||
});
|
||||
|
||||
it('should link and queue removed MembershipEvent with a removed team', () => {
|
||||
const request = createRequest('MembershipEvent', 'http://foo/');
|
||||
const queue = [];
|
||||
request.crawler = { queue: sinon.spy(request => { queue.push.apply(queue, request) }) };
|
||||
const payload = {
|
||||
action: 'removed',
|
||||
member: { id: 7, url: 'http://member/7' },
|
||||
team: { id: 14, url: 'http://member/14', deleted: true }
|
||||
}
|
||||
request.document = createEvent('MembershipEvent', payload);
|
||||
|
||||
const processor = new GitHubProcessor();
|
||||
const document = processor.MembershipEvent(request);
|
||||
|
||||
const links = {
|
||||
self: { href: 'urn:repo:4:MembershipEvent:12345', type: 'resource' },
|
||||
siblings: { href: 'urn:repo:4:MembershipEvents', type: 'collection' },
|
||||
actor: { href: 'urn:user:3', type: 'resource' },
|
||||
repo: { href: 'urn:repo:4', type: 'resource' },
|
||||
org: { href: 'urn:org:5', type: 'resource' },
|
||||
member: { href: 'urn:user:7', type: 'resource' }
|
||||
}
|
||||
expectLinks(document._metadata.links, links);
|
||||
|
||||
const expected = [
|
||||
{ type: 'user', url: 'http://user/3', path: '/actor' },
|
||||
{ type: 'repo', url: 'http://repo/4', path: '/repo' },
|
||||
{ type: 'org', url: 'http://org/5', path: '/org' },
|
||||
{ type: 'user', url: 'http://member/7', path: '/' }
|
||||
];
|
||||
expectQueued(queue, expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Status processing', () => {
|
||||
it('should link and queue StatusEvent', () => {
|
||||
const request = createRequest('StatusEvent', 'http://foo/');
|
||||
|
@ -1344,6 +1414,10 @@ function expectQueued(actual, expected) {
|
|||
const ar = a.context.relation;
|
||||
expect(expected.some(e => {
|
||||
const er = e.context ? e.context.relation : null;
|
||||
if (e.type === a.type
|
||||
&& e.url === a.url) {
|
||||
console.log(e, a);
|
||||
}
|
||||
return e.type === a.type
|
||||
&& e.url === a.url
|
||||
&& (!e.urn || e.urn === a.context.qualifier)
|
||||
|
|
Загрузка…
Ссылка в новой задаче