Skip to content
This repository has been archived by the owner on Jan 4, 2022. It is now read-only.

feat: add metadata to document, data contract and identity #318

Merged
merged 4 commits into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/dataContract/DataContract.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,22 @@ class DataContract {
return this.binaryProperties[type];
}

/**
* Set metadata
* @param {Object} metadata
*/
setMetadata(metadata) {
this.metadata = metadata;
}

/**
* Get metadata
* @returns {Object}
*/
getMetadata() {
return this.metadata;
}

/**
* Return Data Contract as plain object
*
Expand Down
16 changes: 16 additions & 0 deletions lib/document/Document.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,22 @@ class Document {
return this.updatedAt;
}

/**
* Set metadata
* @param {Object} metadata
*/
setMetadata(metadata) {
this.metadata = metadata;
}

/**
* Get metadata
* @returns {Object}
*/
getMetadata() {
return this.metadata;
}

/**
* Return Document as plain object
*
Expand Down
16 changes: 16 additions & 0 deletions lib/identity/Identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,22 @@ class Identity {

return this;
}

/**
* Set metadata
* @param {Object} metadata
*/
setMetadata(metadata) {
this.metadata = metadata;
}

/**
* Get metadata
* @returns {Object}
*/
getMetadata() {
return this.metadata;
}
}

/**
Expand Down
25 changes: 25 additions & 0 deletions test/integration/document/Document.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ const getDocumentsFixture = require('../../../lib/test/fixtures/getDocumentsFixt
describe('Document', () => {
let document;
let dataContract;
let metadataFixture;

beforeEach(() => {
dataContract = getDataContractFixture();
[document] = getDocumentsFixture(dataContract).slice(8);

metadataFixture = {
height: 42,
};

document.setMetadata(metadataFixture);
});

describe('#toJSON', () => {
Expand Down Expand Up @@ -65,4 +72,22 @@ describe('Document', () => {
expect(result.identifierField).to.be.an.instanceOf(Identifier);
});
});

describe('#setMetadata', () => {
it('should set metadata', () => {
const otherMetadata = {
height: 43,
};

document.setMetadata(otherMetadata);

expect(document.metadata).to.deep.equal(otherMetadata);
});
});

describe('#getMetadata', () => {
it('should get metadata', () => {
expect(document.getMetadata()).to.deep.equal(metadataFixture);
});
});
});
25 changes: 25 additions & 0 deletions test/unit/dataContract/DataContract.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('DataContract', () => {
let entropy;
let contractId;
let getBinaryPropertiesFromSchemaMock;
let metadataFixture;

beforeEach(function beforeEach() {
hashMock = this.sinonSandbox.stub();
Expand Down Expand Up @@ -66,6 +67,12 @@ describe('DataContract', () => {
documents,
$defs: {},
});

metadataFixture = {
height: 42,
};

dataContract.setMetadata(metadataFixture);
});

describe('constructor', () => {
Expand Down Expand Up @@ -369,4 +376,22 @@ describe('DataContract', () => {
}
});
});

describe('#setMetadata', () => {
it('should set metadata', () => {
const otherMetadata = {
height: 43,
};

dataContract.setMetadata(otherMetadata);

expect(dataContract.metadata).to.deep.equal(otherMetadata);
});
});

describe('#getMetadata', () => {
it('should get metadata', () => {
expect(dataContract.getMetadata()).to.deep.equal(metadataFixture);
});
});
});
25 changes: 25 additions & 0 deletions test/unit/identity/Identity.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe('Identity', () => {
let Identity;
let hashMock;
let encodeMock;
let metadataFixture;

beforeEach(function beforeEach() {
hashMock = this.sinonSandbox.stub();
Expand Down Expand Up @@ -40,6 +41,12 @@ describe('Identity', () => {
};

identity = new Identity(rawIdentity);

metadataFixture = {
height: 42,
};

identity.setMetadata(metadataFixture);
});

describe('#constructor', () => {
Expand Down Expand Up @@ -172,4 +179,22 @@ describe('Identity', () => {
expect(identity.balance).to.equal(40);
});
});

describe('#setMetadata', () => {
it('should set metadata', () => {
const otherMetadata = {
height: 43,
};

identity.setMetadata(otherMetadata);

expect(identity.metadata).to.deep.equal(otherMetadata);
});
});

describe('#getMetadata', () => {
it('should get metadata', () => {
expect(identity.getMetadata()).to.deep.equal(metadataFixture);
});
});
});