WIP Group contributions by URL
This commit is contained in:
@@ -60,6 +60,78 @@ module('Unit | Service | kredits', function(hooks) {
|
||||
assert.equal(service.contributorsSorted[1].name, 'Manuel', 'sorts by name');
|
||||
});
|
||||
|
||||
test('#contributionsGrouped groups contributions sharing a url', function(assert) {
|
||||
let service = this.owner.lookup('service:kredits');
|
||||
service.set('contributors', contributors);
|
||||
service.set('contributions', contributions);
|
||||
|
||||
const grouped = service.contributionsGrouped;
|
||||
|
||||
// 9 contributions, with ids 1+3 sharing a url and ids 7+8 sharing a url,
|
||||
// so 7 groups total (2 grouped + 5 singletons).
|
||||
assert.equal(grouped.length, 7, 'produces one group per unique key plus singletons');
|
||||
|
||||
const ghGroup = grouped.findBy('groupId', 'https://github.com/67P/kredits-contracts/pull/196');
|
||||
assert.ok(ghGroup, 'github url group exists');
|
||||
assert.ok(ghGroup.isGrouped, 'github group is flagged as grouped');
|
||||
assert.equal(ghGroup.items.length, 2, 'github group has two contributions');
|
||||
assert.deepEqual(ghGroup.contributorIds, [1, 2], 'github group lists both contributor ids');
|
||||
assert.equal(ghGroup.contributors.length, 2, 'github group resolves both contributors');
|
||||
assert.equal(ghGroup.totalAmount, 3000, 'github group sums amounts (1500 + 1500)');
|
||||
assert.equal(ghGroup.kind, 'dev', 'github group takes kind from first item');
|
||||
assert.equal(ghGroup.url, 'https://github.com/67P/kredits-contracts/pull/196');
|
||||
|
||||
const giteaGroup = grouped.findBy('groupId', 'https://gitea.kosmos.org/kredits/kredits-web/issues/231');
|
||||
assert.ok(giteaGroup, 'gitea url group exists');
|
||||
assert.ok(giteaGroup.isGrouped, 'gitea group is flagged as grouped');
|
||||
assert.deepEqual(giteaGroup.contributorIds, [3, 1], 'gitea group lists both contributor ids');
|
||||
assert.equal(giteaGroup.totalAmount, 6500, 'gitea group sums amounts (5000 + 1500)');
|
||||
});
|
||||
|
||||
test('#contributionsGrouped treats manual contributions without url as singletons', function(assert) {
|
||||
let service = this.owner.lookup('service:kredits');
|
||||
service.set('contributors', contributors);
|
||||
service.set('contributions', contributions);
|
||||
|
||||
const grouped = service.contributionsGrouped;
|
||||
const singletons = grouped.filterBy('isGrouped', false);
|
||||
|
||||
// 5 contributions without a url: ids 2, 4, 5, 6, 9
|
||||
assert.equal(singletons.length, 5, 'one singleton group per url-less contribution');
|
||||
singletons.forEach(g => {
|
||||
assert.equal(g.items.length, 1, 'singleton group has exactly one item');
|
||||
assert.notOk(g.groupId, 'singleton group has a null/empty groupId');
|
||||
});
|
||||
});
|
||||
|
||||
test('#siblingContributions returns co-contributor contributions for the same url', function(assert) {
|
||||
let service = this.owner.lookup('service:kredits');
|
||||
service.set('contributors', contributors);
|
||||
service.set('contributions', contributions);
|
||||
|
||||
const c1 = contributions.findBy('id', 1);
|
||||
const siblings = service.siblingContributions(c1);
|
||||
assert.equal(siblings.length, 1, 'contribution 1 has one sibling');
|
||||
assert.equal(siblings[0].id, 3, 'the sibling is contribution 3');
|
||||
});
|
||||
|
||||
test('#siblingContributions returns empty for manual contributions', function(assert) {
|
||||
let service = this.owner.lookup('service:kredits');
|
||||
service.set('contributors', contributors);
|
||||
service.set('contributions', contributions);
|
||||
|
||||
const c2 = contributions.findBy('id', 2);
|
||||
assert.deepEqual(service.siblingContributions(c2), [], 'no siblings for url-less contribution');
|
||||
});
|
||||
|
||||
test('#siblingContributions returns empty for null contribution', function(assert) {
|
||||
let service = this.owner.lookup('service:kredits');
|
||||
service.set('contributors', contributors);
|
||||
service.set('contributions', contributions);
|
||||
|
||||
assert.deepEqual(service.siblingContributions(null), [], 'no siblings for null');
|
||||
});
|
||||
|
||||
test('#kreditsByContributor ignores unconfirmed contributions for contributors that are not loaded', function(assert) {
|
||||
let service = this.owner.lookup('service:kredits');
|
||||
service.set('contributors', contributors);
|
||||
|
||||
Reference in New Issue
Block a user