Skip to content

Commit

Permalink
fix: connect all types of endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
arlac77 committed Nov 16, 2019
1 parent 81c9d82 commit cab7dbf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 24 deletions.
22 changes: 10 additions & 12 deletions src/endpoints-mixin.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
isEndpoint,
SendEndpoint,
SendEndpointDefault,
ReceiveEndpoint,
Expand Down Expand Up @@ -129,18 +130,15 @@ export default function EndpointsMixin(superclass) {
* @param {Boolean} throwOnError raise exception if connection can´t be established
*/
connectEndpoint(ep, definition, old, throwOnError) {
if (ep.isOut) {
const target = definition.target;

if (target !== undefined) {
ep.connected =
target instanceof ReceiveEndpoint
? target
: this.endpointForExpression(target, false, throwOnError);
} else {
if (old && old.connected) {
ep.connected = old.connected;
}
const connected = definition.connected;

if (connected !== undefined) {
ep.connected = isEndpoint(connected)
? connected
: this.endpointForExpression(connected, false, throwOnError);
} else {
if (old && old.connected) {
ep.connected = old.connected;
}
}

Expand Down
10 changes: 4 additions & 6 deletions src/service.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import events from "events";
import safeStringify from "fast-safe-stringify";

import {
ReceiveEndpoint
} from "@kronos-integration/endpoint";
import { ReceiveEndpoint } from "@kronos-integration/endpoint";

import {
defaultLogLevels,
Expand Down Expand Up @@ -165,8 +163,8 @@ export default class Service extends EndpointsMixin(
log: {
out: true,
default: true,
// target: 'service(logger).log'
target: dummyLogReceiver
// connected: 'service(logger).log'
connected: dummyLogReceiver
},
config: {
in: true,
Expand Down Expand Up @@ -368,7 +366,7 @@ export default class Service extends EndpointsMixin(
const ep = this.endpoints[endpointName];

function add(ep) {
if(json.endpoints === undefined) {
if (json.endpoints === undefined) {
json.endpoints = {};
}
json.endpoints[endpointName] = ep.toJSON();
Expand Down
12 changes: 6 additions & 6 deletions tests/endpoint-mixin-test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,24 @@ test("endpointForExpression throwing", t => {
t.is(error.message, "Endpoint 'r2' not found in owner");
});

test("endpointFromConfig simple target", t => {
test("endpointFromConfig simple connected", t => {
const o = new Owner();

const r1 = new ReceiveEndpoint("r1");
o.addEndpoint(r1);

const e = o.createEndpointFromConfig("e", { target: "r1" }, o);
const e = o.createEndpointFromConfig("e", { connected: "r1" }, o);

t.is(e.name, "e");
t.is(e.connected.name, "r1");
});

test("endpointFromConfig foreign target", t => {
test("endpointFromConfig foreign connected", t => {
const o = new Owner();

const e = o.createEndpointFromConfig(
"e",
{ target: "service(logger).log" },
{ connected: "service(logger).log" },
o
);

Expand All @@ -103,7 +103,7 @@ test("endpointFromConfig foreign target", t => {
t.is(e.connected.owner.name, "logger");
});

test("endpointFromConfig real target", t => {
test("endpointFromConfig real connected", t => {
const dummyLogReceiver = new ReceiveEndpoint("log", {
endpointIdentifier(ep) {
return undefined; // prevent target;
Expand All @@ -118,7 +118,7 @@ test("endpointFromConfig real target", t => {

const e = o.createEndpointFromConfig(
"e",
{ target: dummyLogReceiver },
{ connected: dummyLogReceiver },
o
);

Expand Down

0 comments on commit cab7dbf

Please sign in to comment.