Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
expect(res).toEqual({
subscribe: [expect.any(Function), expect.any(Function)],
resolve: expect.any(Function),
});
// Test first function
expect(res.subscribe[0]()).toBe("iterator-result");
expect(svc.pubsub.asyncIterator).toBeCalledTimes(1);
expect(svc.pubsub.asyncIterator).toBeCalledWith(["a", "b"]);
// Test second function without payload
expect(await res.subscribe[1]()).toBe(false);
// Test second function with payload
const ctx = new Context(broker);
expect(await res.subscribe[1]({ a: 5 }, { b: "John" }, ctx)).toBe("action response");
expect(broker.call).toBeCalledTimes(1);
expect(broker.call).toBeCalledWith(
"posts.filter",
{ b: "John", payload: { a: 5 } },
ctx
);
});
});
const res = svc.createAsyncIteratorResolver("posts.find");
expect(res).toEqual({
subscribe: expect.any(Function),
resolve: expect.any(Function),
});
// Test subscribe
const res2 = res.subscribe();
expect(res2).toBe("iterator-result");
expect(svc.pubsub.asyncIterator).toBeCalledTimes(1);
expect(svc.pubsub.asyncIterator).toBeCalledWith([]);
// Test resolve
const ctx = new Context(broker);
const res3 = await res.resolve({ a: 5 }, { b: "John" }, ctx);
expect(res3).toBe("action response");
expect(broker.call).toBeCalledTimes(1);
expect(broker.call).toBeCalledWith("posts.find", { b: "John", payload: { a: 5 } }, ctx);
});
export const getCall = (data: object) => {
const ctx = Context.create(broker, endpoint, data);
// eslint-disable-next-line
ctx.call = jest.fn(async () => (broker.Promise as any).resolve({}));
return ctx;
};
}
"use strict";
const { ServiceBroker } = require("moleculer");
const StoreService = require("../../../moleculer-db/index");
const ModuleChecker = require("../../../moleculer-db/test/checker");
const SequelizeAdapter = require("../../index");
const Sequelize = require("sequelize");
const Op = Sequelize.Op;
process.on("warning", e => console.warn(e.stack));
// Create broker
const broker = new ServiceBroker({
logger: console,
logLevel: "debug"
});
let adapter;
// Load my service
broker.createService(StoreService, {
name: "posts",
adapter: new SequelizeAdapter("sqlite://:memory:"),
model: {
name: "post",
define: {
title: Sequelize.STRING,
content: Sequelize.TEXT,
votes: Sequelize.INTEGER,
author: Sequelize.INTEGER,
init(broker, service) {
this.broker = broker;
this.service = service;
if (this.service.schema.model) {
this.model = this.service.schema.model;
} else if (this.service.schema.schema) {
if (!this.service.schema.modelName) {
throw new ServiceSchemaError("`modelName` is required when `schema` is given in schema of service!");
}
this.schema = this.service.schema.schema;
this.modelName = this.service.schema.modelName;
}
if (!this.model && !this.schema) {
/* istanbul ignore next */
throw new ServiceSchemaError("Missing `model` or `schema` definition in schema of service!");
}
}
init(broker, service) {
this.broker = broker;
this.service = service;
if (!this.service.schema.collection) {
/* istanbul ignore next */
throw new ServiceSchemaError("Missing `collection` definition in schema of service!");
}
}
init(broker, service) {
this.broker = broker;
this.service = service;
if (!this.service.schema.model) {
/* istanbul ignore next */
throw new ServiceSchemaError("Missing `model` definition in schema of service!");
}
}
if (param.default) {
return param.name + " = " + param.default;
}
return param.name + "?";
}
return param.name;
}
if (param.type && param.type.name)
return param.name + ": " + param.type.name.replace(/\n/g, "");
return param.name;
}
// Read package.json to get API version number
const pkg = require("moleculer/package.json");
const apiVersion = semver.major(pkg.version) + "." + semver.minor(pkg.version);
console.log("API version:", apiVersion);
// Source files for API docs
const sourceFiles = [
{ path: "service-broker.js", name: "ServiceBroker" },
{ path: "service.js", name: "Service" },
{ path: "context.js", name: "Context" }
]
// Target folder
const targetFolder = path.join(".", "source", "docs", apiVersion, "api");
console.log("Target folder:", targetFolder);
mkdir(targetFolder);
// Template
const templateFolder = path.join(__dirname, "api-template", "md");
"use strict";
const { ServiceBroker } = require("moleculer");
const { MoleculerError } = require("moleculer").Errors;
const JaegerService = require("../../index");
const ApiGateway = require("moleculer-web");
const THROW_ERR = true;
// Create broker
const broker = new ServiceBroker({
logger: console,
logLevel: "debug",
metrics: true,
sampleCount: 1
});
broker.createService(ApiGateway);
// Load Jaeger service
broker.createService({
mixins: [JaegerService],
settings: {
host: "192.168.0.181"
}
});
"use strict";
const { ServiceBroker } = require("moleculer");
const { MoleculerClientError } = require("moleculer").Errors;
const ApiGateway = require("moleculer-web");
const { ApolloService } = require("../../index");
const broker = new ServiceBroker({ logLevel: "info", hotReload: true });
broker.createService({
name: "api",
mixins: [
// Gateway
ApiGateway,
// GraphQL Apollo Server
ApolloService({
// API Gateway route options
routeOptions: {
path: "/graphql",
cors: true,
mappingPolicy: "restrict",
},