@asyncapi/cupid
Advanced tools
Comparing version 0.6.15 to 0.6.16
@@ -9,5 +9,6 @@ const parser = require('@asyncapi/parser'); | ||
*/ | ||
function validate(asyncApiDocs) { | ||
return Promise.all(asyncApiDocs.map(async doc => { | ||
if (doc && doc['x-parser-spec-parsed'] === true) { | ||
if (typeof doc === 'object' && typeof doc.ext === 'function' && doc.ext('x-parser-spec-parsed')) { | ||
return doc; | ||
@@ -14,0 +15,0 @@ } |
{ | ||
"name": "@asyncapi/cupid", | ||
"version": "0.6.15", | ||
"version": "0.6.16", | ||
"description": "A library that focuses on finding and analyzing the relationships between AsyncAPI Documents too later output consolidated information about the system architecture. Output format should be customizable and available in different formats like uml, mermaid.js and other.", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -8,3 +8,3 @@ const chai = require('chai'); | ||
const {getRelations} = require('../lib/appRelationsDiscovery'); | ||
const {getAsyncApiExamples} = require('./testsUtil'); | ||
const {getAsyncApiExamples,parseAsyncApiExamples} = require('./testsUtil'); | ||
@@ -23,11 +23,17 @@ const outputMermaid = 'graph TD\n server1[(mqtt://localhost:1883)]\nFlightMonitorService[Flight Monitor Service]\nFlightMonitorService -- flight/update --> server1\nFlightNotifierService[Flight Notifier Service]\nserver1 -- flight/update --> FlightNotifierService\nFlightSubscriberService[Flight Subscriber Service]\nFlightSubscriberService -- flight/queue --> server1\nserver1 -- flight/queue --> FlightMonitorService'; | ||
let slugOutput; | ||
let parsedSlugOutput; | ||
let output; | ||
let correctChannelUpdate; | ||
let correctChannelQueue; | ||
let parsedDocs; | ||
let parsedOutput; | ||
before(async function() { | ||
flightServiceDocs = getAsyncApiExamples(); | ||
parsedDocs = await parseAsyncApiExamples(flightServiceDocs); | ||
output = await getRelations(flightServiceDocs); | ||
parsedOutput = await getRelations(parsedDocs); | ||
correctSlug = 'mqtt://localhost:1883,mqtt'; | ||
slugOutput = output.get(correctSlug); | ||
parsedSlugOutput = parsedOutput.get(correctSlug); | ||
correctChannelUpdate = 'flight/update'; | ||
@@ -38,2 +44,3 @@ correctChannelQueue = 'flight/queue'; | ||
expect(output).to.have.key(correctSlug); | ||
expect(parsedOutput).to.have.key(correctSlug); | ||
}); | ||
@@ -43,2 +50,3 @@ | ||
expect(slugOutput).to.have.all.keys(correctChannelUpdate, correctChannelQueue); | ||
expect(parsedSlugOutput).to.have.all.keys(correctChannelUpdate, correctChannelQueue); | ||
}); | ||
@@ -48,4 +56,6 @@ | ||
const updateChannelOutput = slugOutput.get(correctChannelUpdate); | ||
const updateChannelParsedOutput = parsedSlugOutput.get(correctChannelUpdate); | ||
const correctSubOperation = 'Flight Monitor Service'; | ||
expect(updateChannelOutput.sub.get(correctSubOperation)).to.deep.equal(flightUpdateSubData.get(correctSubOperation)); | ||
expect(updateChannelParsedOutput.sub.get(correctSubOperation)).to.deep.equal(flightUpdateSubData.get(correctSubOperation)); | ||
}); | ||
@@ -55,4 +65,6 @@ | ||
const updateChannelOutput = slugOutput.get(correctChannelUpdate); | ||
const updateChannelParsedOutput = parsedSlugOutput.get(correctChannelUpdate); | ||
const correctPubOperation = 'Flight Notifier Service'; | ||
expect(updateChannelOutput.pub.get(correctPubOperation)).to.deep.equal(flightUpdatePubData.get(correctPubOperation)); | ||
expect(updateChannelParsedOutput.pub.get(correctPubOperation)).to.deep.equal(flightUpdatePubData.get(correctPubOperation)); | ||
}); | ||
@@ -62,4 +74,6 @@ | ||
const queueChannelOutput = slugOutput.get(correctChannelQueue); | ||
const queueChannelParsedOutput = parsedSlugOutput.get(correctChannelQueue); | ||
const correctSubOperation = 'Flight Subscriber Service'; | ||
expect(queueChannelOutput.sub.get(correctSubOperation)).to.deep.equal(flightQueueSubData.get(correctSubOperation)); | ||
expect(queueChannelParsedOutput.sub.get(correctSubOperation)).to.deep.equal(flightQueueSubData.get(correctSubOperation)); | ||
}); | ||
@@ -69,20 +83,28 @@ | ||
const queueChannelOutput = slugOutput.get(correctChannelQueue); | ||
const queueChannelParsedOutput = parsedSlugOutput.get(correctChannelQueue); | ||
const correctPubOperation = 'Flight Monitor Service'; | ||
expect(queueChannelOutput.pub.get(correctPubOperation)).to.deep.equal(flightQueuePubData.get(correctPubOperation)); | ||
expect(queueChannelParsedOutput.pub.get(correctPubOperation)).to.deep.equal(flightQueuePubData.get(correctPubOperation)); | ||
}); | ||
it('should return the correct mermaid syntax', async function() { | ||
const output = await getRelations(flightServiceDocs,{syntax: 'mermaid'}); | ||
expect(output).to.be.equal(outputMermaid); | ||
const testOutput = await getRelations(flightServiceDocs,{syntax: 'mermaid'}); | ||
const testParsedOutput = await getRelations(parsedDocs,{syntax: 'mermaid'}); | ||
expect(testOutput).to.be.equal(outputMermaid); | ||
expect(testParsedOutput).to.be.equal(outputMermaid); | ||
}); | ||
it('should return the correct plantUML syntax', async function() { | ||
const output = await getRelations(flightServiceDocs,{syntax: 'plantUML'}); | ||
expect(output).to.be.equal(outputPlantUML); | ||
const testOutput = await getRelations(flightServiceDocs,{syntax: 'plantUML'}); | ||
const testParsedOutput = await getRelations(parsedDocs,{syntax: 'plantUML'}); | ||
expect(testOutput).to.be.equal(outputPlantUML); | ||
expect(testParsedOutput).to.be.equal(outputPlantUML); | ||
}); | ||
it('should return the correct reactFlow elements array', async function() { | ||
const output = await getRelations(flightServiceDocs,{syntax: 'reactFlow'}); | ||
expect(output).to.be.deep.equal(outputReactFlow); | ||
const testOutput = await getRelations(flightServiceDocs,{syntax: 'reactFlow'}); | ||
const testParsedOutput = await getRelations(parsedDocs,{syntax: 'reactFlow'}); | ||
expect(testOutput).to.be.deep.equal(outputReactFlow); | ||
expect(testParsedOutput).to.be.deep.equal(outputReactFlow); | ||
}); | ||
}); |
const path = require('path'); | ||
const fs = require('fs'); | ||
const parser = require('@asyncapi/parser'); | ||
const examplesPath = './test/examples/flightService'; | ||
async function parseAsyncApiExamples(asyncApiDocs) { | ||
const docs = []; | ||
for (const doc of asyncApiDocs) { | ||
const parsedDoc = await parser.parse(doc); | ||
docs.push(parsedDoc); | ||
} | ||
return docs; | ||
} | ||
function getAsyncApiExamples() { | ||
@@ -17,2 +27,2 @@ const docs = []; | ||
module.exports = {getAsyncApiExamples}; | ||
module.exports = {getAsyncApiExamples,parseAsyncApiExamples}; |
Sorry, the diff of this file is not supported yet
833683
53
358