Don't cache contribution details in browser storage
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
export default function processContributionData(data) {
|
export default function processContributionData(data, options={}) {
|
||||||
const processed = {}
|
const processed = {}
|
||||||
|
|
||||||
if (data.confirmedAtBlock && (typeof data.confirmedAtBlock.toNumber === 'function')) {
|
if (data.confirmedAtBlock && (typeof data.confirmedAtBlock.toNumber === 'function')) {
|
||||||
@@ -9,12 +9,16 @@ export default function processContributionData(data) {
|
|||||||
|
|
||||||
const otherProperties = [
|
const otherProperties = [
|
||||||
'id', 'contributorId', 'amount', 'vetoed', 'ipfsHash', 'kind',
|
'id', 'contributorId', 'amount', 'vetoed', 'ipfsHash', 'kind',
|
||||||
'description', 'details', 'url', 'date', 'time', 'pendingTx'
|
'description', 'url', 'date', 'time', 'pendingTx'
|
||||||
];
|
];
|
||||||
|
|
||||||
otherProperties.forEach(prop => {
|
otherProperties.forEach(prop => {
|
||||||
processed[prop] = data[prop];
|
processed[prop] = data[prop];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (options.includeDetails) {
|
||||||
|
processed.details = data.details;
|
||||||
|
}
|
||||||
|
|
||||||
return processed;
|
return processed;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,16 +4,18 @@ import testData from '../../fixtures/contribution-data';
|
|||||||
|
|
||||||
module('Unit | Utility | process-contribution-data', function() {
|
module('Unit | Utility | process-contribution-data', function() {
|
||||||
|
|
||||||
let result = processContributionData(testData);
|
|
||||||
|
|
||||||
test('formats the data correctly', function(assert) {
|
test('formats the data correctly', function(assert) {
|
||||||
|
const result = processContributionData(testData);
|
||||||
|
|
||||||
assert.ok(typeof result.confirmedAt === 'number');
|
assert.ok(typeof result.confirmedAt === 'number');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('copies other properties', function(assert) {
|
test('copies other properties', function(assert) {
|
||||||
|
const result = processContributionData(testData);
|
||||||
|
|
||||||
[
|
[
|
||||||
'id', 'contributorId', 'amount', 'vetoed',
|
'id', 'contributorId', 'amount', 'vetoed',
|
||||||
'ipfsHash', 'kind', 'description', 'details',
|
'ipfsHash', 'kind', 'description',
|
||||||
'url', 'date', 'time', 'pendingTx'
|
'url', 'date', 'time', 'pendingTx'
|
||||||
].forEach(p => {
|
].forEach(p => {
|
||||||
assert.ok(Object.prototype.hasOwnProperty.call(result, p), `copies property ${p}`);
|
assert.ok(Object.prototype.hasOwnProperty.call(result, p), `copies property ${p}`);
|
||||||
@@ -21,8 +23,17 @@ module('Unit | Utility | process-contribution-data', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('does not copy unnecessary properties', function(assert) {
|
test('does not copy unnecessary properties', function(assert) {
|
||||||
|
const result = processContributionData(testData);
|
||||||
|
|
||||||
['exists', '5'].forEach(p => {
|
['exists', '5'].forEach(p => {
|
||||||
assert.notOk(Object.prototype.hasOwnProperty.call(result, p));
|
assert.notOk(Object.prototype.hasOwnProperty.call(result, p));
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('includeDetails option', function(assert) {
|
||||||
|
const result = processContributionData(testData, { includeDetails: true });
|
||||||
|
|
||||||
|
assert.ok(Object.prototype.hasOwnProperty.call(result, 'details'), 'includes the details property/value');
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user