Merge pull request #115 from 67P/bugfix/114-contributor_list
Fix contributor list, add kredits service tests
This commit was merged in pull request #115.
This commit is contained in:
+18
-3
@@ -45,19 +45,34 @@ export default Service.extend({
|
|||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
|
||||||
kreditsByContributor: computed('contributionsUnconfirmed.[]', 'contributors', function() {
|
kreditsByContributor: computed('contributionsUnconfirmed.@each.vetoed', 'contributors', function() {
|
||||||
const contributionsGrouped = groupBy(this.contributionsUnconfirmed, 'contributorId');
|
const contributionsUnconfirmed = this.contributionsUnconfirmed.filterBy('vetoed', false);
|
||||||
|
const contributionsGrouped = groupBy(contributionsUnconfirmed, 'contributorId');
|
||||||
|
const contributorsWithUnconfirmed = contributionsGrouped.map(c => c.value.toString());
|
||||||
|
const contributorsWithOnlyConfirmed = this.contributors.reject(c => contributorsWithUnconfirmed.includes(c.id))
|
||||||
|
|
||||||
return contributionsGrouped.map(c => {
|
const kreditsByContributor = contributionsGrouped.map(c => {
|
||||||
const amountUnconfirmed = c.items.mapBy('amount').reduce((a, b) => a + b);
|
const amountUnconfirmed = c.items.mapBy('amount').reduce((a, b) => a + b);
|
||||||
const contributor = this.contributors.findBy('id', c.value.toString());
|
const contributor = this.contributors.findBy('id', c.value.toString());
|
||||||
|
|
||||||
return EmberObject.create({
|
return EmberObject.create({
|
||||||
contributor: contributor,
|
contributor: contributor,
|
||||||
amountUnconfirmed: amountUnconfirmed,
|
amountUnconfirmed: amountUnconfirmed,
|
||||||
amountConfirmed: contributor.totalKreditsEarned,
|
amountConfirmed: contributor.totalKreditsEarned,
|
||||||
amountTotal: contributor.totalKreditsEarned + amountUnconfirmed
|
amountTotal: contributor.totalKreditsEarned + amountUnconfirmed
|
||||||
})
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
contributorsWithOnlyConfirmed.forEach(c => {
|
||||||
|
kreditsByContributor.push(EmberObject.create({
|
||||||
|
contributor: c,
|
||||||
|
amountUnconfirmed: 0,
|
||||||
|
amountConfirmed: c.totalKreditsEarned,
|
||||||
|
amountTotal: c.totalKreditsEarned
|
||||||
|
}));
|
||||||
})
|
})
|
||||||
|
|
||||||
|
return kreditsByContributor;
|
||||||
}),
|
}),
|
||||||
|
|
||||||
init () {
|
init () {
|
||||||
|
|||||||
Vendored
+18
@@ -0,0 +1,18 @@
|
|||||||
|
import Model from 'kredits-web/models/contribution';
|
||||||
|
|
||||||
|
const items = [];
|
||||||
|
|
||||||
|
const data = [
|
||||||
|
{ id: 1, contributorId: 1, confirmedAtBlock: 1000, claimed: false, vetoed: false, amount: 1500 },
|
||||||
|
{ id: 2, contributorId: 1, confirmedAtBlock: 1000, claimed: false, vetoed: false, amount: 5000 },
|
||||||
|
{ id: 3, contributorId: 2, confirmedAtBlock: 1000, claimed: false, vetoed: false, amount: 1500 },
|
||||||
|
{ id: 4, contributorId: 2, confirmedAtBlock: 1000, claimed: false, vetoed: false, amount: 1500 },
|
||||||
|
{ id: 5, contributorId: 1, confirmedAtBlock: 1000, claimed: false, vetoed: false, amount: 5000 },
|
||||||
|
{ id: 6, contributorId: 3, confirmedAtBlock: 2000, claimed: false, vetoed: false, amount: 5000 },
|
||||||
|
{ id: 7, contributorId: 1, confirmedAtBlock: 2000, claimed: false, vetoed: false, amount: 1500 },
|
||||||
|
{ id: 8, contributorId: 3, confirmedAtBlock: 2000, claimed: false, vetoed: true, amount: 1500 },
|
||||||
|
];
|
||||||
|
|
||||||
|
data.forEach(attrs => items.push(Model.create(attrs)));
|
||||||
|
|
||||||
|
export default items;
|
||||||
Vendored
+3
-3
@@ -3,9 +3,9 @@ import Contributor from 'kredits-web/models/contributor';
|
|||||||
const contributors = [];
|
const contributors = [];
|
||||||
|
|
||||||
const data = [
|
const data = [
|
||||||
{ id: 1, name: 'Bumi', totalKreditsEarned: 5500 },
|
{ id: 1, name: 'Bumi', totalKreditsEarned: 11500 },
|
||||||
{ id: 2, name: 'Râu Cao', totalKreditsEarned: 1500 },
|
{ id: 2, name: 'Râu Cao', totalKreditsEarned: 3000 },
|
||||||
{ id: 3, name: 'Manuel', totalKreditsEarned: 3000 }
|
{ id: 3, name: 'Manuel', totalKreditsEarned: 0 }
|
||||||
];
|
];
|
||||||
|
|
||||||
data.forEach(attrs => contributors.push(Contributor.create(attrs)));
|
data.forEach(attrs => contributors.push(Contributor.create(attrs)));
|
||||||
|
|||||||
@@ -1,12 +1,52 @@
|
|||||||
import { module, test } from 'qunit';
|
import { module, test } from 'qunit';
|
||||||
import { setupTest } from 'ember-qunit';
|
import { setupTest } from 'ember-qunit';
|
||||||
|
import contributors from '../../fixtures/contributors';
|
||||||
|
import contributions from '../../fixtures/contributions';
|
||||||
|
|
||||||
module('Unit | Service | kredits', function(hooks) {
|
module('Unit | Service | kredits', function(hooks) {
|
||||||
setupTest(hooks);
|
setupTest(hooks);
|
||||||
|
|
||||||
// Replace this with your real tests.
|
test('#contributionsConfirmed', function(assert) {
|
||||||
test('it exists', function(assert) {
|
|
||||||
let service = this.owner.lookup('service:kredits');
|
let service = this.owner.lookup('service:kredits');
|
||||||
assert.ok(service);
|
service.set('contributions', contributions);
|
||||||
|
service.set('currentBlock', 1023);
|
||||||
|
|
||||||
|
const items = service.contributionsConfirmed;
|
||||||
|
assert.equal(items.length, 5);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('#contributionsUnconfirmed', function(assert) {
|
||||||
|
let service = this.owner.lookup('service:kredits');
|
||||||
|
service.set('contributions', contributions);
|
||||||
|
service.set('currentBlock', 1023);
|
||||||
|
|
||||||
|
const items = service.contributionsUnconfirmed;
|
||||||
|
assert.equal(items.length, 3);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('#kreditsByContributor', function(assert) {
|
||||||
|
let service = this.owner.lookup('service:kredits');
|
||||||
|
service.set('contributors', contributors);
|
||||||
|
service.set('contributions', contributions);
|
||||||
|
service.set('currentBlock', 1023);
|
||||||
|
|
||||||
|
const kreditsByContributor = service.kreditsByContributor;
|
||||||
|
|
||||||
|
assert.equal(kreditsByContributor.length, 3, 'includes all contributors with confirmed kredits');
|
||||||
|
|
||||||
|
const c1 = kreditsByContributor.find(k => k.contributor.id == 1);
|
||||||
|
assert.equal(c1.amountConfirmed, 11500, 'correct amount confirmed');
|
||||||
|
assert.equal(c1.amountUnconfirmed, 1500, 'correct amount unconfirmed');
|
||||||
|
assert.equal(c1.amountTotal, 13000, 'correct amount total');
|
||||||
|
|
||||||
|
const c2 = kreditsByContributor.find(k => k.contributor.id == 2);
|
||||||
|
assert.equal(c2.amountConfirmed, 3000, 'correct amount confirmed');
|
||||||
|
assert.equal(c2.amountUnconfirmed, 0, 'correct amount unconfirmed');
|
||||||
|
assert.equal(c2.amountTotal, 3000, 'correct amount total');
|
||||||
|
|
||||||
|
const c3 = kreditsByContributor.find(k => k.contributor.id == 3);
|
||||||
|
assert.equal(c3.amountConfirmed, 0, 'correct amount confirmed');
|
||||||
|
assert.equal(c3.amountUnconfirmed, 5000, 'correct amount unconfirmed');
|
||||||
|
assert.equal(c3.amountTotal, 5000, 'correct amount total');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user