Process contributor data

Add util function for processing contributor data, and remove bignums,
etc.
This commit is contained in:
2020-05-27 16:27:08 +02:00
parent f996c89dfe
commit 871731110b
6 changed files with 124 additions and 12 deletions
+64
View File
@@ -0,0 +1,64 @@
export default {
"0": 1,
"1": "0x7E8f313C56F809188313aa274Fa67EE58c31515d",
"2": "0x99b8afd7b266e19990924a8be9099e81054b70c36b20937228a77a5cf75723b8",
"3": 18,
"4": 32,
"5": true,
"6": {
"_hex": "0x09979c0838e8fc880000"
},
"7": 53500,
"8": {
"_hex": "0x49"
},
"9": true,
"id": 1,
"account": "0x7E8f313C56F809188313aa274Fa67EE58c31515d",
"hashDigest": "0x99b8afd7b266e19990924a8be9099e81054b70c36b20937228a77a5cf75723b8",
"hashFunction": 18,
"hashSize": 32,
"isCore": true,
"balance": {
"_hex": "0x09979c0838e8fc880000"
},
"totalKreditsEarned": 53500,
"contributionsCount": {
"_hex": "0x49",
"toNumber": function() { return 73; }
},
"exists": true,
"balanceInt": 45298,
"ipfsHash": "QmYgiRd1FZ7JjDGBwkmLQNF6XQuyF8AWoFDRvUWhhmxiEj",
"name": "Bumi",
"kind": "person",
"url": "https://michaelbumann.com",
"accounts": [
{
"site": "github.com",
"uid": 318,
"username": "bumi",
"url": "https://github.com/bumi"
},
{
"site": "gitea.kosmos.org",
"username": "bumi",
"url": "https://gitea.kosmos.org/bumi"
},
{
"site": "wiki.kosmos.org",
"username": "Bumi",
"url": "https://wiki.kosmos.org/User:Bumi"
},
{
"site": "zoom.us",
"username": "bumi"
}
],
"github_uid": 318,
"github_username": "bumi",
"gitea_username": "bumi",
"wiki_username": "Bumi",
"zoom_display_name": "bumi",
"ipfsData": "{\n \"@context\": \"https://schema.kosmos.org\",\n \"@type\": \"Contributor\",\n \"kind\": \"person\",\n \"name\": \"Bumi\",\n \"accounts\": [\n {\n \"site\": \"github.com\",\n \"uid\": 318,\n \"username\": \"bumi\",\n \"url\": \"https://github.com/bumi\"\n },\n {\n \"site\": \"gitea.kosmos.org\",\n \"username\": \"bumi\",\n \"url\": \"https://gitea.kosmos.org/bumi\"\n },\n {\n \"site\": \"wiki.kosmos.org\",\n \"username\": \"Bumi\",\n \"url\": \"https://wiki.kosmos.org/User:Bumi\"\n },\n {\n \"site\": \"zoom.us\",\n \"username\": \"bumi\"\n }\n ],\n \"url\": \"https://michaelbumann.com\"\n}"
}
+3 -3
View File
@@ -3,9 +3,9 @@ import Contributor from 'kredits-web/models/contributor';
const contributors = [];
const data = [
{ id: 1, name: 'Bumi', totalKreditsEarned: 11500, github_uid: 318 },
{ id: 2, name: 'Râu Cao', totalKreditsEarned: 3000, github_uid: 842 },
{ id: 3, name: 'Manuel', totalKreditsEarned: 0, github_uid: 54812 }
{ id: '1', name: 'Bumi', totalKreditsEarned: 11500, github_uid: 318 },
{ id: '2', name: 'Râu Cao', totalKreditsEarned: 3000, github_uid: 842 },
{ id: '3', name: 'Manuel', totalKreditsEarned: 0, github_uid: 54812 }
];
data.forEach(attrs => contributors.push(Contributor.create(attrs)));
@@ -0,0 +1,31 @@
import { module, test } from 'qunit';
import processContributorData from 'kredits-web/utils/process-contributor-data';
import testData from '../../fixtures/contributor-data';
module('Unit | Utility | process-contributor-data', function() {
let result = processContributorData(testData);
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');
});
test('copies other properties', function(assert) {
[
'account', 'accounts', 'ipfsHash', 'isCore', 'kind', 'name', 'url',
'github_username', 'github_uid', 'wiki_username', 'zoom_display_name'
].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));
})
});
});