From f682ed2bd458c47beb42b72de291f9588d3f6939 Mon Sep 17 00:00:00 2001 From: Markus Felten Date: Wed, 2 Sep 2020 20:34:07 +0200 Subject: [PATCH] test: push service updates --- tests/admin-test.mjs | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/tests/admin-test.mjs b/tests/admin-test.mjs index f0bcff6c..eb74c0e6 100644 --- a/tests/admin-test.mjs +++ b/tests/admin-test.mjs @@ -1,5 +1,8 @@ import test from "ava"; -import { StandaloneServiceProvider } from "@kronos-integration/service"; +import { + StandaloneServiceProvider, + Service +} from "@kronos-integration/service"; import { ServiceAdmin } from "@kronos-integration/service-admin"; const config = { @@ -78,3 +81,41 @@ test("service-admin service entpoint", async t => { } }); }); + +test("service-admin push from services endpoint", async t => { + const sp = new StandaloneServiceProvider(); + await sp.declareServices({ + admin: { + type: ServiceAdmin + }, + test: { + type: Service, + endpoints: { + test: "service(admin).services" + } + } + }); + + const admin = sp.services.admin; + const ts = sp.services.test; + + const updates = []; + ts.endpoints.test.receive = update => { + update = JSON.parse(JSON.stringify(update)); + + updates.push(update); + }; + + t.is(ts.name, "test"); + + await admin.start(); + t.is(admin.state, "running"); + + await ts.start(); + + t.is(updates.length, 4); + + t.is(updates[2].test.state, "stopped"); + t.is(updates[3].test.state, "starting"); + //console.log(updates); +});