Skip to content

Commit

Permalink
feat: add hasMessages function to main model (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
derberg authored Jun 15, 2020
1 parent f7b1947 commit 4a9805a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/models/asyncapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ class AsyncAPIDocument extends Base {
return this._json.tags.map(t => new Tag(t));
}

/**
* @returns {boolean}
*/
hasMessages() {
return !!this.allMessages().size
}

/**
* @returns {Map<Message>}
*/
Expand Down
18 changes: 18 additions & 0 deletions test/models/asyncapi_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,24 @@ describe('AsyncAPIDocument', () => {
});
});

describe('#hasMessages()', function () {
it('should return true if there is a message in components but not in channels', () => {
const doc = { components: { messages: { test: { test: true, k: 3 } } } };
const d = new AsyncAPIDocument(doc);
expect(d.hasMessages()).to.equal(true);
});
it('should return true if there is a message in channels operations but not in components', () => {
const doc = { channels: { test: { publish: { message: { name: 'test', test: false, k: 1 } } } } };
const d = new AsyncAPIDocument(doc);
expect(d.hasMessages()).to.equal(true);
});
it('should return false if there are no messages neither in components nor in channels operations', () => {
const doc = { channels: { test: { publish: { } } }, components: { } };
const d = new AsyncAPIDocument(doc);
expect(d.hasMessages()).to.equal(false);
});
});

describe('#allMessages()', function () {
it('should return an array with all the messages used in the document and overwrite the message from channel', () => {
const doc = { channels: { test: { publish: { message: { name: 'test', test: false, k: 1 } } } }, components: { messages: { test: { test: true, k: 3 } } } };
Expand Down

0 comments on commit 4a9805a

Please sign in to comment.