Process contribution data before loading models
This commit is contained in:
Vendored
+391
File diff suppressed because one or more lines are too long
Vendored
+13
-11
@@ -1,23 +1,25 @@
|
||||
import Model from 'kredits-web/models/contribution';
|
||||
import contributors from '../../tests/fixtures/contributors';
|
||||
import processContributionData from 'kredits-web/utils/process-contribution-data';
|
||||
|
||||
const items = [];
|
||||
|
||||
const data = [
|
||||
{ id: 1, contributorId: 1, confirmedAtBlock: 1000, claimed: false, vetoed: false, amount: 1500, kind: 'dev' },
|
||||
{ id: 2, contributorId: 1, confirmedAtBlock: 1000, claimed: false, vetoed: false, amount: 5000, kind: 'ops' },
|
||||
{ id: 3, contributorId: 2, confirmedAtBlock: 1000, claimed: false, vetoed: false, amount: 1500, kind: 'ops' },
|
||||
{ id: 4, contributorId: 2, confirmedAtBlock: 1000, claimed: false, vetoed: false, amount: 1500, kind: 'docs' },
|
||||
{ id: 5, contributorId: 1, confirmedAtBlock: 1000, claimed: false, vetoed: false, amount: 5000, kind: 'design' },
|
||||
{ id: 6, contributorId: 1, confirmedAtBlock: 1000, claimed: false, vetoed: true, amount: 500, kind: 'dev' },
|
||||
{ id: 7, contributorId: 3, confirmedAtBlock: 2000, claimed: false, vetoed: false, amount: 5000, kind: 'dev' },
|
||||
{ id: 8, contributorId: 1, confirmedAtBlock: 2000, claimed: false, vetoed: false, amount: 1500, kind: 'community' },
|
||||
{ id: 9, contributorId: 3, confirmedAtBlock: 2000, claimed: false, vetoed: true, amount: 1500, kind: 'docs' },
|
||||
{ id: 1, contributorId: 1, confirmedAt: 1000, claimed: false, vetoed: false, amount: 1500, kind: 'dev' },
|
||||
{ id: 2, contributorId: 1, confirmedAt: 1000, claimed: false, vetoed: false, amount: 5000, kind: 'ops' },
|
||||
{ id: 3, contributorId: 2, confirmedAt: 1000, claimed: false, vetoed: false, amount: 1500, kind: 'ops' },
|
||||
{ id: 4, contributorId: 2, confirmedAt: 1000, claimed: false, vetoed: false, amount: 1500, kind: 'docs' },
|
||||
{ id: 5, contributorId: 1, confirmedAt: 1000, claimed: false, vetoed: false, amount: 5000, kind: 'design' },
|
||||
{ id: 6, contributorId: 1, confirmedAt: 1000, claimed: false, vetoed: true, amount: 500, kind: 'dev' },
|
||||
{ id: 7, contributorId: 3, confirmedAt: 2000, claimed: false, vetoed: false, amount: 5000, kind: 'dev' },
|
||||
{ id: 8, contributorId: 1, confirmedAt: 2000, claimed: false, vetoed: false, amount: 1500, kind: 'community' },
|
||||
{ id: 9, contributorId: 3, confirmedAt: 2000, claimed: false, vetoed: true, amount: 1500, kind: 'docs' },
|
||||
];
|
||||
|
||||
data.forEach(attrs => {
|
||||
attrs.contributor = contributors.findBy('id', attrs.contributorId.toString());
|
||||
items.push(Model.create(attrs))
|
||||
const c = Model.create(processContributionData(attrs));
|
||||
c.set('contributor', contributors.findBy('id', attrs.contributorId.toString()));
|
||||
items.push(c);
|
||||
});
|
||||
|
||||
export default items;
|
||||
|
||||
Vendored
+5
-1
@@ -1,4 +1,5 @@
|
||||
import Contributor from 'kredits-web/models/contributor';
|
||||
import processContributorData from 'kredits-web/utils/process-contributor-data';
|
||||
|
||||
const contributors = [];
|
||||
|
||||
@@ -8,6 +9,9 @@ const data = [
|
||||
{ id: '3', name: 'Manuel', totalKreditsEarned: 0, github_uid: 54812 }
|
||||
];
|
||||
|
||||
data.forEach(attrs => contributors.push(Contributor.create(attrs)));
|
||||
data.forEach(attrs => {
|
||||
const c = Contributor.create(processContributorData(attrs));
|
||||
contributors.push(c);
|
||||
});
|
||||
|
||||
export default contributors;
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { module, test } from 'qunit';
|
||||
import processContributionData from 'kredits-web/utils/process-contribution-data';
|
||||
import testData from '../../fixtures/contribution-data';
|
||||
|
||||
module('Unit | Utility | process-contribution-data', function() {
|
||||
|
||||
let result = processContributionData(testData);
|
||||
|
||||
test('formats the data correctly', function(assert) {
|
||||
assert.ok(typeof result.confirmedAt === 'number');
|
||||
});
|
||||
|
||||
test('copies other properties', function(assert) {
|
||||
[
|
||||
'id', 'contributorId', 'amount', 'vetoed',
|
||||
'ipfsHash', 'kind', 'description', 'details',
|
||||
'url', 'date', 'time', 'pendingTx'
|
||||
].forEach(p => {
|
||||
assert.ok(Object.prototype.hasOwnProperty.call(result, p), `copies property ${p}`);
|
||||
})
|
||||
});
|
||||
|
||||
test('does not copy unnecessary properties', function(assert) {
|
||||
['exists', '5'].forEach(p => {
|
||||
assert.notOk(Object.prototype.hasOwnProperty.call(result, p));
|
||||
})
|
||||
});
|
||||
});
|
||||
@@ -8,10 +8,10 @@ module('Unit | Utility | process-contributor-data', function() {
|
||||
|
||||
test('formats the data correctly', function(assert) {
|
||||
// TODO use integers everywhere for IDs
|
||||
assert.ok(typeof result.id == 'string');
|
||||
assert.ok(typeof result.balance == 'number');
|
||||
assert.ok(typeof result.totalKreditsEarned == 'number');
|
||||
assert.ok(typeof result.contributionsCount == 'number');
|
||||
assert.ok(typeof result.id === 'string');
|
||||
assert.ok(typeof result.balance === 'number');
|
||||
assert.ok(typeof result.totalKreditsEarned === 'number');
|
||||
assert.ok(typeof result.contributionsCount === 'number');
|
||||
});
|
||||
|
||||
test('copies other properties', function(assert) {
|
||||
|
||||
Reference in New Issue
Block a user