Skip to content

Commit

Permalink
add missed test
Browse files Browse the repository at this point in the history
  • Loading branch information
magicmatatjahu committed Mar 25, 2022
1 parent 407e433 commit ba6f4f2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/models/v2/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class Info
};

tags(): TagsInterface {
const tags = this._json.tags || [];
const tags = this._meta.asyncapi.parsed.tags || [];
return new Tags(tags.map((tag: any, idx: number) => this.createModel(Tag, tag, { pointer: `/tags/${idx}` })));
}
}
22 changes: 22 additions & 0 deletions test/models/v2/info.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Info } from '../../../src/models/v2/info';
import { Contact } from '../../../src/models/v2/contact';
import { License } from '../../../src/models/v2/license';
import { ExternalDocumentation } from '../../../src/models/v2/mixins/external-docs';
import { Tags, Tag } from '../../../src/models/v2/mixins/tags';
import { createDetailedAsyncAPI } from '../../../src/utils';

import {
Expand Down Expand Up @@ -189,6 +190,27 @@ describe('Info model', function() {
});
});

describe('.tags()', function() {
it('should return the collection of tags', function() {
const tags = [{ name: 'one' }, { name: 'two' }];
const doc = { asyncapi: '2.0.0', tags };
const asyncapi = createDetailedAsyncAPI(doc, doc);
const d = new Info({}, { asyncapi, parent: null, pointer: '/info' });
expect(d.tags()).toBeInstanceOf(Tags);
expect(d.tags().length).toEqual(2);
expect(d.tags().all()[0]).toBeInstanceOf(Tag);
expect(d.tags().all()[1]).toBeInstanceOf(Tag);
});

it('should return empty array when there is an empty collection', function() {
const doc = { asyncapi: '2.0.0' };
const asyncapi = createDetailedAsyncAPI(doc, doc);
const d = new Info({}, { asyncapi, parent: null, pointer: '/info' });
expect(d.tags()).toBeInstanceOf(Tags);
expect(d.tags().all()).toEqual([]);
});
});

describe('mixins inheritance', function() {
assertDescriptionMixinInheritance(Info);
assertExtensionsMixinInheritance(Info);
Expand Down

0 comments on commit ba6f4f2

Please sign in to comment.