Skip to content

Commit

Permalink
test(ns-asyncapi-2-0): add tests using S-expressions snapshots
Browse files Browse the repository at this point in the history
These tests specifically target refracting stage.
This is bunch #1 of the tests.

Refs #434
  • Loading branch information
char0n committed Jun 2, 2021
1 parent 5d7d068 commit 69d435c
Show file tree
Hide file tree
Showing 33 changed files with 727 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import ServerUrlVisitor from './visitors/async-api-2-0/server/UrlVisitor';
import ServerProtocolVisitor from './visitors/async-api-2-0/server/ProtocolVisitor';
import ServerProtocolVersionVisitor from './visitors/async-api-2-0/server/ProtocolVersionVisitor';
import ServerDescriptionVisitor from './visitors/async-api-2-0/server/DescriptionVisitor';
import ServerBindingsVisitor_ from './visitors/async-api-2-0/server/BindingsVisitor';
import ServerVariablesVisitor from './visitors/async-api-2-0/server/VariablesVisitor';
import ServerSecurityVisitor from './visitors/async-api-2-0/server/SecurityVisitor';
import ServerVariableVisitor from './visitors/async-api-2-0/server-variable';
Expand Down Expand Up @@ -89,6 +90,7 @@ import ChannelBindingsVisitor from './visitors/async-api-2-0/channel-bindings';
import ChannelItemVisitor from './visitors/async-api-2-0/channel-item';
import ChannelItem$RefVisitor from './visitors/async-api-2-0/channel-item/$RefVisitor';
import ChannelItemDescriptionVisitor from './visitors/async-api-2-0/channel-item/DescriptionVisitor';
import ChannelItemBindingsVisitor from './visitors/async-api-2-0/channel-item/BindingsVisitor';
import MessageBindingsVisitor from './visitors/async-api-2-0/message-bindings';
import MessageTraitVisitor from './visitors/async-api-2-0/message-trait';
import MessageTraitHeadersVisitor from './visitors/async-api-2-0/message-trait/HeadersVisitor';
Expand Down Expand Up @@ -325,9 +327,7 @@ const specification = {
description: ServerDescriptionVisitor,
variables: ServerVariablesVisitor,
security: ServerSecurityVisitor,
bindings: {
$ref: '#/visitors/document/objects/ServerBindings',
},
bindings: ServerBindingsVisitor_,
},
},
ServerVariable: {
Expand Down Expand Up @@ -359,9 +359,7 @@ const specification = {
parameters: {
$ref: '#/visitors/document/objects/Parameters',
},
bindings: {
$ref: '#/visitors/document/objects/ChannelBindings',
},
bindings: ChannelItemBindingsVisitor,
},
},
Operation: {
Expand Down
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;
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;
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)))
`;
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();
});
});
});
});
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)`;
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();
});
});
});
});
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)))
`;
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();
});
});
});
});
});
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)))
`;
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();
});
});
});
});
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)))
`;
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();
});
});
});
});
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)`;
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();
});
});
});
});
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)`;
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();
});
});
});
});
Loading

0 comments on commit 69d435c

Please sign in to comment.