Fix contributor list, add kredits service tests #115

Merged
raucao merged 7 commits from bugfix/114-contributor_list into master 2019-05-08 10:35:01 +00:00
2 changed files with 17 additions and 4 deletions
Showing only changes of commit ef45d55521 - Show all commits
+17 -2
View File
@@ -46,18 +46,33 @@ export default Service.extend({
}),
galfert commented 2019-05-08 09:05:51 +00:00 (Migrated from github.com)
Review

I think you might want to change the dependency, so the computed property updates when the vetoed status of any of the contributions changes.

   kreditsByContributor: computed('contributionsUnconfirmed.@each.vetoed', 'contributors', function() {
I think you might want to change the dependency, so the computed property updates when the `vetoed` status of any of the contributions changes. ```suggestion kreditsByContributor: computed('contributionsUnconfirmed.@each.vetoed', 'contributors', function() { ```
raucao commented 2019-05-08 09:45:19 +00:00 (Migrated from github.com)
Review

Cool. Will that still account for new and deleted objects in the collection, and changes of other properties?

Cool. Will that still account for new and deleted objects in the collection, and changes of other properties?
galfert commented 2019-05-08 10:19:30 +00:00 (Migrated from github.com)
Review

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}.

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}`.
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 () {
-2
View File
@@ -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);