Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.

Commit 62dff8c

Browse files
author
Marco Friso
authored
fix(core): make category hosts return host categories (#472)
1 parent 908c6bb commit 62dff8c

File tree

4 files changed

+92
-10
lines changed

4 files changed

+92
-10
lines changed

packages/api-elements/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# API Elements (JavaScript) CHANGELOG
22

3+
## 0.2.6 (2020-07-01)
4+
5+
### Bug Fixes
6+
7+
- Fixes the `hosts` property in api category to return the hosts category.
8+
39
## 0.2.5 (2020-06-13)
410

511
### Bug Fixes

packages/api-elements/lib/elements/Category.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ class Category extends ArrayElement {
1515
this.element = 'category';
1616
}
1717

18+
/**
19+
* @name hosts
20+
* @type ArraySlice
21+
* @memberof Category.prototype
22+
*/
23+
get hosts() {
24+
return this.children.filter(item => item.classes.contains('hosts'));
25+
}
26+
1827
/**
1928
* @name resourceGroups
2029
* @type ArraySlice
@@ -78,15 +87,6 @@ class Category extends ArrayElement {
7887
return this.children.filter(item => schemes.indexOf(item.element) !== -1);
7988
}
8089

81-
/**
82-
* @name hosts
83-
* @type ArraySlice
84-
* @memberof Category.prototype
85-
*/
86-
get hosts() {
87-
return this.children.filter(item => item.element === 'hosts');
88-
}
89-
9090
metadata(value) {
9191
const metadata = this.attributes.get('metadata');
9292

packages/api-elements/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "api-elements",
3-
"version": "0.2.5",
3+
"version": "0.2.6",
44
"description": "API Elements JavaScript",
55
"author": "Apiary.io <[email protected]>",
66
"license": "MIT",

packages/api-elements/test/api-description-test.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,20 @@ describe('API description namespace', () => {
102102
},
103103
},
104104
content: [
105+
{
106+
element: 'category',
107+
meta: {
108+
classes: {
109+
element: 'array',
110+
content: [
111+
{
112+
element: 'string',
113+
content: 'hosts',
114+
},
115+
],
116+
},
117+
},
118+
},
105119
{
106120
element: 'category',
107121
meta: {
@@ -212,6 +226,16 @@ describe('API description namespace', () => {
212226
expect(random).to.be.undefined;
213227
});
214228

229+
it('should contain hosts', () => {
230+
const items = category.hosts;
231+
expect(items).to.have.length(1);
232+
233+
items.forEach((item) => {
234+
expect(item).to.be.an.instanceof(Category);
235+
expect(item).to.have.class('hosts');
236+
});
237+
});
238+
215239
it('should contain a resource group', () => {
216240
const items = category.resourceGroups;
217241
expect(items).to.have.length(1);
@@ -734,6 +758,20 @@ describe('API description namespace', () => {
734758
},
735759
],
736760
},
761+
hosts: {
762+
element: 'array',
763+
content: [
764+
{
765+
element: 'resource',
766+
attributes: {
767+
href: {
768+
element: 'href',
769+
content: 'https://first-server.com',
770+
},
771+
},
772+
},
773+
],
774+
},
737775
},
738776
content: [
739777
{
@@ -795,6 +833,18 @@ describe('API description namespace', () => {
795833
});
796834
});
797835

836+
it('should have hosts', () => {
837+
expect(resource.hosts.first.attributes.get('href').toValue()).to.deep.equal('https://first-server.com');
838+
});
839+
840+
it('should set hosts', () => {
841+
const host = new namespace.elements.Resource();
842+
host.href = 'https://second-server.com';
843+
resource.hosts = [host];
844+
845+
expect(resource.hosts.first.attributes.get('href').toValue()).to.deep.equal('https://second-server.com');
846+
});
847+
798848
it('should contain a transition', () => {
799849
const items = resource.transitions;
800850
expect(items).to.have.length(1);
@@ -842,6 +892,20 @@ describe('API description namespace', () => {
842892
},
843893
],
844894
},
895+
hosts: {
896+
element: 'array',
897+
content: [
898+
{
899+
element: 'resource',
900+
attributes: {
901+
href: {
902+
element: 'href',
903+
content: 'https://first-server.com',
904+
},
905+
},
906+
},
907+
],
908+
},
845909
data: {
846910
element: 'dataStructure',
847911
content: {
@@ -943,6 +1007,18 @@ describe('API description namespace', () => {
9431007
});
9441008
});
9451009

1010+
it('should have hosts', () => {
1011+
expect(transition.hosts.first.href.toValue()).to.deep.equal('https://first-server.com');
1012+
});
1013+
1014+
it('should set hosts', () => {
1015+
const host = new namespace.elements.Resource();
1016+
host.href = 'https://second-server.com';
1017+
transition.hosts = [host];
1018+
1019+
expect(transition.hosts.first.href.toValue()).to.deep.equal('https://second-server.com');
1020+
});
1021+
9461022
it('should have data', () => {
9471023
expect(transition.data.toValue()).to.deep.equal({});
9481024
});

0 commit comments

Comments
 (0)