mongodb-dynamic-api 3.2.1 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +69 -0
- package/README.md +36 -3
- package/package.json +5 -2
- package/src/adapters/socket-adapter.d.ts +4 -3
- package/src/adapters/socket-adapter.js +8 -1
- package/src/adapters/socket-adapter.js.map +1 -1
- package/src/builders/route-decorators/auth-decorators.builder.d.ts +1 -1
- package/src/builders/route-decorators/route-decorators.builder.d.ts +1 -1
- package/src/builders/route-decorators/route-decorators.builder.js.map +1 -1
- package/src/decorators/validator-pipe.decorator.js.map +1 -1
- package/src/dynamic-api.module.js +13 -8
- package/src/dynamic-api.module.js.map +1 -1
- package/src/gateways/base.gateway.js +10 -2
- package/src/gateways/base.gateway.js.map +1 -1
- package/src/gateways/dynamic-api-broadcast.gateway.d.ts +13 -1
- package/src/gateways/dynamic-api-broadcast.gateway.js +32 -0
- package/src/gateways/dynamic-api-broadcast.gateway.js.map +1 -1
- package/src/guards/jwt-socket.guard.js +1 -1
- package/src/guards/jwt-socket.guard.js.map +1 -1
- package/src/helpers/index.d.ts +1 -0
- package/src/helpers/index.js +1 -0
- package/src/helpers/index.js.map +1 -1
- package/src/helpers/resolve-rooms.helper.d.ts +3 -0
- package/src/helpers/resolve-rooms.helper.js +18 -0
- package/src/helpers/resolve-rooms.helper.js.map +1 -0
- package/src/helpers/swagger-config.helper.js.map +1 -1
- package/src/interceptors/dynamic-api-cache.interceptor.d.ts +3 -2
- package/src/interceptors/dynamic-api-cache.interceptor.js +4 -0
- package/src/interceptors/dynamic-api-cache.interceptor.js.map +1 -1
- package/src/interfaces/dynamic-api-ability.interface.d.ts +2 -1
- package/src/interfaces/dynamic-api-broadcast-config.interface.d.ts +2 -1
- package/src/interfaces/dynamic-api-decorator-builder.interface.d.ts +1 -1
- package/src/interfaces/dynamic-api-global-state.interface.d.ts +3 -0
- package/src/interfaces/dynamic-api-swagger-options.type.d.ts +1 -1
- package/src/modules/auth/auth-broadcast.helper.d.ts +3 -0
- package/src/modules/auth/auth-broadcast.helper.js +11 -0
- package/src/modules/auth/auth-broadcast.helper.js.map +1 -0
- package/src/modules/auth/auth-events.constants.d.ts +13 -0
- package/src/modules/auth/auth-events.constants.js +28 -0
- package/src/modules/auth/auth-events.constants.js.map +1 -0
- package/src/modules/auth/auth.helper.d.ts +20 -6
- package/src/modules/auth/auth.helper.js +34 -10
- package/src/modules/auth/auth.helper.js.map +1 -1
- package/src/modules/auth/auth.module.d.ts +5 -2
- package/src/modules/auth/auth.module.js +46 -7
- package/src/modules/auth/auth.module.js.map +1 -1
- package/src/modules/auth/guards/index.d.ts +2 -0
- package/src/modules/auth/guards/index.js +2 -0
- package/src/modules/auth/guards/index.js.map +1 -1
- package/src/modules/auth/guards/jwt-refresh/jwt-refresh.guard.d.ts +4 -0
- package/src/modules/auth/guards/jwt-refresh/jwt-refresh.guard.js +18 -0
- package/src/modules/auth/guards/jwt-refresh/jwt-refresh.guard.js.map +1 -0
- package/src/modules/auth/guards/jwt-socket-auth/jwt-socket-auth.guard.js +1 -1
- package/src/modules/auth/guards/jwt-socket-auth/jwt-socket-auth.guard.js.map +1 -1
- package/src/modules/auth/guards/jwt-socket-refresh/jwt-socket-refresh.guard.d.ts +8 -0
- package/src/modules/auth/guards/jwt-socket-refresh/jwt-socket-refresh.guard.js +62 -0
- package/src/modules/auth/guards/jwt-socket-refresh/jwt-socket-refresh.guard.js.map +1 -0
- package/src/modules/auth/index.d.ts +2 -0
- package/src/modules/auth/index.js +2 -0
- package/src/modules/auth/index.js.map +1 -1
- package/src/modules/auth/interfaces/auth-controller.interface.d.ts +19 -4
- package/src/modules/auth/interfaces/auth-gateway.interface.d.ts +2 -0
- package/src/modules/auth/interfaces/auth-options.interface.d.ts +23 -2
- package/src/modules/auth/interfaces/auth-service.interface.d.ts +3 -0
- package/src/modules/auth/mixins/auth-controller.mixin.d.ts +2 -2
- package/src/modules/auth/mixins/auth-controller.mixin.js +114 -18
- package/src/modules/auth/mixins/auth-controller.mixin.js.map +1 -1
- package/src/modules/auth/mixins/auth-gateway.mixin.d.ts +2 -2
- package/src/modules/auth/mixins/auth-gateway.mixin.js +65 -31
- package/src/modules/auth/mixins/auth-gateway.mixin.js.map +1 -1
- package/src/modules/auth/services/base-auth.service.d.ts +9 -0
- package/src/modules/auth/services/base-auth.service.js +74 -15
- package/src/modules/auth/services/base-auth.service.js.map +1 -1
- package/src/modules/auth/strategies/index.d.ts +1 -0
- package/src/modules/auth/strategies/index.js +1 -0
- package/src/modules/auth/strategies/index.js.map +1 -1
- package/src/modules/auth/strategies/jwt-refresh.strategy.d.ts +14 -0
- package/src/modules/auth/strategies/jwt-refresh.strategy.js +45 -0
- package/src/modules/auth/strategies/jwt-refresh.strategy.js.map +1 -0
- package/src/modules/auth/strategies/jwt.strategy.d.ts +3 -1
- package/src/modules/auth/strategies/jwt.strategy.js.map +1 -1
- package/src/routes/aggregate/base-aggregate.service.js.map +1 -1
- package/src/routes/create-many/base-create-many.service.js.map +1 -1
- package/src/routes/create-one/base-create-one.service.js.map +1 -1
- package/src/routes/delete-many/base-delete-many.service.js.map +1 -1
- package/src/routes/delete-one/base-delete-one.service.js.map +1 -1
- package/src/routes/duplicate-many/base-duplicate-many.service.js +4 -3
- package/src/routes/duplicate-many/base-duplicate-many.service.js.map +1 -1
- package/src/routes/duplicate-one/base-duplicate-one.service.js +3 -2
- package/src/routes/duplicate-one/base-duplicate-one.service.js.map +1 -1
- package/src/routes/get-many/base-get-many.service.js.map +1 -1
- package/src/routes/get-one/base-get-one.service.js.map +1 -1
- package/src/routes/replace-one/base-replace-one.service.js +3 -2
- package/src/routes/replace-one/base-replace-one.service.js.map +1 -1
- package/src/routes/update-many/base-update-many.service.js.map +1 -1
- package/src/routes/update-one/base-update-one.service.js.map +1 -1
- package/src/services/base/base.service.d.ts +3 -3
- package/src/services/base/base.service.js +26 -8
- package/src/services/base/base.service.js.map +1 -1
- package/src/services/dynamic-api-broadcast/dynamic-api-broadcast.service.js +10 -2
- package/src/services/dynamic-api-broadcast/dynamic-api-broadcast.service.js.map +1 -1
- package/src/services/dynamic-api-global-state/dynamic-api-global-state.service.js +3 -0
- package/src/services/dynamic-api-global-state/dynamic-api-global-state.service.js.map +1 -1
- package/src/version.json +1 -1
- package/test/e2e.setup.d.ts +25 -2
- package/test/e2e.setup.js +150 -4
- package/test/e2e.setup.js.map +1 -1
- package/test/for-feature/base-entity.e2e-spec.js +316 -0
- package/test/for-feature/base-entity.e2e-spec.js.map +1 -0
- package/test/for-feature/http-broadcast.e2e-spec.js +187 -0
- package/test/for-feature/http-broadcast.e2e-spec.js.map +1 -0
- package/test/for-feature/room-broadcast.e2e-spec.d.ts +1 -0
- package/test/for-feature/room-broadcast.e2e-spec.js +192 -0
- package/test/for-feature/room-broadcast.e2e-spec.js.map +1 -0
- package/test/for-feature/soft-deletable-entity.e2e-spec.d.ts +1 -0
- package/test/for-feature/soft-deletable-entity.e2e-spec.js +335 -0
- package/test/for-feature/soft-deletable-entity.e2e-spec.js.map +1 -0
- package/test/for-feature/websockets.e2e-spec.d.ts +1 -0
- package/test/for-feature/websockets.e2e-spec.js +324 -0
- package/test/for-feature/websockets.e2e-spec.js.map +1 -0
- package/test/for-root/auth-api-basic.e2e-spec.d.ts +1 -0
- package/test/for-root/auth-api-basic.e2e-spec.js +338 -0
- package/test/for-root/auth-api-basic.e2e-spec.js.map +1 -0
- package/test/for-root/auth-api-broadcast.e2e-spec.d.ts +1 -0
- package/test/for-root/auth-api-broadcast.e2e-spec.js +82 -0
- package/test/for-root/auth-api-broadcast.e2e-spec.js.map +1 -0
- package/test/for-root/auth-api-login.e2e-spec.d.ts +1 -0
- package/test/for-root/auth-api-login.e2e-spec.js +103 -0
- package/test/for-root/auth-api-login.e2e-spec.js.map +1 -0
- package/test/for-root/auth-api-logout.e2e-spec.d.ts +1 -0
- package/test/for-root/auth-api-logout.e2e-spec.js +74 -0
- package/test/for-root/auth-api-logout.e2e-spec.js.map +1 -0
- package/test/for-root/auth-api-refresh-token-cookie.e2e-spec.d.ts +1 -0
- package/test/for-root/auth-api-refresh-token-cookie.e2e-spec.js +110 -0
- package/test/for-root/auth-api-refresh-token-cookie.e2e-spec.js.map +1 -0
- package/test/for-root/auth-api-refresh-token.e2e-spec.d.ts +1 -0
- package/test/for-root/auth-api-refresh-token.e2e-spec.js +153 -0
- package/test/for-root/auth-api-refresh-token.e2e-spec.js.map +1 -0
- package/test/for-root/auth-api-register.e2e-spec.d.ts +1 -0
- package/test/for-root/auth-api-register.e2e-spec.js +116 -0
- package/test/for-root/auth-api-register.e2e-spec.js.map +1 -0
- package/test/for-root/auth-api-reset-password.e2e-spec.d.ts +1 -0
- package/test/for-root/auth-api-reset-password.e2e-spec.js +168 -0
- package/test/for-root/auth-api-reset-password.e2e-spec.js.map +1 -0
- package/test/for-root/initialization.e2e-spec.d.ts +1 -0
- package/test/for-root/initialization.e2e-spec.js +84 -0
- package/test/for-root/initialization.e2e-spec.js.map +1 -0
- package/test/for-root/websockets-auth-basic.e2e-spec.d.ts +1 -0
- package/test/for-root/websockets-auth-basic.e2e-spec.js +313 -0
- package/test/for-root/websockets-auth-basic.e2e-spec.js.map +1 -0
- package/test/for-root/websockets-auth-broadcast.e2e-spec.d.ts +1 -0
- package/test/for-root/websockets-auth-broadcast.e2e-spec.js +86 -0
- package/test/for-root/websockets-auth-broadcast.e2e-spec.js.map +1 -0
- package/test/for-root/websockets-auth-login.e2e-spec.d.ts +1 -0
- package/test/for-root/websockets-auth-login.e2e-spec.js +107 -0
- package/test/for-root/websockets-auth-login.e2e-spec.js.map +1 -0
- package/test/for-root/websockets-auth-refresh-token.e2e-spec.d.ts +1 -0
- package/test/for-root/websockets-auth-refresh-token.e2e-spec.js +104 -0
- package/test/for-root/websockets-auth-refresh-token.e2e-spec.js.map +1 -0
- package/test/for-root/websockets-auth-register.e2e-spec.d.ts +1 -0
- package/test/for-root/websockets-auth-register.e2e-spec.js +131 -0
- package/test/for-root/websockets-auth-register.e2e-spec.js.map +1 -0
- package/test/for-root/websockets-auth-reset-password.e2e-spec.d.ts +1 -0
- package/test/for-root/websockets-auth-reset-password.e2e-spec.js +164 -0
- package/test/for-root/websockets-auth-reset-password.e2e-spec.js.map +1 -0
- package/test/shared/entities/basic-user.factory.d.ts +12 -0
- package/test/shared/entities/basic-user.factory.js +31 -0
- package/test/shared/entities/basic-user.factory.js.map +1 -0
- package/test/shared/entities/broadcast-user.factory.d.ts +13 -0
- package/test/shared/entities/broadcast-user.factory.js +35 -0
- package/test/shared/entities/broadcast-user.factory.js.map +1 -0
- package/test/shared/entities/index.d.ts +7 -0
- package/test/shared/entities/index.js +24 -0
- package/test/shared/entities/index.js.map +1 -0
- package/test/shared/entities/login-user.factory.d.ts +14 -0
- package/test/shared/entities/login-user.factory.js +39 -0
- package/test/shared/entities/login-user.factory.js.map +1 -0
- package/test/shared/entities/refresh-token-user.factory.d.ts +13 -0
- package/test/shared/entities/refresh-token-user.factory.js +35 -0
- package/test/shared/entities/refresh-token-user.factory.js.map +1 -0
- package/test/shared/entities/register-user.factory.d.ts +14 -0
- package/test/shared/entities/register-user.factory.js +39 -0
- package/test/shared/entities/register-user.factory.js.map +1 -0
- package/test/shared/entities/reset-password-user.factory.d.ts +14 -0
- package/test/shared/entities/reset-password-user.factory.js +39 -0
- package/test/shared/entities/reset-password-user.factory.js.map +1 -0
- package/test/shared/entities/validated-user.factory.d.ts +12 -0
- package/test/shared/entities/validated-user.factory.js +40 -0
- package/test/shared/entities/validated-user.factory.js.map +1 -0
- package/test/shared/fixtures/index.d.ts +2 -0
- package/test/shared/fixtures/index.js +19 -0
- package/test/shared/fixtures/index.js.map +1 -0
- package/test/shared/fixtures/login.fixtures.d.ts +16 -0
- package/test/shared/fixtures/login.fixtures.js +20 -0
- package/test/shared/fixtures/login.fixtures.js.map +1 -0
- package/test/shared/fixtures/register.fixtures.d.ts +10 -0
- package/test/shared/fixtures/register.fixtures.js +14 -0
- package/test/shared/fixtures/register.fixtures.js.map +1 -0
- package/test/shared/index.d.ts +4 -0
- package/test/shared/index.js +24 -0
- package/test/shared/index.js.map +1 -0
- package/test/shared/init-app.d.ts +3 -0
- package/test/shared/init-app.js +19 -0
- package/test/shared/init-app.js.map +1 -0
- package/test/shared/init-module.d.ts +4 -0
- package/test/shared/init-module.js +16 -0
- package/test/shared/init-module.js.map +1 -0
- package/test/test-socket-adapter.d.ts +1 -0
- package/test/test-socket-adapter.js +11 -4
- package/test/test-socket-adapter.js.map +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/test/dynamic-api-for-feature.e2e-spec.js +0 -1100
- package/test/dynamic-api-for-feature.e2e-spec.js.map +0 -1
- package/test/dynamic-api-for-root.e2e-spec.js +0 -1573
- package/test/dynamic-api-for-root.e2e-spec.js.map +0 -1
- /package/test/{dynamic-api-for-feature.e2e-spec.d.ts → for-feature/base-entity.e2e-spec.d.ts} +0 -0
- /package/test/{dynamic-api-for-root.e2e-spec.d.ts → for-feature/http-broadcast.e2e-spec.d.ts} +0 -0
|
@@ -1,1100 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const mongoose_1 = require("@nestjs/mongoose");
|
|
13
|
-
const testing_1 = require("@nestjs/testing");
|
|
14
|
-
const mongoose_2 = require("mongoose");
|
|
15
|
-
const src_1 = require("../src");
|
|
16
|
-
const e2e_setup_1 = require("./e2e.setup");
|
|
17
|
-
require("dotenv/config");
|
|
18
|
-
const utils_1 = require("./utils");
|
|
19
|
-
describe('DynamicApiModule forFeature (e2e)', () => {
|
|
20
|
-
const uri = process.env.MONGO_DB_URL;
|
|
21
|
-
const initApp = async (forFeatureOptions, forRootOptions = {}, initFixtures, initMainCb, testGateway) => {
|
|
22
|
-
const moduleRef = await testing_1.Test.createTestingModule({
|
|
23
|
-
imports: [
|
|
24
|
-
src_1.DynamicApiModule.forRoot(uri, forRootOptions),
|
|
25
|
-
src_1.DynamicApiModule.forFeature(forFeatureOptions),
|
|
26
|
-
],
|
|
27
|
-
providers: testGateway ? [e2e_setup_1.TestGateway] : [],
|
|
28
|
-
}).compile();
|
|
29
|
-
await (0, e2e_setup_1.createTestingApp)(moduleRef, initFixtures, initMainCb);
|
|
30
|
-
};
|
|
31
|
-
beforeEach(() => {
|
|
32
|
-
src_1.DynamicApiModule.state['resetState']();
|
|
33
|
-
});
|
|
34
|
-
afterEach(async () => {
|
|
35
|
-
await (0, e2e_setup_1.closeTestingApp)(mongoose_2.default.connections);
|
|
36
|
-
});
|
|
37
|
-
describe('Entity extends BaseEntity', () => {
|
|
38
|
-
let TestEntity = class TestEntity extends src_1.BaseEntity {
|
|
39
|
-
};
|
|
40
|
-
__decorate([
|
|
41
|
-
(0, mongoose_1.Prop)({ type: String, required: true }),
|
|
42
|
-
__metadata("design:type", String)
|
|
43
|
-
], TestEntity.prototype, "name", void 0);
|
|
44
|
-
__decorate([
|
|
45
|
-
(0, mongoose_1.Prop)({ type: String }),
|
|
46
|
-
__metadata("design:type", String)
|
|
47
|
-
], TestEntity.prototype, "group", void 0);
|
|
48
|
-
TestEntity = __decorate([
|
|
49
|
-
(0, src_1.DynamicAPISchemaOptions)({
|
|
50
|
-
indexes: [{ fields: { name: 1 }, options: { unique: true } }],
|
|
51
|
-
}),
|
|
52
|
-
(0, mongoose_1.Schema)({ collection: 'test-entities' })
|
|
53
|
-
], TestEntity);
|
|
54
|
-
beforeEach(async () => {
|
|
55
|
-
const fixtures = async (_) => {
|
|
56
|
-
const model = await (0, utils_1.getModelFromEntity)(TestEntity);
|
|
57
|
-
await model.insertMany([
|
|
58
|
-
{ name: 'test1' },
|
|
59
|
-
{ name: 'test2' },
|
|
60
|
-
]);
|
|
61
|
-
};
|
|
62
|
-
await initApp({
|
|
63
|
-
entity: TestEntity,
|
|
64
|
-
controllerOptions: {
|
|
65
|
-
path: 'test-entities',
|
|
66
|
-
},
|
|
67
|
-
}, {}, fixtures);
|
|
68
|
-
});
|
|
69
|
-
describe('GET /test-entities', () => {
|
|
70
|
-
it('should return all test entities', async () => {
|
|
71
|
-
const { body, status } = await e2e_setup_1.server.get('/test-entities');
|
|
72
|
-
expect(status).toBe(200);
|
|
73
|
-
expect(body).toEqual([
|
|
74
|
-
{
|
|
75
|
-
id: expect.any(String),
|
|
76
|
-
name: 'test1',
|
|
77
|
-
createdAt: expect.any(String),
|
|
78
|
-
updatedAt: expect.any(String),
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
id: expect.any(String),
|
|
82
|
-
name: 'test2',
|
|
83
|
-
createdAt: expect.any(String),
|
|
84
|
-
updatedAt: expect.any(String),
|
|
85
|
-
},
|
|
86
|
-
]);
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
describe('GET /test-entities/:id', () => {
|
|
90
|
-
let entities;
|
|
91
|
-
beforeEach(async () => {
|
|
92
|
-
const { body } = await e2e_setup_1.server.get('/test-entities');
|
|
93
|
-
entities = body;
|
|
94
|
-
});
|
|
95
|
-
it('should return a test entity by id', async () => {
|
|
96
|
-
const { body, status } = await e2e_setup_1.server.get(`/test-entities/${entities[0].id}`);
|
|
97
|
-
expect(status).toBe(200);
|
|
98
|
-
expect(body).toEqual(entities[0]);
|
|
99
|
-
});
|
|
100
|
-
it('should return 404 if entity not found', async () => {
|
|
101
|
-
const { body, status } = await e2e_setup_1.server.get(`/test-entities/123`);
|
|
102
|
-
expect(status).toBe(404);
|
|
103
|
-
expect(body).toHaveProperty('error', 'Not Found');
|
|
104
|
-
expect(body).toHaveProperty('statusCode', 404);
|
|
105
|
-
expect(body).toHaveProperty('message', 'TestEntity not found');
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
describe('POST /test-entities/many', () => {
|
|
109
|
-
it('should create many test entities', async () => {
|
|
110
|
-
const { body, status } = await e2e_setup_1.server.post('/test-entities/many', {
|
|
111
|
-
list: [
|
|
112
|
-
{ name: 'test3' },
|
|
113
|
-
{ name: 'test4' },
|
|
114
|
-
],
|
|
115
|
-
});
|
|
116
|
-
expect(status).toBe(201);
|
|
117
|
-
expect(body).toEqual([
|
|
118
|
-
{
|
|
119
|
-
id: expect.any(String),
|
|
120
|
-
name: 'test3',
|
|
121
|
-
createdAt: expect.any(String),
|
|
122
|
-
updatedAt: expect.any(String),
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
id: expect.any(String),
|
|
126
|
-
name: 'test4',
|
|
127
|
-
createdAt: expect.any(String),
|
|
128
|
-
updatedAt: expect.any(String),
|
|
129
|
-
},
|
|
130
|
-
]);
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
describe('POST /test-entities', () => {
|
|
134
|
-
it('should create a test entity', async () => {
|
|
135
|
-
const { body, status } = await e2e_setup_1.server.post('/test-entities', { name: 'test3' });
|
|
136
|
-
expect(status).toBe(201);
|
|
137
|
-
expect(body).toEqual({
|
|
138
|
-
id: expect.any(String),
|
|
139
|
-
name: 'test3',
|
|
140
|
-
createdAt: expect.any(String),
|
|
141
|
-
updatedAt: expect.any(String),
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
describe('PUT /test-entities/:id', () => {
|
|
146
|
-
let entityToReplace;
|
|
147
|
-
beforeEach(async () => {
|
|
148
|
-
const { body } = await e2e_setup_1.server.get('/test-entities');
|
|
149
|
-
entityToReplace = body.pop();
|
|
150
|
-
});
|
|
151
|
-
it('should replace a test entity by id', async () => {
|
|
152
|
-
const { body, status } = await e2e_setup_1.server.put(`/test-entities/${entityToReplace.id}`, { name: 'test-replaced' });
|
|
153
|
-
expect(status).toBe(200);
|
|
154
|
-
expect(body).toEqual({
|
|
155
|
-
id: expect.any(String),
|
|
156
|
-
name: 'test-replaced',
|
|
157
|
-
createdAt: expect.any(String),
|
|
158
|
-
updatedAt: expect.any(String),
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
it('should return 404 if entity not found', async () => {
|
|
162
|
-
const { body, status } = await e2e_setup_1.server.put(`/test-entities/123`, { name: 'test1-updated' });
|
|
163
|
-
expect(status).toBe(404);
|
|
164
|
-
expect(body).toHaveProperty('error', 'Not Found');
|
|
165
|
-
expect(body).toHaveProperty('statusCode', 404);
|
|
166
|
-
expect(body).toHaveProperty('message', 'TestEntity not found');
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
describe('PATCH /test-entities', () => {
|
|
170
|
-
let entities;
|
|
171
|
-
beforeEach(async () => {
|
|
172
|
-
const { body } = await e2e_setup_1.server.get('/test-entities');
|
|
173
|
-
entities = body;
|
|
174
|
-
});
|
|
175
|
-
it('should update many test entities', async () => {
|
|
176
|
-
const { body, status } = await e2e_setup_1.server.patch('/test-entities', {
|
|
177
|
-
group: 'many-patched',
|
|
178
|
-
}, { query: { ids: entities.map(({ id }) => id) } });
|
|
179
|
-
expect(status).toBe(200);
|
|
180
|
-
expect(body).toEqual([
|
|
181
|
-
{
|
|
182
|
-
...entities[0],
|
|
183
|
-
group: 'many-patched',
|
|
184
|
-
updatedAt: expect.any(String),
|
|
185
|
-
},
|
|
186
|
-
{
|
|
187
|
-
...entities[1],
|
|
188
|
-
group: 'many-patched',
|
|
189
|
-
updatedAt: expect.any(String),
|
|
190
|
-
},
|
|
191
|
-
]);
|
|
192
|
-
});
|
|
193
|
-
it('should return 404 if entity not found', async () => {
|
|
194
|
-
const { body, status } = await e2e_setup_1.server.patch('/test-entities', {
|
|
195
|
-
group: 'many-patched',
|
|
196
|
-
}, { query: { ids: ['123'] } });
|
|
197
|
-
expect(status).toBe(404);
|
|
198
|
-
expect(body).toHaveProperty('error', 'Not Found');
|
|
199
|
-
expect(body).toHaveProperty('statusCode', 404);
|
|
200
|
-
expect(body).toHaveProperty('message', 'TestEntity not found');
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
describe('PATCH /test-entities/:id', () => {
|
|
204
|
-
let entityToUpdate;
|
|
205
|
-
beforeEach(async () => {
|
|
206
|
-
const { body } = await e2e_setup_1.server.get('/test-entities');
|
|
207
|
-
entityToUpdate = body.pop();
|
|
208
|
-
});
|
|
209
|
-
it('should update a test entity by id', async () => {
|
|
210
|
-
const { body, status } = await e2e_setup_1.server.patch(`/test-entities/${entityToUpdate.id}`, { name: 'test-updated' });
|
|
211
|
-
expect(status).toBe(200);
|
|
212
|
-
expect(body).toEqual({
|
|
213
|
-
id: expect.any(String),
|
|
214
|
-
name: 'test-updated',
|
|
215
|
-
createdAt: expect.any(String),
|
|
216
|
-
updatedAt: expect.any(String),
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
it('should return 404 if entity not found', async () => {
|
|
220
|
-
const { body, status } = await e2e_setup_1.server.patch(`/test-entities/123`, { name: 'test1-updated' });
|
|
221
|
-
expect(status).toBe(404);
|
|
222
|
-
expect(body).toHaveProperty('error', 'Not Found');
|
|
223
|
-
expect(body).toHaveProperty('statusCode', 404);
|
|
224
|
-
expect(body).toHaveProperty('message', 'TestEntity not found');
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
describe('DELETE /test-entities', () => {
|
|
228
|
-
let entities;
|
|
229
|
-
beforeEach(async () => {
|
|
230
|
-
const { body } = await e2e_setup_1.server.get('/test-entities');
|
|
231
|
-
entities = body;
|
|
232
|
-
});
|
|
233
|
-
it('should delete many test entities', async () => {
|
|
234
|
-
const { body, status } = await e2e_setup_1.server.delete('/test-entities', { query: { ids: entities.map(({ id }) => id) } });
|
|
235
|
-
expect(status).toBe(200);
|
|
236
|
-
expect(body).toEqual({ deletedCount: 2 });
|
|
237
|
-
const model = await (0, utils_1.getModelFromEntity)(TestEntity);
|
|
238
|
-
const updatedList = await model.find().lean().exec();
|
|
239
|
-
expect(updatedList).toEqual([]);
|
|
240
|
-
});
|
|
241
|
-
it('should return 200 with 0 for deletedCount if one of entities is not found', async () => {
|
|
242
|
-
const { body, status } = await e2e_setup_1.server.delete('/test-entities', { query: { ids: [entities[0].id, '123'] } });
|
|
243
|
-
expect(status).toBe(200);
|
|
244
|
-
expect(body).toEqual({ deletedCount: 0 });
|
|
245
|
-
});
|
|
246
|
-
});
|
|
247
|
-
describe('DELETE /test-entities/:id', () => {
|
|
248
|
-
let entityToDelete;
|
|
249
|
-
beforeEach(async () => {
|
|
250
|
-
const { body } = await e2e_setup_1.server.get('/test-entities');
|
|
251
|
-
entityToDelete = body.pop();
|
|
252
|
-
});
|
|
253
|
-
it('should delete a test entity by id', async () => {
|
|
254
|
-
const { body, status } = await e2e_setup_1.server.delete(`/test-entities/${entityToDelete.id}`);
|
|
255
|
-
expect(status).toBe(200);
|
|
256
|
-
expect(body).toEqual({ deletedCount: 1 });
|
|
257
|
-
});
|
|
258
|
-
it('should return 200 with deletedCount at 0 if entity not found', async () => {
|
|
259
|
-
const { body, status } = await e2e_setup_1.server.delete(`/test-entities/123`);
|
|
260
|
-
expect(status).toBe(200);
|
|
261
|
-
expect(body).toEqual({ deletedCount: 0 });
|
|
262
|
-
});
|
|
263
|
-
});
|
|
264
|
-
describe('POST /test-entities/duplicate', () => {
|
|
265
|
-
let entities;
|
|
266
|
-
beforeEach(async () => {
|
|
267
|
-
const { body } = await e2e_setup_1.server.get('/test-entities');
|
|
268
|
-
entities = body;
|
|
269
|
-
});
|
|
270
|
-
it('should duplicate test entities', async () => {
|
|
271
|
-
const { body, status } = await e2e_setup_1.server.post('/test-entities/duplicate', {
|
|
272
|
-
name: 'test1-duplicated',
|
|
273
|
-
group: 'duplicated',
|
|
274
|
-
}, { query: { ids: [entities[0].id] } });
|
|
275
|
-
expect(status).toBe(201);
|
|
276
|
-
expect(body).toEqual([
|
|
277
|
-
{
|
|
278
|
-
...entities[0],
|
|
279
|
-
id: expect.any(String),
|
|
280
|
-
name: 'test1-duplicated',
|
|
281
|
-
group: 'duplicated',
|
|
282
|
-
createdAt: expect.any(String),
|
|
283
|
-
updatedAt: expect.any(String),
|
|
284
|
-
},
|
|
285
|
-
]);
|
|
286
|
-
});
|
|
287
|
-
it('should return 404 if one of entities is not found', async () => {
|
|
288
|
-
const { body, status } = await e2e_setup_1.server.post(`/test-entities/duplicate`, {
|
|
289
|
-
group: 'duplicated',
|
|
290
|
-
}, { query: { ids: [entities[0].id, '123'] } });
|
|
291
|
-
expect(status).toBe(404);
|
|
292
|
-
expect(body).toHaveProperty('error', 'Not Found');
|
|
293
|
-
expect(body).toHaveProperty('statusCode', 404);
|
|
294
|
-
expect(body).toHaveProperty('message', 'TestEntity not found');
|
|
295
|
-
});
|
|
296
|
-
});
|
|
297
|
-
describe('POST /test-entities/duplicate/:id', () => {
|
|
298
|
-
let entityToDuplicate;
|
|
299
|
-
beforeEach(async () => {
|
|
300
|
-
const { body } = await e2e_setup_1.server.get('/test-entities');
|
|
301
|
-
entityToDuplicate = body.pop();
|
|
302
|
-
});
|
|
303
|
-
it('should duplicate a test entity by id', async () => {
|
|
304
|
-
const { body, status } = await e2e_setup_1.server.post(`/test-entities/duplicate/${entityToDuplicate.id}`, {
|
|
305
|
-
name: 'test2-duplicated',
|
|
306
|
-
});
|
|
307
|
-
expect(status).toBe(201);
|
|
308
|
-
expect(body).toEqual({
|
|
309
|
-
...entityToDuplicate,
|
|
310
|
-
id: expect.any(String),
|
|
311
|
-
name: 'test2-duplicated',
|
|
312
|
-
createdAt: expect.any(String),
|
|
313
|
-
updatedAt: expect.any(String),
|
|
314
|
-
});
|
|
315
|
-
});
|
|
316
|
-
it('should return 404 if entity not found', async () => {
|
|
317
|
-
const { body, status } = await e2e_setup_1.server.post(`/test-entities/duplicate/123`, {
|
|
318
|
-
name: 'test1-duplicated',
|
|
319
|
-
group: 'duplicated',
|
|
320
|
-
});
|
|
321
|
-
expect(status).toBe(404);
|
|
322
|
-
expect(body).toHaveProperty('error', 'Not Found');
|
|
323
|
-
expect(body).toHaveProperty('statusCode', 404);
|
|
324
|
-
expect(body).toHaveProperty('message', 'TestEntity not found');
|
|
325
|
-
});
|
|
326
|
-
});
|
|
327
|
-
});
|
|
328
|
-
describe('Entity extends SoftDeletableEntity', () => {
|
|
329
|
-
let TestDeletableEntity = class TestDeletableEntity extends src_1.SoftDeletableEntity {
|
|
330
|
-
};
|
|
331
|
-
__decorate([
|
|
332
|
-
(0, mongoose_1.Prop)({ type: String, required: true }),
|
|
333
|
-
__metadata("design:type", String)
|
|
334
|
-
], TestDeletableEntity.prototype, "name", void 0);
|
|
335
|
-
__decorate([
|
|
336
|
-
(0, mongoose_1.Prop)({ type: String }),
|
|
337
|
-
__metadata("design:type", String)
|
|
338
|
-
], TestDeletableEntity.prototype, "group", void 0);
|
|
339
|
-
TestDeletableEntity = __decorate([
|
|
340
|
-
(0, src_1.DynamicAPISchemaOptions)({
|
|
341
|
-
indexes: [{ fields: { name: 1 }, options: { unique: true, partialFilterExpression: { deletedAt: { $eq: null } } } }],
|
|
342
|
-
}),
|
|
343
|
-
(0, mongoose_1.Schema)({ collection: 'test-entities' })
|
|
344
|
-
], TestDeletableEntity);
|
|
345
|
-
beforeEach(async () => {
|
|
346
|
-
const fixtures = async (_) => {
|
|
347
|
-
const model = await (0, utils_1.getModelFromEntity)(TestDeletableEntity);
|
|
348
|
-
await model.insertMany([
|
|
349
|
-
{ name: 'test1' },
|
|
350
|
-
{ name: 'test2' },
|
|
351
|
-
]);
|
|
352
|
-
};
|
|
353
|
-
await initApp({
|
|
354
|
-
entity: TestDeletableEntity,
|
|
355
|
-
controllerOptions: {
|
|
356
|
-
path: 'test-entities',
|
|
357
|
-
},
|
|
358
|
-
}, {}, fixtures);
|
|
359
|
-
});
|
|
360
|
-
describe('GET /test-entities', () => {
|
|
361
|
-
it('should return all test entities', async () => {
|
|
362
|
-
const { body, status } = await e2e_setup_1.server.get('/test-entities');
|
|
363
|
-
expect(status).toBe(200);
|
|
364
|
-
expect(body).toEqual([
|
|
365
|
-
{
|
|
366
|
-
id: expect.any(String),
|
|
367
|
-
name: 'test1',
|
|
368
|
-
createdAt: expect.any(String),
|
|
369
|
-
updatedAt: expect.any(String),
|
|
370
|
-
},
|
|
371
|
-
{
|
|
372
|
-
id: expect.any(String),
|
|
373
|
-
name: 'test2',
|
|
374
|
-
createdAt: expect.any(String),
|
|
375
|
-
updatedAt: expect.any(String),
|
|
376
|
-
},
|
|
377
|
-
]);
|
|
378
|
-
});
|
|
379
|
-
});
|
|
380
|
-
describe('GET /test-entities/:id', () => {
|
|
381
|
-
let entities;
|
|
382
|
-
beforeEach(async () => {
|
|
383
|
-
const { body } = await e2e_setup_1.server.get('/test-entities');
|
|
384
|
-
entities = body;
|
|
385
|
-
});
|
|
386
|
-
it('should return a test entity by id', async () => {
|
|
387
|
-
const { body, status } = await e2e_setup_1.server.get(`/test-entities/${entities[0].id}`);
|
|
388
|
-
expect(status).toBe(200);
|
|
389
|
-
expect(body).toEqual(entities[0]);
|
|
390
|
-
});
|
|
391
|
-
it('should return 404 if entity not found', async () => {
|
|
392
|
-
const { body, status } = await e2e_setup_1.server.get(`/test-entities/123`);
|
|
393
|
-
expect(status).toBe(404);
|
|
394
|
-
expect(body).toHaveProperty('error', 'Not Found');
|
|
395
|
-
expect(body).toHaveProperty('statusCode', 404);
|
|
396
|
-
expect(body).toHaveProperty('message', 'TestDeletableEntity not found');
|
|
397
|
-
});
|
|
398
|
-
});
|
|
399
|
-
describe('POST /test-entities/many', () => {
|
|
400
|
-
it('should create many test entities', async () => {
|
|
401
|
-
const { body, status } = await e2e_setup_1.server.post('/test-entities/many', {
|
|
402
|
-
list: [
|
|
403
|
-
{ name: 'test3' },
|
|
404
|
-
{ name: 'test4' },
|
|
405
|
-
],
|
|
406
|
-
});
|
|
407
|
-
expect(status).toBe(201);
|
|
408
|
-
expect(body).toEqual([
|
|
409
|
-
{
|
|
410
|
-
id: expect.any(String),
|
|
411
|
-
name: 'test3',
|
|
412
|
-
createdAt: expect.any(String),
|
|
413
|
-
updatedAt: expect.any(String),
|
|
414
|
-
},
|
|
415
|
-
{
|
|
416
|
-
id: expect.any(String),
|
|
417
|
-
name: 'test4',
|
|
418
|
-
createdAt: expect.any(String),
|
|
419
|
-
updatedAt: expect.any(String),
|
|
420
|
-
},
|
|
421
|
-
]);
|
|
422
|
-
});
|
|
423
|
-
});
|
|
424
|
-
describe('POST /test-entities', () => {
|
|
425
|
-
it('should create a test entity', async () => {
|
|
426
|
-
const { body, status } = await e2e_setup_1.server.post('/test-entities', { name: 'test3' });
|
|
427
|
-
expect(status).toBe(201);
|
|
428
|
-
expect(body).toEqual({
|
|
429
|
-
id: expect.any(String),
|
|
430
|
-
name: 'test3',
|
|
431
|
-
createdAt: expect.any(String),
|
|
432
|
-
updatedAt: expect.any(String),
|
|
433
|
-
});
|
|
434
|
-
});
|
|
435
|
-
});
|
|
436
|
-
describe('PUT /test-entities/:id', () => {
|
|
437
|
-
let entityToReplace;
|
|
438
|
-
beforeEach(async () => {
|
|
439
|
-
const { body } = await e2e_setup_1.server.get('/test-entities');
|
|
440
|
-
entityToReplace = body.pop();
|
|
441
|
-
});
|
|
442
|
-
it('should replace a test entity by id', async () => {
|
|
443
|
-
const { body, status } = await e2e_setup_1.server.put(`/test-entities/${entityToReplace.id}`, { name: 'test-replaced' });
|
|
444
|
-
expect(status).toBe(200);
|
|
445
|
-
expect(body).toEqual({
|
|
446
|
-
id: expect.any(String),
|
|
447
|
-
name: 'test-replaced',
|
|
448
|
-
createdAt: expect.any(String),
|
|
449
|
-
updatedAt: expect.any(String),
|
|
450
|
-
});
|
|
451
|
-
});
|
|
452
|
-
it('should return 404 if entity not found', async () => {
|
|
453
|
-
const { body, status } = await e2e_setup_1.server.put(`/test-entities/123`, { name: 'test1-updated' });
|
|
454
|
-
expect(status).toBe(404);
|
|
455
|
-
expect(body).toHaveProperty('error', 'Not Found');
|
|
456
|
-
expect(body).toHaveProperty('statusCode', 404);
|
|
457
|
-
expect(body).toHaveProperty('message', 'TestDeletableEntity not found');
|
|
458
|
-
});
|
|
459
|
-
});
|
|
460
|
-
describe('PATCH /test-entities', () => {
|
|
461
|
-
let entities;
|
|
462
|
-
beforeEach(async () => {
|
|
463
|
-
const { body } = await e2e_setup_1.server.get('/test-entities');
|
|
464
|
-
entities = body;
|
|
465
|
-
});
|
|
466
|
-
it('should update many test entities', async () => {
|
|
467
|
-
const { body, status } = await e2e_setup_1.server.patch('/test-entities', {
|
|
468
|
-
group: 'many-patched',
|
|
469
|
-
}, { query: { ids: entities.map(({ id }) => id) } });
|
|
470
|
-
expect(status).toBe(200);
|
|
471
|
-
expect(body).toEqual([
|
|
472
|
-
{
|
|
473
|
-
...entities[0],
|
|
474
|
-
group: 'many-patched',
|
|
475
|
-
updatedAt: expect.any(String),
|
|
476
|
-
},
|
|
477
|
-
{
|
|
478
|
-
...entities[1],
|
|
479
|
-
group: 'many-patched',
|
|
480
|
-
updatedAt: expect.any(String),
|
|
481
|
-
},
|
|
482
|
-
]);
|
|
483
|
-
});
|
|
484
|
-
it('should return 404 if entity not found', async () => {
|
|
485
|
-
const { body, status } = await e2e_setup_1.server.patch('/test-entities', {
|
|
486
|
-
group: 'many-patched',
|
|
487
|
-
}, { query: { ids: ['123'] } });
|
|
488
|
-
expect(status).toBe(404);
|
|
489
|
-
expect(body).toHaveProperty('error', 'Not Found');
|
|
490
|
-
expect(body).toHaveProperty('statusCode', 404);
|
|
491
|
-
expect(body).toHaveProperty('message', 'TestDeletableEntity not found');
|
|
492
|
-
});
|
|
493
|
-
});
|
|
494
|
-
describe('PATCH /test-entities/:id', () => {
|
|
495
|
-
let entityToUpdate;
|
|
496
|
-
beforeEach(async () => {
|
|
497
|
-
const { body } = await e2e_setup_1.server.get('/test-entities');
|
|
498
|
-
entityToUpdate = body.pop();
|
|
499
|
-
});
|
|
500
|
-
it('should update a test entity by id', async () => {
|
|
501
|
-
const { body, status } = await e2e_setup_1.server.patch(`/test-entities/${entityToUpdate.id}`, { name: 'test-updated' });
|
|
502
|
-
expect(status).toBe(200);
|
|
503
|
-
expect(body).toEqual({
|
|
504
|
-
id: expect.any(String),
|
|
505
|
-
name: 'test-updated',
|
|
506
|
-
createdAt: expect.any(String),
|
|
507
|
-
updatedAt: expect.any(String),
|
|
508
|
-
});
|
|
509
|
-
});
|
|
510
|
-
it('should return 404 if entity not found', async () => {
|
|
511
|
-
const { body, status } = await e2e_setup_1.server.patch(`/test-entities/123`, { name: 'test1-updated' });
|
|
512
|
-
expect(status).toBe(404);
|
|
513
|
-
expect(body).toHaveProperty('error', 'Not Found');
|
|
514
|
-
expect(body).toHaveProperty('statusCode', 404);
|
|
515
|
-
expect(body).toHaveProperty('message', 'TestDeletableEntity not found');
|
|
516
|
-
});
|
|
517
|
-
});
|
|
518
|
-
describe('DELETE /test-entities', () => {
|
|
519
|
-
let entities;
|
|
520
|
-
beforeEach(async () => {
|
|
521
|
-
const { body } = await e2e_setup_1.server.get('/test-entities');
|
|
522
|
-
entities = body;
|
|
523
|
-
});
|
|
524
|
-
it('should delete many test entities', async () => {
|
|
525
|
-
const { body, status } = await e2e_setup_1.server.delete('/test-entities', { query: { ids: entities.map(({ id }) => id) } });
|
|
526
|
-
expect(status).toBe(200);
|
|
527
|
-
expect(body).toEqual({ deletedCount: 2 });
|
|
528
|
-
const model = await (0, utils_1.getModelFromEntity)(TestDeletableEntity);
|
|
529
|
-
const updatedList = await model.find().lean().exec();
|
|
530
|
-
expect(updatedList).toEqual([
|
|
531
|
-
{
|
|
532
|
-
_id: expect.any(Object),
|
|
533
|
-
__v: expect.any(Number),
|
|
534
|
-
name: 'test1',
|
|
535
|
-
isDeleted: true,
|
|
536
|
-
createdAt: expect.any(Date),
|
|
537
|
-
updatedAt: expect.any(Date),
|
|
538
|
-
deletedAt: expect.any(Date),
|
|
539
|
-
},
|
|
540
|
-
{
|
|
541
|
-
_id: expect.any(Object),
|
|
542
|
-
__v: expect.any(Number),
|
|
543
|
-
name: 'test2',
|
|
544
|
-
isDeleted: true,
|
|
545
|
-
createdAt: expect.any(Date),
|
|
546
|
-
updatedAt: expect.any(Date),
|
|
547
|
-
deletedAt: expect.any(Date),
|
|
548
|
-
},
|
|
549
|
-
]);
|
|
550
|
-
});
|
|
551
|
-
it('should return 200 with 0 for deletedCount if one of entities is not found', async () => {
|
|
552
|
-
const { body, status } = await e2e_setup_1.server.delete('/test-entities', { query: { ids: [entities[0].id, '123'] } });
|
|
553
|
-
expect(status).toBe(200);
|
|
554
|
-
expect(body).toEqual({ deletedCount: 0 });
|
|
555
|
-
});
|
|
556
|
-
});
|
|
557
|
-
describe('DELETE /test-entities/:id', () => {
|
|
558
|
-
let entityToDelete;
|
|
559
|
-
beforeEach(async () => {
|
|
560
|
-
const { body } = await e2e_setup_1.server.get('/test-entities');
|
|
561
|
-
entityToDelete = body.pop();
|
|
562
|
-
});
|
|
563
|
-
it('should delete a test entity by id', async () => {
|
|
564
|
-
const { body, status } = await e2e_setup_1.server.delete(`/test-entities/${entityToDelete.id}`);
|
|
565
|
-
expect(status).toBe(200);
|
|
566
|
-
expect(body).toEqual({ deletedCount: 1 });
|
|
567
|
-
});
|
|
568
|
-
it('should return 200 with deletedCount at 0 if entity not found', async () => {
|
|
569
|
-
const { body, status } = await e2e_setup_1.server.delete(`/test-entities/123`);
|
|
570
|
-
expect(status).toBe(200);
|
|
571
|
-
expect(body).toEqual({ deletedCount: 0 });
|
|
572
|
-
});
|
|
573
|
-
});
|
|
574
|
-
describe('POST /test-entities/duplicate', () => {
|
|
575
|
-
let entities;
|
|
576
|
-
beforeEach(async () => {
|
|
577
|
-
const { body } = await e2e_setup_1.server.get('/test-entities');
|
|
578
|
-
entities = body;
|
|
579
|
-
});
|
|
580
|
-
it('should duplicate test entities', async () => {
|
|
581
|
-
const { body, status } = await e2e_setup_1.server.post('/test-entities/duplicate', {
|
|
582
|
-
name: 'test1-duplicated',
|
|
583
|
-
group: 'duplicated',
|
|
584
|
-
}, { query: { ids: [entities[0].id] } });
|
|
585
|
-
expect(status).toBe(201);
|
|
586
|
-
expect(body).toEqual([
|
|
587
|
-
{
|
|
588
|
-
...entities[0],
|
|
589
|
-
id: expect.any(String),
|
|
590
|
-
name: 'test1-duplicated',
|
|
591
|
-
group: 'duplicated',
|
|
592
|
-
createdAt: expect.any(String),
|
|
593
|
-
updatedAt: expect.any(String),
|
|
594
|
-
},
|
|
595
|
-
]);
|
|
596
|
-
});
|
|
597
|
-
it('should return 404 if one of entities is not found', async () => {
|
|
598
|
-
const { body, status } = await e2e_setup_1.server.post(`/test-entities/duplicate`, {
|
|
599
|
-
group: 'duplicated',
|
|
600
|
-
}, { query: { ids: [entities[0].id, '123'] } });
|
|
601
|
-
expect(status).toBe(404);
|
|
602
|
-
expect(body).toHaveProperty('error', 'Not Found');
|
|
603
|
-
expect(body).toHaveProperty('statusCode', 404);
|
|
604
|
-
expect(body).toHaveProperty('message', 'TestDeletableEntity not found');
|
|
605
|
-
});
|
|
606
|
-
});
|
|
607
|
-
describe('POST /test-entities/duplicate/:id', () => {
|
|
608
|
-
let entityToDuplicate;
|
|
609
|
-
beforeEach(async () => {
|
|
610
|
-
const { body } = await e2e_setup_1.server.get('/test-entities');
|
|
611
|
-
entityToDuplicate = body.pop();
|
|
612
|
-
});
|
|
613
|
-
it('should duplicate a test entity by id', async () => {
|
|
614
|
-
const { body, status } = await e2e_setup_1.server.post(`/test-entities/duplicate/${entityToDuplicate.id}`, {
|
|
615
|
-
name: 'test2-duplicated',
|
|
616
|
-
});
|
|
617
|
-
expect(status).toBe(201);
|
|
618
|
-
expect(body).toEqual({
|
|
619
|
-
...entityToDuplicate,
|
|
620
|
-
id: expect.any(String),
|
|
621
|
-
name: 'test2-duplicated',
|
|
622
|
-
createdAt: expect.any(String),
|
|
623
|
-
updatedAt: expect.any(String),
|
|
624
|
-
});
|
|
625
|
-
});
|
|
626
|
-
it('should return 404 if entity not found', async () => {
|
|
627
|
-
const { body, status } = await e2e_setup_1.server.post(`/test-entities/duplicate/123`, {
|
|
628
|
-
name: 'test1-duplicated',
|
|
629
|
-
group: 'duplicated',
|
|
630
|
-
});
|
|
631
|
-
expect(status).toBe(404);
|
|
632
|
-
expect(body).toHaveProperty('error', 'Not Found');
|
|
633
|
-
expect(body).toHaveProperty('statusCode', 404);
|
|
634
|
-
expect(body).toHaveProperty('message', 'TestDeletableEntity not found');
|
|
635
|
-
});
|
|
636
|
-
});
|
|
637
|
-
});
|
|
638
|
-
describe('Websockets', () => {
|
|
639
|
-
let UserEntity = class UserEntity extends src_1.BaseEntity {
|
|
640
|
-
};
|
|
641
|
-
__decorate([
|
|
642
|
-
(0, mongoose_1.Prop)({ type: String, required: true }),
|
|
643
|
-
__metadata("design:type", String)
|
|
644
|
-
], UserEntity.prototype, "email", void 0);
|
|
645
|
-
__decorate([
|
|
646
|
-
(0, mongoose_1.Prop)({ type: String, required: true }),
|
|
647
|
-
__metadata("design:type", String)
|
|
648
|
-
], UserEntity.prototype, "password", void 0);
|
|
649
|
-
__decorate([
|
|
650
|
-
(0, mongoose_1.Prop)({ type: Boolean, default: false }),
|
|
651
|
-
__metadata("design:type", Boolean)
|
|
652
|
-
], UserEntity.prototype, "isAdmin", void 0);
|
|
653
|
-
UserEntity = __decorate([
|
|
654
|
-
(0, mongoose_1.Schema)({ collection: 'users' })
|
|
655
|
-
], UserEntity);
|
|
656
|
-
let ProductEntity = class ProductEntity extends src_1.BaseEntity {
|
|
657
|
-
};
|
|
658
|
-
__decorate([
|
|
659
|
-
(0, mongoose_1.Prop)({ type: String, required: true }),
|
|
660
|
-
__metadata("design:type", String)
|
|
661
|
-
], ProductEntity.prototype, "name", void 0);
|
|
662
|
-
__decorate([
|
|
663
|
-
(0, mongoose_1.Prop)({ type: Boolean, default: false }),
|
|
664
|
-
__metadata("design:type", Boolean)
|
|
665
|
-
], ProductEntity.prototype, "inStock", void 0);
|
|
666
|
-
__decorate([
|
|
667
|
-
(0, mongoose_1.Prop)({ type: String }),
|
|
668
|
-
__metadata("design:type", String)
|
|
669
|
-
], ProductEntity.prototype, "status", void 0);
|
|
670
|
-
ProductEntity = __decorate([
|
|
671
|
-
(0, mongoose_1.Schema)({ collection: 'products' })
|
|
672
|
-
], ProductEntity);
|
|
673
|
-
const customEvent = 'product-custom-event';
|
|
674
|
-
let adminAccessToken;
|
|
675
|
-
let userAccessToken;
|
|
676
|
-
let firstProduct;
|
|
677
|
-
let secondProduct;
|
|
678
|
-
beforeEach(async () => {
|
|
679
|
-
const fixtures = async (_) => {
|
|
680
|
-
const model = await (0, utils_1.getModelFromEntity)(ProductEntity);
|
|
681
|
-
await model.insertMany([
|
|
682
|
-
{ name: 'mayo', inStock: true },
|
|
683
|
-
{ name: 'ketchup' },
|
|
684
|
-
]).then(([mayoProduct, ketchupProduct]) => {
|
|
685
|
-
firstProduct = mayoProduct;
|
|
686
|
-
secondProduct = ketchupProduct;
|
|
687
|
-
});
|
|
688
|
-
};
|
|
689
|
-
await initApp({
|
|
690
|
-
entity: ProductEntity,
|
|
691
|
-
controllerOptions: {
|
|
692
|
-
apiTag: 'Product',
|
|
693
|
-
path: 'products',
|
|
694
|
-
},
|
|
695
|
-
routes: [
|
|
696
|
-
{ type: 'GetMany', isPublic: true },
|
|
697
|
-
{
|
|
698
|
-
type: 'CreateMany',
|
|
699
|
-
webSocket: true,
|
|
700
|
-
broadcast: {
|
|
701
|
-
enabled: (_, user) => user.isAdmin === true,
|
|
702
|
-
},
|
|
703
|
-
},
|
|
704
|
-
{
|
|
705
|
-
type: 'CreateOne',
|
|
706
|
-
webSocket: true,
|
|
707
|
-
broadcast: { enabled: true },
|
|
708
|
-
},
|
|
709
|
-
{
|
|
710
|
-
type: 'UpdateMany',
|
|
711
|
-
webSocket: true,
|
|
712
|
-
broadcast: {
|
|
713
|
-
enabled: false,
|
|
714
|
-
eventName: customEvent,
|
|
715
|
-
},
|
|
716
|
-
},
|
|
717
|
-
{
|
|
718
|
-
type: 'UpdateOne',
|
|
719
|
-
webSocket: true,
|
|
720
|
-
broadcast: {
|
|
721
|
-
enabled: true,
|
|
722
|
-
eventName: customEvent,
|
|
723
|
-
},
|
|
724
|
-
},
|
|
725
|
-
{
|
|
726
|
-
type: 'ReplaceOne',
|
|
727
|
-
webSocket: true,
|
|
728
|
-
broadcast: {
|
|
729
|
-
enabled: true,
|
|
730
|
-
},
|
|
731
|
-
},
|
|
732
|
-
{
|
|
733
|
-
type: 'DuplicateOne',
|
|
734
|
-
webSocket: true,
|
|
735
|
-
broadcast: {
|
|
736
|
-
enabled: (_, user) => user.isAdmin === true,
|
|
737
|
-
eventName: customEvent,
|
|
738
|
-
},
|
|
739
|
-
},
|
|
740
|
-
{
|
|
741
|
-
type: 'DuplicateMany',
|
|
742
|
-
webSocket: true,
|
|
743
|
-
broadcast: {
|
|
744
|
-
enabled: true,
|
|
745
|
-
},
|
|
746
|
-
},
|
|
747
|
-
{
|
|
748
|
-
type: 'DeleteOne',
|
|
749
|
-
webSocket: true,
|
|
750
|
-
broadcast: {
|
|
751
|
-
enabled: true,
|
|
752
|
-
},
|
|
753
|
-
},
|
|
754
|
-
{
|
|
755
|
-
type: 'DeleteMany',
|
|
756
|
-
webSocket: true,
|
|
757
|
-
broadcast: {
|
|
758
|
-
enabled: true,
|
|
759
|
-
},
|
|
760
|
-
},
|
|
761
|
-
],
|
|
762
|
-
}, {
|
|
763
|
-
useAuth: {
|
|
764
|
-
userEntity: UserEntity,
|
|
765
|
-
login: {
|
|
766
|
-
additionalFields: ['isAdmin'],
|
|
767
|
-
},
|
|
768
|
-
webSocket: true,
|
|
769
|
-
},
|
|
770
|
-
}, fixtures, async (app) => {
|
|
771
|
-
app.useWebSocketAdapter(new e2e_setup_1.TestSocketAdapter(app));
|
|
772
|
-
}, true);
|
|
773
|
-
adminAccessToken = (await e2e_setup_1.server.emit('auth-register', { email: 'unit@test.co', password: 'test', isAdmin: true })).accessToken;
|
|
774
|
-
userAccessToken = (await e2e_setup_1.server.emit('auth-register', { email: 'toto@test.co', password: 'test' })).accessToken;
|
|
775
|
-
});
|
|
776
|
-
it('[CreateOne] should broadcast created product to all clients', async () => {
|
|
777
|
-
await e2e_setup_1.server.emit('create-one-product', { name: 'mustard', inStock: true }, { accessToken: adminAccessToken, expectBroadcast: true });
|
|
778
|
-
expect(e2e_setup_1.handleSocketBroadcast).toHaveBeenCalledTimes(1);
|
|
779
|
-
expect(e2e_setup_1.handleSocketBroadcast).toHaveBeenCalledWith({
|
|
780
|
-
event: 'create-one-product',
|
|
781
|
-
data: expect.arrayContaining([
|
|
782
|
-
expect.objectContaining({
|
|
783
|
-
name: 'mustard',
|
|
784
|
-
inStock: true,
|
|
785
|
-
}),
|
|
786
|
-
]),
|
|
787
|
-
});
|
|
788
|
-
});
|
|
789
|
-
it('[CreateMany] should broadcast created products to all clients when admin', async () => {
|
|
790
|
-
await e2e_setup_1.server.emit('create-many-product', {
|
|
791
|
-
list: [
|
|
792
|
-
{ name: 'mustard', inStock: true },
|
|
793
|
-
{ name: 'relish', inStock: false },
|
|
794
|
-
],
|
|
795
|
-
}, { accessToken: adminAccessToken, expectBroadcast: true });
|
|
796
|
-
expect(e2e_setup_1.handleSocketBroadcast).toHaveBeenCalledTimes(1);
|
|
797
|
-
expect(e2e_setup_1.handleSocketBroadcast).toHaveBeenCalledWith({
|
|
798
|
-
event: 'create-many-product',
|
|
799
|
-
data: expect.arrayContaining([
|
|
800
|
-
expect.objectContaining({
|
|
801
|
-
name: 'mustard',
|
|
802
|
-
inStock: true,
|
|
803
|
-
}),
|
|
804
|
-
expect.objectContaining({
|
|
805
|
-
name: 'relish',
|
|
806
|
-
inStock: false,
|
|
807
|
-
}),
|
|
808
|
-
]),
|
|
809
|
-
});
|
|
810
|
-
});
|
|
811
|
-
it('[CreateMany] should NOT broadcast created products when user is not admin', async () => {
|
|
812
|
-
await e2e_setup_1.server.emit('create-many-product', {
|
|
813
|
-
list: [
|
|
814
|
-
{ name: 'pickles', inStock: true },
|
|
815
|
-
{ name: 'onions', inStock: false },
|
|
816
|
-
],
|
|
817
|
-
}, { accessToken: userAccessToken });
|
|
818
|
-
expect(e2e_setup_1.handleSocketBroadcast).not.toHaveBeenCalled();
|
|
819
|
-
});
|
|
820
|
-
it('[UpdateOne] should broadcast updated product to all clients with custom event name', async () => {
|
|
821
|
-
await e2e_setup_1.server.emit('update-one-product', {
|
|
822
|
-
id: firstProduct.id,
|
|
823
|
-
name: 'updated mayo',
|
|
824
|
-
inStock: false,
|
|
825
|
-
}, { accessToken: adminAccessToken, broadcastEvent: customEvent, expectBroadcast: true });
|
|
826
|
-
expect(e2e_setup_1.handleSocketBroadcast).toHaveBeenCalledTimes(1);
|
|
827
|
-
expect(e2e_setup_1.handleSocketBroadcast).toHaveBeenCalledWith({
|
|
828
|
-
event: customEvent,
|
|
829
|
-
data: expect.arrayContaining([
|
|
830
|
-
expect.objectContaining({
|
|
831
|
-
id: firstProduct.id,
|
|
832
|
-
name: 'updated mayo',
|
|
833
|
-
inStock: false,
|
|
834
|
-
}),
|
|
835
|
-
]),
|
|
836
|
-
});
|
|
837
|
-
});
|
|
838
|
-
it('[UpdateMany] should NOT broadcast updated products when broadcast is disabled', async () => {
|
|
839
|
-
const { body: products } = await e2e_setup_1.server.get('/products');
|
|
840
|
-
await e2e_setup_1.server.emit('update-many-product', {
|
|
841
|
-
ids: products.map(p => p.id),
|
|
842
|
-
status: 'updated',
|
|
843
|
-
}, { accessToken: adminAccessToken });
|
|
844
|
-
expect(e2e_setup_1.handleSocketBroadcast).not.toHaveBeenCalled();
|
|
845
|
-
});
|
|
846
|
-
it('[DeleteOne] should broadcast deleted product id to all clients', async () => {
|
|
847
|
-
await e2e_setup_1.server.emit('delete-one-product', {
|
|
848
|
-
id: firstProduct.id,
|
|
849
|
-
}, { accessToken: adminAccessToken, expectBroadcast: true });
|
|
850
|
-
expect(e2e_setup_1.handleSocketBroadcast).toHaveBeenCalledTimes(1);
|
|
851
|
-
expect(e2e_setup_1.handleSocketBroadcast).toHaveBeenCalledWith({
|
|
852
|
-
event: 'delete-one-product',
|
|
853
|
-
data: expect.arrayContaining([
|
|
854
|
-
expect.objectContaining({
|
|
855
|
-
id: firstProduct.id,
|
|
856
|
-
}),
|
|
857
|
-
]),
|
|
858
|
-
});
|
|
859
|
-
});
|
|
860
|
-
it('[ReplaceOne] should broadcast replaced product to all clients', async () => {
|
|
861
|
-
await e2e_setup_1.server.emit('replace-one-product', {
|
|
862
|
-
id: firstProduct.id,
|
|
863
|
-
name: 'replaced mayo',
|
|
864
|
-
inStock: false,
|
|
865
|
-
}, { accessToken: adminAccessToken, expectBroadcast: true });
|
|
866
|
-
expect(e2e_setup_1.handleSocketBroadcast).toHaveBeenCalledTimes(1);
|
|
867
|
-
expect(e2e_setup_1.handleSocketBroadcast).toHaveBeenCalledWith({
|
|
868
|
-
event: 'replace-one-product',
|
|
869
|
-
data: expect.arrayContaining([
|
|
870
|
-
expect.objectContaining({
|
|
871
|
-
id: firstProduct.id,
|
|
872
|
-
name: 'replaced mayo',
|
|
873
|
-
inStock: false,
|
|
874
|
-
}),
|
|
875
|
-
]),
|
|
876
|
-
});
|
|
877
|
-
});
|
|
878
|
-
it('[DuplicateOne] should broadcast duplicated product to all clients with custom event name when admin', async () => {
|
|
879
|
-
await e2e_setup_1.server.emit('duplicate-one-product', {
|
|
880
|
-
id: firstProduct.id,
|
|
881
|
-
name: 'duplicated mayo',
|
|
882
|
-
}, { accessToken: adminAccessToken, broadcastEvent: customEvent, expectBroadcast: true });
|
|
883
|
-
expect(e2e_setup_1.handleSocketBroadcast).toHaveBeenCalledTimes(1);
|
|
884
|
-
expect(e2e_setup_1.handleSocketBroadcast).toHaveBeenCalledWith({
|
|
885
|
-
event: customEvent,
|
|
886
|
-
data: expect.arrayContaining([
|
|
887
|
-
expect.objectContaining({
|
|
888
|
-
name: 'duplicated mayo',
|
|
889
|
-
inStock: firstProduct.inStock,
|
|
890
|
-
}),
|
|
891
|
-
]),
|
|
892
|
-
});
|
|
893
|
-
});
|
|
894
|
-
it('[DuplicateOne] should NOT broadcast duplicated product when user is not admin', async () => {
|
|
895
|
-
await e2e_setup_1.server.emit('duplicate-one-product', {
|
|
896
|
-
id: firstProduct.id,
|
|
897
|
-
name: 'duplicated mayo user',
|
|
898
|
-
}, { accessToken: userAccessToken });
|
|
899
|
-
expect(e2e_setup_1.handleSocketBroadcast).not.toHaveBeenCalled();
|
|
900
|
-
});
|
|
901
|
-
it('[DuplicateMany] should broadcast duplicated products to all clients', async () => {
|
|
902
|
-
await e2e_setup_1.server.emit('duplicate-many-product', {
|
|
903
|
-
ids: [secondProduct.id, firstProduct.id],
|
|
904
|
-
status: 'duplicated',
|
|
905
|
-
}, { accessToken: adminAccessToken, expectBroadcast: true });
|
|
906
|
-
expect(e2e_setup_1.handleSocketBroadcast).toHaveBeenCalledTimes(1);
|
|
907
|
-
expect(e2e_setup_1.handleSocketBroadcast).toHaveBeenCalledWith({
|
|
908
|
-
event: 'duplicate-many-product',
|
|
909
|
-
data: expect.arrayContaining([
|
|
910
|
-
expect.objectContaining({
|
|
911
|
-
id: expect.any(String),
|
|
912
|
-
name: secondProduct.name,
|
|
913
|
-
inStock: secondProduct.inStock,
|
|
914
|
-
status: 'duplicated',
|
|
915
|
-
}),
|
|
916
|
-
expect.objectContaining({
|
|
917
|
-
id: expect.any(String),
|
|
918
|
-
name: firstProduct.name,
|
|
919
|
-
inStock: firstProduct.inStock,
|
|
920
|
-
status: 'duplicated',
|
|
921
|
-
}),
|
|
922
|
-
]),
|
|
923
|
-
});
|
|
924
|
-
});
|
|
925
|
-
it('[DeleteMany] should broadcast deleted product ids to all clients', async () => {
|
|
926
|
-
const products = [firstProduct, secondProduct];
|
|
927
|
-
await e2e_setup_1.server.emit('delete-many-product', {
|
|
928
|
-
ids: products.map(p => p.id),
|
|
929
|
-
}, { accessToken: adminAccessToken, expectBroadcast: true });
|
|
930
|
-
expect(e2e_setup_1.handleSocketBroadcast).toHaveBeenCalledTimes(1);
|
|
931
|
-
expect(e2e_setup_1.handleSocketBroadcast).toHaveBeenCalledWith({
|
|
932
|
-
event: 'delete-many-product',
|
|
933
|
-
data: expect.arrayContaining(products.map(p => ({ id: p.id }))),
|
|
934
|
-
});
|
|
935
|
-
});
|
|
936
|
-
});
|
|
937
|
-
describe('HTTP Broadcast', () => {
|
|
938
|
-
let HbProductEntity = class HbProductEntity extends src_1.BaseEntity {
|
|
939
|
-
};
|
|
940
|
-
__decorate([
|
|
941
|
-
(0, mongoose_1.Prop)({ type: String, required: true }),
|
|
942
|
-
__metadata("design:type", String)
|
|
943
|
-
], HbProductEntity.prototype, "name", void 0);
|
|
944
|
-
__decorate([
|
|
945
|
-
(0, mongoose_1.Prop)({ type: Boolean, default: false }),
|
|
946
|
-
__metadata("design:type", Boolean)
|
|
947
|
-
], HbProductEntity.prototype, "inStock", void 0);
|
|
948
|
-
__decorate([
|
|
949
|
-
(0, mongoose_1.Prop)({ type: String }),
|
|
950
|
-
__metadata("design:type", String)
|
|
951
|
-
], HbProductEntity.prototype, "status", void 0);
|
|
952
|
-
HbProductEntity = __decorate([
|
|
953
|
-
(0, mongoose_1.Schema)({ collection: 'hb_products' })
|
|
954
|
-
], HbProductEntity);
|
|
955
|
-
const customEvent = 'hb-product-custom-event';
|
|
956
|
-
let firstProduct;
|
|
957
|
-
let secondProduct;
|
|
958
|
-
beforeEach(async () => {
|
|
959
|
-
const fixtures = async (_) => {
|
|
960
|
-
const model = await (0, utils_1.getModelFromEntity)(HbProductEntity);
|
|
961
|
-
await model.insertMany([
|
|
962
|
-
{ name: 'mayo', inStock: true },
|
|
963
|
-
{ name: 'ketchup', inStock: false },
|
|
964
|
-
]).then(([mayoProduct, ketchupProduct]) => {
|
|
965
|
-
firstProduct = mayoProduct;
|
|
966
|
-
secondProduct = ketchupProduct;
|
|
967
|
-
});
|
|
968
|
-
};
|
|
969
|
-
await initApp({
|
|
970
|
-
entity: HbProductEntity,
|
|
971
|
-
controllerOptions: {
|
|
972
|
-
apiTag: 'HbProduct',
|
|
973
|
-
path: 'hb-products',
|
|
974
|
-
isPublic: true,
|
|
975
|
-
},
|
|
976
|
-
routes: [
|
|
977
|
-
{ type: 'GetMany', isPublic: true },
|
|
978
|
-
{
|
|
979
|
-
type: 'CreateOne',
|
|
980
|
-
broadcast: { enabled: true },
|
|
981
|
-
},
|
|
982
|
-
{
|
|
983
|
-
type: 'CreateMany',
|
|
984
|
-
broadcast: { enabled: (data) => data.inStock === true },
|
|
985
|
-
},
|
|
986
|
-
{
|
|
987
|
-
type: 'UpdateOne',
|
|
988
|
-
broadcast: { enabled: true, eventName: customEvent },
|
|
989
|
-
},
|
|
990
|
-
{
|
|
991
|
-
type: 'UpdateMany',
|
|
992
|
-
broadcast: { enabled: false },
|
|
993
|
-
},
|
|
994
|
-
{
|
|
995
|
-
type: 'ReplaceOne',
|
|
996
|
-
broadcast: { enabled: true },
|
|
997
|
-
},
|
|
998
|
-
{
|
|
999
|
-
type: 'DuplicateOne',
|
|
1000
|
-
broadcast: { enabled: true },
|
|
1001
|
-
},
|
|
1002
|
-
{
|
|
1003
|
-
type: 'DuplicateMany',
|
|
1004
|
-
broadcast: { enabled: true },
|
|
1005
|
-
},
|
|
1006
|
-
{
|
|
1007
|
-
type: 'DeleteOne',
|
|
1008
|
-
broadcast: { enabled: true },
|
|
1009
|
-
},
|
|
1010
|
-
{
|
|
1011
|
-
type: 'DeleteMany',
|
|
1012
|
-
broadcast: { enabled: true },
|
|
1013
|
-
},
|
|
1014
|
-
],
|
|
1015
|
-
}, undefined, fixtures, async (app) => {
|
|
1016
|
-
app.useWebSocketAdapter(new e2e_setup_1.TestSocketAdapter(app));
|
|
1017
|
-
}, true);
|
|
1018
|
-
});
|
|
1019
|
-
it('[CreateOne] should broadcast created product to all WS clients after HTTP call', async () => {
|
|
1020
|
-
const { broadcastData } = await e2e_setup_1.server.httpWithBroadcast('post', '/hb-products', { name: 'mustard', inStock: true }, { broadcastEvent: 'create-one-hb-product' });
|
|
1021
|
-
expect(e2e_setup_1.handleSocketBroadcast).toHaveBeenCalledTimes(1);
|
|
1022
|
-
expect(e2e_setup_1.handleSocketBroadcast).toHaveBeenCalledWith({
|
|
1023
|
-
event: 'create-one-hb-product',
|
|
1024
|
-
data: expect.arrayContaining([
|
|
1025
|
-
expect.objectContaining({ name: 'mustard', inStock: true }),
|
|
1026
|
-
]),
|
|
1027
|
-
});
|
|
1028
|
-
expect(broadcastData).toEqual(expect.arrayContaining([
|
|
1029
|
-
expect.objectContaining({ name: 'mustard', inStock: true }),
|
|
1030
|
-
]));
|
|
1031
|
-
});
|
|
1032
|
-
it('[CreateMany] should broadcast only inStock products after HTTP call', async () => {
|
|
1033
|
-
const { broadcastData } = await e2e_setup_1.server.httpWithBroadcast('post', '/hb-products/many', { list: [{ name: 'pickles', inStock: true }, { name: 'onions', inStock: false }] }, { broadcastEvent: 'create-many-hb-product' });
|
|
1034
|
-
expect(e2e_setup_1.handleSocketBroadcast).toHaveBeenCalledTimes(1);
|
|
1035
|
-
expect(broadcastData).toEqual(expect.arrayContaining([expect.objectContaining({ name: 'pickles', inStock: true })]));
|
|
1036
|
-
expect(broadcastData).not.toEqual(expect.arrayContaining([expect.objectContaining({ name: 'onions' })]));
|
|
1037
|
-
});
|
|
1038
|
-
it('[UpdateOne] should broadcast updated product with custom event name after HTTP call', async () => {
|
|
1039
|
-
const { broadcastData } = await e2e_setup_1.server.httpWithBroadcast('patch', `/hb-products/${firstProduct.id}`, { name: 'updated mayo', inStock: false }, { broadcastEvent: customEvent });
|
|
1040
|
-
expect(e2e_setup_1.handleSocketBroadcast).toHaveBeenCalledTimes(1);
|
|
1041
|
-
expect(e2e_setup_1.handleSocketBroadcast).toHaveBeenCalledWith({
|
|
1042
|
-
event: customEvent,
|
|
1043
|
-
data: expect.arrayContaining([
|
|
1044
|
-
expect.objectContaining({ id: firstProduct.id, name: 'updated mayo', inStock: false }),
|
|
1045
|
-
]),
|
|
1046
|
-
});
|
|
1047
|
-
expect(broadcastData).toEqual(expect.arrayContaining([
|
|
1048
|
-
expect.objectContaining({ name: 'updated mayo' }),
|
|
1049
|
-
]));
|
|
1050
|
-
});
|
|
1051
|
-
it('[ReplaceOne] should broadcast replaced product after HTTP call', async () => {
|
|
1052
|
-
const { broadcastData } = await e2e_setup_1.server.httpWithBroadcast('put', `/hb-products/${firstProduct.id}`, { name: 'replaced mayo', inStock: false }, { broadcastEvent: 'replace-one-hb-product' });
|
|
1053
|
-
expect(e2e_setup_1.handleSocketBroadcast).toHaveBeenCalledTimes(1);
|
|
1054
|
-
expect(broadcastData).toEqual(expect.arrayContaining([
|
|
1055
|
-
expect.objectContaining({ id: firstProduct.id, name: 'replaced mayo', inStock: false }),
|
|
1056
|
-
]));
|
|
1057
|
-
});
|
|
1058
|
-
it('[DuplicateOne] should broadcast duplicated product after HTTP call', async () => {
|
|
1059
|
-
const { broadcastData } = await e2e_setup_1.server.httpWithBroadcast('post', `/hb-products/duplicate/${firstProduct.id}`, { name: 'duplicated mayo' }, { broadcastEvent: 'duplicate-one-hb-product' });
|
|
1060
|
-
expect(e2e_setup_1.handleSocketBroadcast).toHaveBeenCalledTimes(1);
|
|
1061
|
-
expect(broadcastData).toEqual(expect.arrayContaining([
|
|
1062
|
-
expect.objectContaining({ name: 'duplicated mayo', inStock: firstProduct.inStock }),
|
|
1063
|
-
]));
|
|
1064
|
-
});
|
|
1065
|
-
it('[DuplicateMany] should broadcast duplicated products after HTTP call', async () => {
|
|
1066
|
-
const { broadcastData } = await e2e_setup_1.server.httpWithBroadcast('post', '/hb-products/duplicate', { status: 'dup' }, {
|
|
1067
|
-
broadcastEvent: 'duplicate-many-hb-product',
|
|
1068
|
-
query: { ids: [firstProduct.id, secondProduct.id] },
|
|
1069
|
-
});
|
|
1070
|
-
expect(e2e_setup_1.handleSocketBroadcast).toHaveBeenCalledTimes(1);
|
|
1071
|
-
expect(broadcastData.length).toBeGreaterThanOrEqual(2);
|
|
1072
|
-
});
|
|
1073
|
-
it('[DeleteOne] should broadcast deleted product id to all WS clients after HTTP call', async () => {
|
|
1074
|
-
const { broadcastData } = await e2e_setup_1.server.httpWithBroadcast('delete', `/hb-products/${firstProduct.id}`, {}, { broadcastEvent: 'delete-one-hb-product' });
|
|
1075
|
-
expect(e2e_setup_1.handleSocketBroadcast).toHaveBeenCalledTimes(1);
|
|
1076
|
-
expect(e2e_setup_1.handleSocketBroadcast).toHaveBeenCalledWith({
|
|
1077
|
-
event: 'delete-one-hb-product',
|
|
1078
|
-
data: expect.arrayContaining([expect.objectContaining({ id: firstProduct.id })]),
|
|
1079
|
-
});
|
|
1080
|
-
expect(broadcastData).toEqual(expect.arrayContaining([{ id: firstProduct.id }]));
|
|
1081
|
-
});
|
|
1082
|
-
it('[DeleteMany] should broadcast deleted product ids to all WS clients after HTTP call', async () => {
|
|
1083
|
-
const ids = [firstProduct.id, secondProduct.id];
|
|
1084
|
-
const { broadcastData } = await e2e_setup_1.server.httpWithBroadcast('delete', '/hb-products', {}, {
|
|
1085
|
-
broadcastEvent: 'delete-many-hb-product',
|
|
1086
|
-
query: { ids },
|
|
1087
|
-
});
|
|
1088
|
-
expect(e2e_setup_1.handleSocketBroadcast).toHaveBeenCalledTimes(1);
|
|
1089
|
-
expect(broadcastData).toEqual(expect.arrayContaining(ids.map(id => ({ id }))));
|
|
1090
|
-
});
|
|
1091
|
-
it('[UpdateMany] should NOT broadcast when enabled is false', async () => {
|
|
1092
|
-
const { body: products } = await e2e_setup_1.server.get('/hb-products');
|
|
1093
|
-
const ids = products.map((p) => p.id);
|
|
1094
|
-
const response = await e2e_setup_1.server.patch(`/hb-products/many?ids=${ids.join('&ids=')}`, { status: 'updated' });
|
|
1095
|
-
expect(response).toBeDefined();
|
|
1096
|
-
expect(e2e_setup_1.handleSocketBroadcast).not.toHaveBeenCalled();
|
|
1097
|
-
});
|
|
1098
|
-
});
|
|
1099
|
-
});
|
|
1100
|
-
//# sourceMappingURL=dynamic-api-for-feature.e2e-spec.js.map
|