Fix contributor list, add kredits service tests #115
+17
-2
@@ -46,18 +46,33 @@ export default Service.extend({
|
||||
}),
|
||||
|
|
||||
|
||||
kreditsByContributor: computed('contributionsUnconfirmed.[]', 'contributors', function() {
|
||||
const contributionsGrouped = groupBy(this.contributionsUnconfirmed, 'contributorId');
|
||||
const contributionsUnconfirmed = this.contributionsUnconfirmed;
|
||||
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 contributor = this.contributors.findBy('id', c.value.toString());
|
||||
|
||||
return EmberObject.create({
|
||||
contributor: contributor,
|
||||
amountUnconfirmed: amountUnconfirmed,
|
||||
amountConfirmed: contributor.totalKreditsEarned,
|
||||
amountTotal: contributor.totalKreditsEarned + amountUnconfirmed
|
||||
})
|
||||
});
|
||||
|
||||
contributorsWithOnlyConfirmed.forEach(c => {
|
||||
kreditsByContributor.push(EmberObject.create({
|
||||
contributor: c,
|
||||
amountUnconfirmed: 0,
|
||||
amountConfirmed: c.totalKreditsEarned,
|
||||
amountTotal: c.totalKreditsEarned
|
||||
}));
|
||||
})
|
||||
|
||||
return kreditsByContributor;
|
||||
}),
|
||||
|
||||
init () {
|
||||
|
||||
@@ -32,8 +32,6 @@ module('Unit | Service | kredits', function(hooks) {
|
||||
|
||||
const kreditsByContributor = service.kreditsByContributor;
|
||||
|
||||
console.log(kreditsByContributor);
|
||||
|
||||
assert.equal(kreditsByContributor.length, 3, 'includes all contributors with confirmed kredits');
|
||||
|
||||
const c1 = kreditsByContributor.find(k => k.contributor.id == 1);
|
||||
|
||||
Reference in New Issue
Block a user
I think you might want to change the dependency, so the computed property updates when the
vetoedstatus of any of the contributions changes.Cool. Will that still account for new and deleted objects in the collection, and changes of other properties?
Yes, it will also update when the array itself changes (e.g. elements added or removed). If you want to add additional properties as dependencies, you would add them like this
contributionsUnconfirmed.@each.{vetoed,otherProperty}.