• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

moleculerjs / database / #178

12 Nov 2023 04:51PM UTC coverage: 38.137% (-56.5%) from 94.594%
#178

push

icebob
Fix #53

690 of 1512 branches covered (0.0%)

Branch coverage included in aggregate %.

44 of 45 new or added lines in 2 files covered. (97.78%)

2662 existing lines in 19 files now uncovered.

1517 of 4275 relevant lines covered (35.49%)

50.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

6.12
/test/integration/transform.test.js
1
"use strict";
2

3
const { ServiceBroker, Context } = require("moleculer");
1✔
4
const DbService = require("../..").Service;
1✔
5

6
module.exports = (getAdapter, adapterType) => {
1✔
7
        let expectedID;
UNCOV
8
        if (["Knex"].includes(adapterType)) {
×
UNCOV
9
                expectedID = expect.any(Number);
×
10
        } else {
UNCOV
11
                expectedID = expect.any(String);
×
12
        }
13

UNCOV
14
        describe("Test transformations", () => {
×
UNCOV
15
                const broker = new ServiceBroker({ logger: false });
×
UNCOV
16
                const svc = broker.createService({
×
17
                        name: "users",
18
                        mixins: [
19
                                DbService({
20
                                        adapter: getAdapter()
21
                                })
22
                        ],
23
                        settings: {
24
                                fields: {
25
                                        myID: {
26
                                                type: "string",
27
                                                primaryKey: true,
28
                                                columnName: "_id",
29
                                                columnType: "integer"
30
                                        },
31
                                        name: { type: "string" },
32
                                        upperName: {
33
                                                type: "string",
34
                                                readonly: true,
35
                                                virtual: true,
UNCOV
36
                                                get: ({ entity }) => (entity.name ? entity.name.toUpperCase() : entity.name)
×
37
                                        },
38
                                        password: { type: "string", hidden: true },
39
                                        token: { type: "string", hidden: "byDefault" },
40
                                        email: { type: "string", readPermission: "admin" },
41
                                        phone: { type: "string", permission: "admin" }
42
                                }
43
                        },
44

45
                        async started() {
UNCOV
46
                                const adapter = await this.getAdapter();
×
47

UNCOV
48
                                if (adapterType == "Knex") {
×
UNCOV
49
                                        await adapter.createTable();
×
50
                                }
51

UNCOV
52
                                await this.clearEntities();
×
53
                        }
54
                });
55

UNCOV
56
                beforeAll(() => broker.start());
×
UNCOV
57
                afterAll(() => broker.stop());
×
58

UNCOV
59
                const ctx = Context.create(broker, null, {});
×
UNCOV
60
                const docs = {};
×
61

UNCOV
62
                describe("Set up", () => {
×
UNCOV
63
                        it("should return empty array", async () => {
×
UNCOV
64
                                await svc.clearEntities();
×
65

UNCOV
66
                                const rows = await svc.findEntities(ctx);
×
UNCOV
67
                                expect(rows).toEqual([]);
×
68

UNCOV
69
                                const count = await svc.countEntities(ctx);
×
UNCOV
70
                                expect(count).toEqual(0);
×
71
                        });
72
                });
73

UNCOV
74
                describe("Test hidden fields, getter, readPermission", () => {
×
UNCOV
75
                        it("create test entity", async () => {
×
UNCOV
76
                                const res = await svc.createEntity(ctx, {
×
77
                                        name: "John Doe",
78
                                        upperName: "Nothing",
79
                                        email: "john.doe@moleculer.services",
80
                                        phone: "+1-555-1234",
81
                                        password: "johnDoe1234",
82
                                        token: "token1234"
83
                                });
UNCOV
84
                                docs.johnDoe = res;
×
85

UNCOV
86
                                expect(res).toEqual({
×
87
                                        myID: expectedID,
88
                                        name: "John Doe",
89
                                        upperName: "JOHN DOE",
90
                                        email: "john.doe@moleculer.services",
91
                                        phone: "+1-555-1234"
92
                                });
93
                        });
94

UNCOV
95
                        it("should hide e-mail address", async () => {
×
UNCOV
96
                                svc.checkFieldAuthority = jest.fn(async () => false);
×
UNCOV
97
                                const res = await svc.resolveEntities(ctx, { myID: docs.johnDoe.myID });
×
UNCOV
98
                                expect(res).toEqual({
×
99
                                        myID: expectedID,
100
                                        name: "John Doe",
101
                                        upperName: "JOHN DOE"
102
                                });
103
                        });
104

UNCOV
105
                        it("should not transform the entity", async () => {
×
UNCOV
106
                                const res = await svc.resolveEntities(
×
107
                                        ctx,
108
                                        { myID: docs.johnDoe.myID },
109
                                        { transform: false }
110
                                );
UNCOV
111
                                expect(res).toEqual({
×
112
                                        _id: expect.anything(),
113
                                        name: "John Doe",
114
                                        email: "john.doe@moleculer.services",
115
                                        phone: "+1-555-1234",
116
                                        password: "johnDoe1234",
117
                                        token: "token1234"
118
                                });
119
                        });
120

UNCOV
121
                        it("should filter fields", async () => {
×
UNCOV
122
                                const res = await svc.resolveEntities(ctx, {
×
123
                                        myID: docs.johnDoe.myID,
124
                                        fields: ["upperName", "asdasdasd", "password", "email", "token"]
125
                                });
UNCOV
126
                                expect(res).toEqual({
×
127
                                        upperName: "JOHN DOE",
128
                                        token: "token1234"
129
                                });
130
                        });
131

UNCOV
132
                        it("should filter all fields", async () => {
×
UNCOV
133
                                const res = await svc.resolveEntities(ctx, {
×
134
                                        myID: docs.johnDoe.myID,
135
                                        fields: []
136
                                });
UNCOV
137
                                expect(res).toEqual({});
×
138
                        });
139
                });
140
        });
141
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc