add test object services #1505

This commit is contained in:
baozhoutao 2021-02-26 12:07:52 +08:00
parent fa152ee5fd
commit 71e2392bd1
5 changed files with 37 additions and 1 deletions

1
.gitignore vendored
View File

@ -46,3 +46,4 @@ packages/project-template-empty/.env.local
apps/contracts/src/_test/**
packages/accounts/webapp/build/**
packages/react/.env.local
services/service-metadata-objects/.env.local

View File

@ -0,0 +1 @@
TRANSPORTER=redis://localhost:6379

View File

@ -103,7 +103,6 @@ module.exports = {
// Define a cacher.
// More info: https://moleculer.services/docs/0.14/caching.html
cacher: "redis://192.168.3.17:6379",
// Define a serializer.
// Available values: "JSON", "Avro", "ProtoBuf", "MsgPack", "Notepack", "Thrift".

View File

@ -9,6 +9,7 @@
"cli": "moleculer connect redis://192.168.3.17:6379",
"ci": "jest --watch",
"test": "jest --coverage",
"testObject": "node test/object.services.js",
"lint": "eslint services",
"dc:up": "docker-compose up --build -d",
"dc:logs": "docker-compose logs -f",

View File

@ -0,0 +1,34 @@
const { ServiceBroker } = require("moleculer");
require('dotenv-flow').config(process.cwd());
const broker = new ServiceBroker({
namespace: "steedos",
nodeID: "$test",
logLevel: "debug",
requestTimeout: 5 * 1000,
preferLocal: false,
transporter: process.env.TRANSPORTER,
});
broker.createService({
name: "ObjectFind",
settings: {
},
events: {
"#accounts.created"(ctx) {
broker.call("#accounts.find", {query: {filters: ['_id', '=', ctx.params.recordId]}}).then(res => console.log(ctx.eventName, res));
},
"#accounts.updated"(ctx) {
broker.call("#accounts.find", {query: {filters: ['_id', '=', ctx.params.recordId]}}).then(res => console.log(ctx.eventName, res));
},
"#accounts.deleted"(ctx) {
console.log("#accounts.deleted ctx:", ctx);
}
},
})
broker.start().then((a, b, c, d) => {
broker.repl();
}, 5000)