-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(ns-asyncapi-2-0): add tests using S-expressions snapshots
- Loading branch information
Showing
33 changed files
with
727 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...idom-ns-asyncapi-2-0/src/refractor/visitors/async-api-2-0/channel-item/BindingsVisitor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import stampit from 'stampit'; | ||
import { T as stubTrue } from 'ramda'; | ||
import { ObjectElement } from 'apidom'; | ||
|
||
import ReferenceElement from '../../../../elements/Reference'; | ||
import AlternatingVisitor from '../../generics/AlternatingVisitor'; | ||
import FallbackVisitor from '../../FallbackVisitor'; | ||
import { isReferenceLikeElement } from '../../../predicates'; | ||
import { isReferenceElement } from '../../../../predicates'; | ||
|
||
const BindingsVisitor = stampit(AlternatingVisitor, FallbackVisitor, { | ||
props: { | ||
alternator: [ | ||
{ predicate: isReferenceLikeElement, specPath: ['document', 'objects', 'Reference'] }, | ||
{ predicate: stubTrue, specPath: ['document', 'objects', 'ChannelBindings'] }, | ||
], | ||
}, | ||
methods: { | ||
ObjectElement(objectElement: ObjectElement) { | ||
// @ts-ignore | ||
const result = AlternatingVisitor.compose.methods.ObjectElement.call(this, objectElement); | ||
|
||
this.element.filter(isReferenceElement).forEach((referenceElement: ReferenceElement) => { | ||
referenceElement.setMetaProperty('referenced-element', 'channelBindings'); | ||
}); | ||
|
||
return result; | ||
}, | ||
}, | ||
}); | ||
|
||
export default BindingsVisitor; |
32 changes: 32 additions & 0 deletions
32
...ges/apidom-ns-asyncapi-2-0/src/refractor/visitors/async-api-2-0/server/BindingsVisitor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import stampit from 'stampit'; | ||
import { T as stubTrue } from 'ramda'; | ||
import { ObjectElement } from 'apidom'; | ||
|
||
import ReferenceElement from '../../../../elements/Reference'; | ||
import AlternatingVisitor from '../../generics/AlternatingVisitor'; | ||
import FallbackVisitor from '../../FallbackVisitor'; | ||
import { isReferenceLikeElement } from '../../../predicates'; | ||
import { isReferenceElement } from '../../../../predicates'; | ||
|
||
const BindingsVisitor = stampit(AlternatingVisitor, FallbackVisitor, { | ||
props: { | ||
alternator: [ | ||
{ predicate: isReferenceLikeElement, specPath: ['document', 'objects', 'Reference'] }, | ||
{ predicate: stubTrue, specPath: ['document', 'objects', 'ServerBindings'] }, | ||
], | ||
}, | ||
methods: { | ||
ObjectElement(objectElement: ObjectElement) { | ||
// @ts-ignore | ||
const result = AlternatingVisitor.compose.methods.ObjectElement.call(this, objectElement); | ||
|
||
this.element.filter(isReferenceElement).forEach((referenceElement: ReferenceElement) => { | ||
referenceElement.setMetaProperty('referenced-element', 'serverBindings'); | ||
}); | ||
|
||
return result; | ||
}, | ||
}, | ||
}); | ||
|
||
export default BindingsVisitor; |
32 changes: 32 additions & 0 deletions
32
...es/apidom-ns-asyncapi-2-0/test/refractor/elements/AsyncApi2-0/__snapshots__/index.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`refractor elements AsyncApi2_0Element should refract to semantic ApiDOM tree 1`] = ` | ||
(AsyncApi2_0Element | ||
(MemberElement | ||
(StringElement) | ||
(AsyncApiVersionElement)) | ||
(MemberElement | ||
(StringElement) | ||
(IdentifierElement)) | ||
(MemberElement | ||
(StringElement) | ||
(InfoElement)) | ||
(MemberElement | ||
(StringElement) | ||
(ServersElement)) | ||
(MemberElement | ||
(StringElement) | ||
(DefaultContentTypeElement)) | ||
(MemberElement | ||
(StringElement) | ||
(ChannelsElement)) | ||
(MemberElement | ||
(StringElement) | ||
(ComponentsElement)) | ||
(MemberElement | ||
(StringElement) | ||
(TagsElement)) | ||
(MemberElement | ||
(StringElement) | ||
(ExternalDocumentationElement))) | ||
`; |
26 changes: 26 additions & 0 deletions
26
apidom/packages/apidom-ns-asyncapi-2-0/test/refractor/elements/AsyncApi2-0/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { expect } from 'chai'; | ||
import { sexprs } from 'apidom'; | ||
|
||
import { AsyncApi2_0Element } from '../../../../src'; | ||
|
||
describe('refractor', function () { | ||
context('elements', function () { | ||
context('AsyncApi2_0Element', function () { | ||
specify('should refract to semantic ApiDOM tree', function () { | ||
const asyncApiElement = AsyncApi2_0Element.refract({ | ||
asyncapi: '2.0.0', | ||
id: 'urn:com:smartylighting:streetlights:server', | ||
info: {}, | ||
servers: {}, | ||
defaultContentType: 'application/json', | ||
channels: {}, | ||
components: {}, | ||
tags: [], | ||
externalDocs: {}, | ||
}); | ||
|
||
expect(sexprs(asyncApiElement)).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); | ||
}); |
3 changes: 3 additions & 0 deletions
3
...pidom-ns-asyncapi-2-0/test/refractor/elements/AsyncApiVersion/__snapshots__/index.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`refractor elements AsyncApiVersionElement should refract to semantic ApiDOM tree 1`] = `(AsyncApiVersionElement)`; |
16 changes: 16 additions & 0 deletions
16
apidom/packages/apidom-ns-asyncapi-2-0/test/refractor/elements/AsyncApiVersion/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { expect } from 'chai'; | ||
import { sexprs } from 'apidom'; | ||
|
||
import { AsyncApiVersionElement } from '../../../../src'; | ||
|
||
describe('refractor', function () { | ||
context('elements', function () { | ||
context('AsyncApiVersionElement', function () { | ||
specify('should refract to semantic ApiDOM tree', function () { | ||
const asyncApiVersion = AsyncApiVersionElement.refract('2.0.0'); | ||
|
||
expect(sexprs(asyncApiVersion)).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
...es/apidom-ns-asyncapi-2-0/test/refractor/elements/ChannelItem/__snapshots__/index.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`refractor elements ChannelItemElement given bindings field of type ChannelBindingsElement should refract to semantic ApiDOM tree 1`] = ` | ||
(ChannelItemElement | ||
(MemberElement | ||
(StringElement) | ||
(ChannelBindingsElement))) | ||
`; | ||
|
||
exports[`refractor elements ChannelItemElement given bindings field of type ReferenceElement should refract to semantic ApiDOM tree 1`] = ` | ||
(ChannelItemElement | ||
(MemberElement | ||
(StringElement) | ||
(ReferenceElement | ||
(MemberElement | ||
(StringElement) | ||
(StringElement))))) | ||
`; | ||
|
||
exports[`refractor elements ChannelItemElement should refract to semantic ApiDOM tree 1`] = ` | ||
(ChannelItemElement | ||
(MemberElement | ||
(StringElement) | ||
(StringElement)) | ||
(MemberElement | ||
(StringElement) | ||
(StringElement)) | ||
(MemberElement | ||
(StringElement) | ||
(OperationElement)) | ||
(MemberElement | ||
(StringElement) | ||
(OperationElement)) | ||
(MemberElement | ||
(StringElement) | ||
(ParametersElement))) | ||
`; |
44 changes: 44 additions & 0 deletions
44
apidom/packages/apidom-ns-asyncapi-2-0/test/refractor/elements/ChannelItem/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { expect } from 'chai'; | ||
import { sexprs } from 'apidom'; | ||
|
||
import { ChannelItemElement } from '../../../../src'; | ||
|
||
describe('refractor', function () { | ||
context('elements', function () { | ||
context('ChannelItemElement', function () { | ||
specify('should refract to semantic ApiDOM tree', function () { | ||
const channelItemElement = ChannelItemElement.refract({ | ||
$ref: '#/path/to/channel-item', | ||
description: 'channel-item-description', | ||
subscribe: {}, | ||
publish: {}, | ||
parameters: {}, | ||
}); | ||
|
||
expect(sexprs(channelItemElement)).toMatchSnapshot(); | ||
}); | ||
|
||
context('given bindings field of type ChannelBindingsElement', function () { | ||
specify('should refract to semantic ApiDOM tree', function () { | ||
const channelItemElement = ChannelItemElement.refract({ | ||
bindings: {}, | ||
}); | ||
|
||
expect(sexprs(channelItemElement)).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
context('given bindings field of type ReferenceElement', function () { | ||
specify('should refract to semantic ApiDOM tree', function () { | ||
const channelItemElement = ChannelItemElement.refract({ | ||
bindings: { | ||
$ref: '#/path/to/bindings', | ||
}, | ||
}); | ||
|
||
expect(sexprs(channelItemElement)).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
11 changes: 11 additions & 0 deletions
11
...kages/apidom-ns-asyncapi-2-0/test/refractor/elements/Channels/__snapshots__/index.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`refractor elements ChannelsElement should refract to semantic ApiDOM tree 1`] = ` | ||
(ChannelsElement | ||
(MemberElement | ||
(StringElement) | ||
(ChannelItemElement)) | ||
(MemberElement | ||
(StringElement) | ||
(ChannelItemElement))) | ||
`; |
19 changes: 19 additions & 0 deletions
19
apidom/packages/apidom-ns-asyncapi-2-0/test/refractor/elements/Channels/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { expect } from 'chai'; | ||
import { sexprs } from 'apidom'; | ||
|
||
import { ChannelsElement } from '../../../../src'; | ||
|
||
describe('refractor', function () { | ||
context('elements', function () { | ||
context('ChannelsElement', function () { | ||
specify('should refract to semantic ApiDOM tree', function () { | ||
const channelsElement = ChannelsElement.refract({ | ||
'user/signedup': {}, | ||
'user/loggedout': {}, | ||
}); | ||
|
||
expect(sexprs(channelsElement)).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); | ||
}); |
14 changes: 14 additions & 0 deletions
14
...ckages/apidom-ns-asyncapi-2-0/test/refractor/elements/Contact/__snapshots__/index.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`refractor elements ContactElement should refract to semantic ApiDOM tree 1`] = ` | ||
(ContactElement | ||
(MemberElement | ||
(StringElement) | ||
(StringElement)) | ||
(MemberElement | ||
(StringElement) | ||
(StringElement)) | ||
(MemberElement | ||
(StringElement) | ||
(StringElement))) | ||
`; |
20 changes: 20 additions & 0 deletions
20
apidom/packages/apidom-ns-asyncapi-2-0/test/refractor/elements/Contact/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { expect } from 'chai'; | ||
import { sexprs } from 'apidom'; | ||
|
||
import { ContactElement } from '../../../../src'; | ||
|
||
describe('refractor', function () { | ||
context('elements', function () { | ||
context('ContactElement', function () { | ||
specify('should refract to semantic ApiDOM tree', function () { | ||
const contactElement = ContactElement.refract({ | ||
name: 'API Support', | ||
url: 'http://www.asyncapi.org/support', | ||
email: '[email protected]', | ||
}); | ||
|
||
expect(sexprs(contactElement)).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); | ||
}); |
3 changes: 3 additions & 0 deletions
3
...om-ns-asyncapi-2-0/test/refractor/elements/DefaultContentType/__snapshots__/index.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`refractor elements DefaultContentTypeElement should refract to semantic ApiDOM tree 1`] = `(DefaultContentTypeElement)`; |
16 changes: 16 additions & 0 deletions
16
apidom/packages/apidom-ns-asyncapi-2-0/test/refractor/elements/DefaultContentType/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { expect } from 'chai'; | ||
import { sexprs } from 'apidom'; | ||
|
||
import { DefaultContentTypeElement } from '../../../../src'; | ||
|
||
describe('refractor', function () { | ||
context('elements', function () { | ||
context('DefaultContentTypeElement', function () { | ||
specify('should refract to semantic ApiDOM tree', function () { | ||
const defaultContentTypeElement = DefaultContentTypeElement.refract('application/json'); | ||
|
||
expect(sexprs(defaultContentTypeElement)).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); | ||
}); |
3 changes: 3 additions & 0 deletions
3
...ges/apidom-ns-asyncapi-2-0/test/refractor/elements/Identifier/__snapshots__/index.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`refractor elements IdentifierElement should refract to semantic ApiDOM tree 1`] = `(IdentifierElement)`; |
18 changes: 18 additions & 0 deletions
18
apidom/packages/apidom-ns-asyncapi-2-0/test/refractor/elements/Identifier/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { expect } from 'chai'; | ||
import { sexprs } from 'apidom'; | ||
|
||
import { IdentifierElement } from '../../../../src'; | ||
|
||
describe('refractor', function () { | ||
context('elements', function () { | ||
context('IdentifierElement', function () { | ||
specify('should refract to semantic ApiDOM tree', function () { | ||
const identifierElement = IdentifierElement.refract( | ||
'urn:com:smartylighting:streetlights:server', | ||
); | ||
|
||
expect(sexprs(identifierElement)).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.