Move tests
This commit is contained in:
@@ -0,0 +1,43 @@
|
|||||||
|
import { module, test } from 'ember-qunit';
|
||||||
|
import schemas from 'npm:kosmos-schemas';
|
||||||
|
import tv4 from 'npm:tv4';
|
||||||
|
import { ContributionSerializer } from 'kredits-web/lib/kredits';
|
||||||
|
|
||||||
|
module('Serializers contribution');
|
||||||
|
|
||||||
|
test('#serialize returns a valid JSON-LD representation', function(assert) {
|
||||||
|
let serialized = ContributionSerializer.serialize({
|
||||||
|
recipientAddress: '0xd4a64570b12da659ee4bbd41c3509b7b1f9c51ac',
|
||||||
|
kind: 'design',
|
||||||
|
description: 'New logo design',
|
||||||
|
url: 'http://opensourcedesign.org',
|
||||||
|
contributorIpfsHash: 'QmT2A7rY4e7uoKktkcFHQNN7BD1oXdZTgd8wNkr1u9nNVE'
|
||||||
|
});
|
||||||
|
|
||||||
|
let valid = tv4.validate(JSON.parse(serialized), schemas['contribution']);
|
||||||
|
assert.ok(valid);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('#deserialize returns a valid object representation', function(assert) {
|
||||||
|
let json = JSON.stringify({
|
||||||
|
"@context": "https://schema.kosmos.org",
|
||||||
|
"@type": "Contribution",
|
||||||
|
"contributor": {
|
||||||
|
"ipfs": "QmT2A7rY4e7uoKktkcFHQNN7BD1oXdZTgd8wNkr1u9nNVE"
|
||||||
|
},
|
||||||
|
"kind": "design",
|
||||||
|
"description": "New logo design",
|
||||||
|
"details": {},
|
||||||
|
"url": "http://opensourcedesign.org"
|
||||||
|
});
|
||||||
|
let deserialized = ContributionSerializer.deserialize(json);
|
||||||
|
|
||||||
|
let expected = {
|
||||||
|
kind: 'design',
|
||||||
|
description: 'New logo design',
|
||||||
|
details: {},
|
||||||
|
url: 'http://opensourcedesign.org',
|
||||||
|
ipfsData: json,
|
||||||
|
};
|
||||||
|
assert.deepEqual(expected, deserialized);
|
||||||
|
});
|
||||||
@@ -1,49 +1,8 @@
|
|||||||
import { moduleFor, test } from 'ember-qunit';
|
// import { moduleFor, test } from 'ember-qunit';
|
||||||
import schemas from 'npm:kosmos-schemas';
|
//
|
||||||
import tv4 from 'npm:tv4';
|
// moduleFor('model:proposal', 'Unit | Model | proposal');
|
||||||
|
//
|
||||||
moduleFor('model:proposal', 'Unit | Model | proposal');
|
// test('contributor relation', function(assert) {
|
||||||
|
// // TODO: Test contributor relation
|
||||||
test('#toJSON() requires a recipient profile IPFS hash to be set', function(assert) {
|
// assert.ok(true);
|
||||||
let model = this.subject();
|
// });
|
||||||
|
|
||||||
model.setProperties({
|
|
||||||
recipientAddress: '0xd4a64570b12da659ee4bbd41c3509b7b1f9c51ac'
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
|
||||||
let json = model.contributionToJSON();
|
|
||||||
assert.notOk(json, true);
|
|
||||||
} catch(e) {
|
|
||||||
assert.ok(e.message.match(/IPFS hash .* missing/i));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test('#toJSON() requires kind and description to be set', function(assert) {
|
|
||||||
let model = this.subject();
|
|
||||||
|
|
||||||
model.setProperties({
|
|
||||||
recipientProfile: 'QmT2A7rY4e7uoKktkcFHQNN7BD1oXdZTgd8wNkr1u9nNVE'
|
|
||||||
});
|
|
||||||
|
|
||||||
try {
|
|
||||||
let json = model.contributionToJSON();
|
|
||||||
assert.notOk(json, true);
|
|
||||||
} catch(e) {
|
|
||||||
assert.ok(e.message.match(/Missing .* kind.*description/i));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test('#toJSON() returns a valid JSON-LD representation of the model', function(assert) {
|
|
||||||
let model = this.subject();
|
|
||||||
|
|
||||||
model.setProperties({
|
|
||||||
recipientAddress: '0xd4a64570b12da659ee4bbd41c3509b7b1f9c51ac',
|
|
||||||
kind: 'design',
|
|
||||||
description: 'New logo design',
|
|
||||||
url: 'http://opensourcedesign.org',
|
|
||||||
recipientProfile: 'QmT2A7rY4e7uoKktkcFHQNN7BD1oXdZTgd8wNkr1u9nNVE'
|
|
||||||
});
|
|
||||||
|
|
||||||
assert.ok(tv4.validate(model.contributionToJSON(), schemas['contribution']));
|
|
||||||
});
|
|
||||||
|
|||||||
Reference in New Issue
Block a user