@gluestack-v2/glue-plugin-service-gateway
Version:
Gluestack V2 service Gateway Plugin
43 lines (30 loc) • 1.04 kB
JavaScript
;
const { ServiceBroker } = require("moleculer");
const { ValidationError } = require("moleculer").Errors;
const TestService = require("../../../services/greeter.service");
describe("Test 'greeter' service", () => {
let broker = new ServiceBroker({ logger: false });
broker.createService(TestService);
beforeAll(() => broker.start());
afterAll(() => broker.stop());
describe("Test 'greeter.hello' action", () => {
it("should return with 'Hello Moleculer'", async () => {
const res = await broker.call("greeter.hello");
expect(res).toBe("Hello Moleculer");
});
});
describe("Test 'greeter.welcome' action", () => {
it("should return with 'Welcome'", async () => {
const res = await broker.call("greeter.welcome", { name: "Adam" });
expect(res).toBe("Welcome, Adam");
});
it("should reject an ValidationError", async () => {
expect.assertions(1);
try {
await broker.call("greeter.welcome");
} catch(err) {
expect(err).toBeInstanceOf(ValidationError);
}
});
});
});