@openora/core 0.4.1-canary.37 → 0.4.1-canary.39
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/dist/.tsbuildinfo +1 -1
- package/dist/admin-console/__tests__/backoffice.router.test.js +67 -51
- package/dist/admin-console/__tests__/backoffice.router.test.js.map +1 -1
- package/dist/admin-console/__tests__/backoffice.service.test.js +1 -13
- package/dist/admin-console/__tests__/backoffice.service.test.js.map +1 -1
- package/dist/analytics/__tests__/analytics.contract.test.js +12 -0
- package/dist/analytics/__tests__/analytics.contract.test.js.map +1 -1
- package/dist/analytics/__tests__/financial-analytics.service.test.js +3 -3
- package/dist/analytics/__tests__/financial-analytics.service.test.js.map +1 -1
- package/dist/analytics/service/financial-analytics.service.d.ts.map +1 -1
- package/dist/analytics/service/financial-analytics.service.js +14 -17
- package/dist/analytics/service/financial-analytics.service.js.map +1 -1
- package/dist/analytics/service/funnel-analytics.service.d.ts.map +1 -1
- package/dist/analytics/service/funnel-analytics.service.js +8 -11
- package/dist/analytics/service/funnel-analytics.service.js.map +1 -1
- package/dist/audit/__tests__/audit.service.test.js +128 -251
- package/dist/audit/__tests__/audit.service.test.js.map +1 -1
- package/dist/casino/gaming/__tests__/gaming.service.test.js +83 -89
- package/dist/casino/gaming/__tests__/gaming.service.test.js.map +1 -1
- package/dist/casino/lobby/__tests__/lobby.cache.test.js +42 -33
- package/dist/casino/lobby/__tests__/lobby.cache.test.js.map +1 -1
- package/dist/cms/__tests__/cms.reads.test.js +59 -80
- package/dist/cms/__tests__/cms.reads.test.js.map +1 -1
- package/dist/cms/__tests__/cms.router.test.js +62 -20
- package/dist/cms/__tests__/cms.router.test.js.map +1 -1
- package/dist/cms/__tests__/cms.service.test.js +116 -14
- package/dist/cms/__tests__/cms.service.test.js.map +1 -1
- package/dist/common/errors/__tests__/errors.mapper.test.d.ts +2 -0
- package/dist/common/errors/__tests__/errors.mapper.test.d.ts.map +1 -0
- package/dist/common/errors/__tests__/errors.mapper.test.js +59 -0
- package/dist/common/errors/__tests__/errors.mapper.test.js.map +1 -0
- package/dist/compliance/__tests__/assert.test.d.ts +2 -0
- package/dist/compliance/__tests__/assert.test.d.ts.map +1 -0
- package/dist/compliance/__tests__/assert.test.js +34 -0
- package/dist/compliance/__tests__/assert.test.js.map +1 -0
- package/dist/compliance/__tests__/compliance.service.test.js +149 -84
- package/dist/compliance/__tests__/compliance.service.test.js.map +1 -1
- package/dist/compliance/__tests__/kyc.service.test.js +247 -155
- package/dist/compliance/__tests__/kyc.service.test.js.map +1 -1
- package/dist/compliance/__tests__/limits.contract.test.d.ts +2 -0
- package/dist/compliance/__tests__/limits.contract.test.d.ts.map +1 -0
- package/dist/compliance/__tests__/limits.contract.test.js +43 -0
- package/dist/compliance/__tests__/limits.contract.test.js.map +1 -0
- package/dist/compliance/__tests__/rg-monitoring.service.test.js +256 -101
- package/dist/compliance/__tests__/rg-monitoring.service.test.js.map +1 -1
- package/dist/compliance/__tests__/rg.contract.test.js +1 -20
- package/dist/compliance/__tests__/rg.contract.test.js.map +1 -1
- package/dist/compliance/__tests__/rg.router.test.js +113 -65
- package/dist/compliance/__tests__/rg.router.test.js.map +1 -1
- package/dist/compliance/__tests__/rg.service.test.js +277 -235
- package/dist/compliance/__tests__/rg.service.test.js.map +1 -1
- package/dist/compliance/service/rg-monitoring.service.d.ts.map +1 -1
- package/dist/compliance/service/rg-monitoring.service.js +11 -8
- package/dist/compliance/service/rg-monitoring.service.js.map +1 -1
- package/dist/contracts/__tests__/compose-contract.test.d.ts +2 -0
- package/dist/contracts/__tests__/compose-contract.test.d.ts.map +1 -0
- package/dist/contracts/__tests__/compose-contract.test.js +27 -0
- package/dist/contracts/__tests__/compose-contract.test.js.map +1 -0
- package/dist/contracts/adapters/__tests__/token.test.d.ts +2 -0
- package/dist/contracts/adapters/__tests__/token.test.d.ts.map +1 -0
- package/dist/contracts/adapters/__tests__/token.test.js +14 -0
- package/dist/contracts/adapters/__tests__/token.test.js.map +1 -0
- package/dist/contracts/schemas/__tests__/events.test.d.ts +2 -0
- package/dist/contracts/schemas/__tests__/events.test.d.ts.map +1 -0
- package/dist/contracts/schemas/__tests__/events.test.js +51 -0
- package/dist/contracts/schemas/__tests__/events.test.js.map +1 -0
- package/dist/contracts/schemas/__tests__/igaming-config.test.d.ts +2 -0
- package/dist/contracts/schemas/__tests__/igaming-config.test.d.ts.map +1 -0
- package/dist/contracts/schemas/__tests__/igaming-config.test.js +38 -0
- package/dist/contracts/schemas/__tests__/igaming-config.test.js.map +1 -0
- package/dist/contracts/schemas/reporting.d.ts +7 -2
- package/dist/contracts/schemas/reporting.d.ts.map +1 -1
- package/dist/contracts/schemas/reporting.js +2 -1
- package/dist/contracts/schemas/reporting.js.map +1 -1
- package/dist/engagement/chat/__tests__/chat.service.test.js +524 -364
- package/dist/engagement/chat/__tests__/chat.service.test.js.map +1 -1
- package/dist/engagement/notifications/__tests__/notifications.service.test.js +125 -68
- package/dist/engagement/notifications/__tests__/notifications.service.test.js.map +1 -1
- package/dist/iam/__tests__/iam.service.test.js +367 -596
- package/dist/iam/__tests__/iam.service.test.js.map +1 -1
- package/dist/pam/identity/__tests__/admin-user-directory.test.js +144 -68
- package/dist/pam/identity/__tests__/admin-user-directory.test.js.map +1 -1
- package/dist/pam/identity/__tests__/identity.rate-limit.test.js +33 -22
- package/dist/pam/identity/__tests__/identity.rate-limit.test.js.map +1 -1
- package/dist/pam/identity/__tests__/identity.service.test.js +217 -298
- package/dist/pam/identity/__tests__/identity.service.test.js.map +1 -1
- package/dist/pam/identity/__tests__/login-enforcement.service.test.js +97 -32
- package/dist/pam/identity/__tests__/login-enforcement.service.test.js.map +1 -1
- package/dist/pam/identity/__tests__/phone-login.service.test.js +163 -134
- package/dist/pam/identity/__tests__/phone-login.service.test.js.map +1 -1
- package/dist/pam/identity/__tests__/rg-guard.test.d.ts +2 -0
- package/dist/pam/identity/__tests__/rg-guard.test.d.ts.map +1 -0
- package/dist/pam/identity/__tests__/rg-guard.test.js +21 -0
- package/dist/pam/identity/__tests__/rg-guard.test.js.map +1 -0
- package/dist/pam/player-management/__tests__/kyc-status-writer.test.js +73 -26
- package/dist/pam/player-management/__tests__/kyc-status-writer.test.js.map +1 -1
- package/dist/pam/player-management/__tests__/player.router.test.js +63 -46
- package/dist/pam/player-management/__tests__/player.router.test.js.map +1 -1
- package/dist/pam/player-management/__tests__/player.service.test.js +207 -111
- package/dist/pam/player-management/__tests__/player.service.test.js.map +1 -1
- package/dist/pam/profile/__tests__/profile.service.test.js +89 -41
- package/dist/pam/profile/__tests__/profile.service.test.js.map +1 -1
- package/dist/pam/shared/__tests__/shared-mappers.test.d.ts +2 -0
- package/dist/pam/shared/__tests__/shared-mappers.test.d.ts.map +1 -0
- package/dist/pam/shared/__tests__/shared-mappers.test.js +55 -0
- package/dist/pam/shared/__tests__/shared-mappers.test.js.map +1 -0
- package/dist/pam/tag/__tests__/get-active-tag-keys.test.js +72 -30
- package/dist/pam/tag/__tests__/get-active-tag-keys.test.js.map +1 -1
- package/dist/pam/tag/__tests__/tag-evaluation.service.test.js +308 -235
- package/dist/pam/tag/__tests__/tag-evaluation.service.test.js.map +1 -1
- package/dist/pam/tag/__tests__/tag-rule.service.test.js +136 -140
- package/dist/pam/tag/__tests__/tag-rule.service.test.js.map +1 -1
- package/dist/pam/tag/__tests__/tag.router.test.js +76 -25
- package/dist/pam/tag/__tests__/tag.router.test.js.map +1 -1
- package/dist/pam/tag/__tests__/tag.service.test.js +224 -247
- package/dist/pam/tag/__tests__/tag.service.test.js.map +1 -1
- package/dist/server/auth/__tests__/admin-guard.test.js +107 -117
- package/dist/server/auth/__tests__/admin-guard.test.js.map +1 -1
- package/dist/server/auth/__tests__/permission-levels.test.d.ts +2 -0
- package/dist/server/auth/__tests__/permission-levels.test.d.ts.map +1 -0
- package/dist/server/auth/__tests__/permission-levels.test.js +89 -0
- package/dist/server/auth/__tests__/permission-levels.test.js.map +1 -0
- package/dist/server/auth/__tests__/session-resolver.test.js +45 -13
- package/dist/server/auth/__tests__/session-resolver.test.js.map +1 -1
- package/dist/server/db/__tests__/query-helpers.test.js +72 -1
- package/dist/server/db/__tests__/query-helpers.test.js.map +1 -1
- package/dist/server/db/outbox/__tests__/relay.test.js +74 -81
- package/dist/server/db/outbox/__tests__/relay.test.js.map +1 -1
- package/dist/server/kernel/__tests__/bullmq-job-queue.test.js +204 -154
- package/dist/server/kernel/__tests__/bullmq-job-queue.test.js.map +1 -1
- package/dist/server/kernel/__tests__/cache.test.js +26 -13
- package/dist/server/kernel/__tests__/cache.test.js.map +1 -1
- package/dist/server/kernel/__tests__/domain-error.test.d.ts +2 -0
- package/dist/server/kernel/__tests__/domain-error.test.d.ts.map +1 -0
- package/dist/server/kernel/__tests__/domain-error.test.js +35 -0
- package/dist/server/kernel/__tests__/domain-error.test.js.map +1 -0
- package/dist/server/kernel/__tests__/error-reporter.test.d.ts +2 -0
- package/dist/server/kernel/__tests__/error-reporter.test.d.ts.map +1 -0
- package/dist/server/kernel/__tests__/error-reporter.test.js +52 -0
- package/dist/server/kernel/__tests__/error-reporter.test.js.map +1 -0
- package/dist/server/kernel/__tests__/event-bus.test.js +60 -20
- package/dist/server/kernel/__tests__/event-bus.test.js.map +1 -1
- package/dist/server/kernel/__tests__/orpc-error-map.test.d.ts +2 -0
- package/dist/server/kernel/__tests__/orpc-error-map.test.d.ts.map +1 -0
- package/dist/server/kernel/__tests__/orpc-error-map.test.js +54 -0
- package/dist/server/kernel/__tests__/orpc-error-map.test.js.map +1 -0
- package/dist/server/kernel/__tests__/platform-config-loader.test.d.ts +2 -0
- package/dist/server/kernel/__tests__/platform-config-loader.test.d.ts.map +1 -0
- package/dist/server/kernel/__tests__/platform-config-loader.test.js +112 -0
- package/dist/server/kernel/__tests__/platform-config-loader.test.js.map +1 -0
- package/dist/server/kernel/__tests__/rate-limiter.test.js +22 -13
- package/dist/server/kernel/__tests__/rate-limiter.test.js.map +1 -1
- package/dist/server/kernel/__tests__/realtime-transport.test.d.ts.map +1 -0
- package/dist/{testing/fakes → server/kernel}/__tests__/realtime-transport.test.js.map +1 -1
- package/dist/server/kernel/__tests__/redis-cache.test.js +34 -34
- package/dist/server/kernel/__tests__/redis-cache.test.js.map +1 -1
- package/dist/server/kernel/__tests__/redis-rate-limiter.test.js +49 -44
- package/dist/server/kernel/__tests__/redis-rate-limiter.test.js.map +1 -1
- package/dist/server/kernel/__tests__/redis-streams-broker.test.js +141 -262
- package/dist/server/kernel/__tests__/redis-streams-broker.test.js.map +1 -1
- package/dist/server/kernel/__tests__/request-context.test.d.ts +2 -0
- package/dist/server/kernel/__tests__/request-context.test.d.ts.map +1 -0
- package/dist/server/kernel/__tests__/request-context.test.js +64 -0
- package/dist/server/kernel/__tests__/request-context.test.js.map +1 -0
- package/dist/server/kernel/__tests__/router-utils.test.d.ts +2 -0
- package/dist/server/kernel/__tests__/router-utils.test.d.ts.map +1 -0
- package/dist/server/kernel/__tests__/router-utils.test.js +80 -0
- package/dist/server/kernel/__tests__/router-utils.test.js.map +1 -0
- package/dist/server/kernel/bullmq-job-queue.d.ts.map +1 -1
- package/dist/server/kernel/bullmq-job-queue.js +8 -2
- package/dist/server/kernel/bullmq-job-queue.js.map +1 -1
- package/dist/server/runtime/__tests__/create-app.test.js +26 -18
- package/dist/server/runtime/__tests__/create-app.test.js.map +1 -1
- package/dist/testing/index.d.ts +2 -6
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +2 -10
- package/dist/testing/index.js.map +1 -1
- package/dist/testing/mock.d.ts +28 -16
- package/dist/testing/mock.d.ts.map +1 -1
- package/dist/testing/mock.js +58 -37
- package/dist/testing/mock.js.map +1 -1
- package/dist/testing/real-infra.d.ts +47 -0
- package/dist/testing/real-infra.d.ts.map +1 -0
- package/dist/testing/real-infra.js +122 -0
- package/dist/testing/real-infra.js.map +1 -0
- package/dist/wallet/__tests__/admin-reporting.test.js +201 -90
- package/dist/wallet/__tests__/admin-reporting.test.js.map +1 -1
- package/dist/wallet/__tests__/rail-for.test.d.ts +2 -0
- package/dist/wallet/__tests__/rail-for.test.d.ts.map +1 -0
- package/dist/wallet/__tests__/rail-for.test.js +22 -0
- package/dist/wallet/__tests__/rail-for.test.js.map +1 -0
- package/dist/wallet/__tests__/wallet-auto-rule.router.test.js +82 -63
- package/dist/wallet/__tests__/wallet-auto-rule.router.test.js.map +1 -1
- package/dist/wallet/__tests__/wallet-auto-withdrawal.test.js +414 -437
- package/dist/wallet/__tests__/wallet-auto-withdrawal.test.js.map +1 -1
- package/dist/wallet/__tests__/wallet-commands.service.test.js +116 -155
- package/dist/wallet/__tests__/wallet-commands.service.test.js.map +1 -1
- package/dist/wallet/__tests__/wallet-kyc-gate.test.js +63 -42
- package/dist/wallet/__tests__/wallet-kyc-gate.test.js.map +1 -1
- package/dist/wallet/__tests__/wallet-webhook.router.test.js +129 -51
- package/dist/wallet/__tests__/wallet-webhook.router.test.js.map +1 -1
- package/dist/wallet/__tests__/wallet.rate-limit.test.js +74 -21
- package/dist/wallet/__tests__/wallet.rate-limit.test.js.map +1 -1
- package/dist/wallet/__tests__/wallet.router.test.js +56 -36
- package/dist/wallet/__tests__/wallet.router.test.js.map +1 -1
- package/dist/wallet/__tests__/wallet.service.test.js +623 -887
- package/dist/wallet/__tests__/wallet.service.test.js.map +1 -1
- package/package.json +1 -2
- package/dist/casino/lobby/__tests__/lobby.service.test.d.ts +0 -2
- package/dist/casino/lobby/__tests__/lobby.service.test.d.ts.map +0 -1
- package/dist/casino/lobby/__tests__/lobby.service.test.js +0 -11
- package/dist/casino/lobby/__tests__/lobby.service.test.js.map +0 -1
- package/dist/contracts/schemas/__tests__/identity-schemas.test.d.ts +0 -2
- package/dist/contracts/schemas/__tests__/identity-schemas.test.d.ts.map +0 -1
- package/dist/contracts/schemas/__tests__/identity-schemas.test.js +0 -43
- package/dist/contracts/schemas/__tests__/identity-schemas.test.js.map +0 -1
- package/dist/testing/fakes/__tests__/cache.test.d.ts +0 -2
- package/dist/testing/fakes/__tests__/cache.test.d.ts.map +0 -1
- package/dist/testing/fakes/__tests__/cache.test.js +0 -89
- package/dist/testing/fakes/__tests__/cache.test.js.map +0 -1
- package/dist/testing/fakes/__tests__/job-queue.test.d.ts +0 -2
- package/dist/testing/fakes/__tests__/job-queue.test.d.ts.map +0 -1
- package/dist/testing/fakes/__tests__/job-queue.test.js +0 -135
- package/dist/testing/fakes/__tests__/job-queue.test.js.map +0 -1
- package/dist/testing/fakes/__tests__/rate-limiter.test.d.ts +0 -2
- package/dist/testing/fakes/__tests__/rate-limiter.test.d.ts.map +0 -1
- package/dist/testing/fakes/__tests__/rate-limiter.test.js +0 -83
- package/dist/testing/fakes/__tests__/rate-limiter.test.js.map +0 -1
- package/dist/testing/fakes/__tests__/realtime-authorizer.test.d.ts +0 -2
- package/dist/testing/fakes/__tests__/realtime-authorizer.test.d.ts.map +0 -1
- package/dist/testing/fakes/__tests__/realtime-authorizer.test.js +0 -19
- package/dist/testing/fakes/__tests__/realtime-authorizer.test.js.map +0 -1
- package/dist/testing/fakes/__tests__/realtime-transport.test.d.ts.map +0 -1
- package/dist/testing/fakes/cache.d.ts +0 -14
- package/dist/testing/fakes/cache.d.ts.map +0 -1
- package/dist/testing/fakes/cache.js +0 -56
- package/dist/testing/fakes/cache.js.map +0 -1
- package/dist/testing/fakes/event-bus.d.ts +0 -17
- package/dist/testing/fakes/event-bus.d.ts.map +0 -1
- package/dist/testing/fakes/event-bus.js +0 -30
- package/dist/testing/fakes/event-bus.js.map +0 -1
- package/dist/testing/fakes/job-queue.d.ts +0 -40
- package/dist/testing/fakes/job-queue.d.ts.map +0 -1
- package/dist/testing/fakes/job-queue.js +0 -200
- package/dist/testing/fakes/job-queue.js.map +0 -1
- package/dist/testing/fakes/rate-limiter.d.ts +0 -11
- package/dist/testing/fakes/rate-limiter.d.ts.map +0 -1
- package/dist/testing/fakes/rate-limiter.js +0 -39
- package/dist/testing/fakes/rate-limiter.js.map +0 -1
- package/dist/testing/fakes/realtime-authorizer.d.ts +0 -10
- package/dist/testing/fakes/realtime-authorizer.d.ts.map +0 -1
- package/dist/testing/fakes/realtime-authorizer.js +0 -10
- package/dist/testing/fakes/realtime-authorizer.js.map +0 -1
- package/dist/testing/fakes/realtime-transport.d.ts +0 -2
- package/dist/testing/fakes/realtime-transport.d.ts.map +0 -1
- package/dist/testing/fakes/realtime-transport.js +0 -2
- package/dist/testing/fakes/realtime-transport.js.map +0 -1
- /package/dist/{testing/fakes → server/kernel}/__tests__/realtime-transport.test.d.ts +0 -0
- /package/dist/{testing/fakes → server/kernel}/__tests__/realtime-transport.test.js +0 -0
|
@@ -1,284 +1,326 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { describe, it, expect, vi, beforeAll, afterAll, beforeEach } from 'vitest';
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { eq, sql } from 'drizzle-orm';
|
|
4
|
+
import { createTestDb } from '@openora/core/testing';
|
|
5
|
+
import { mock, makeEventBus } from '../../testing/mock.js';
|
|
6
|
+
import { migrate } from '../migrate.js';
|
|
4
7
|
import { userLimit, rgExclusion } from '../schema/index.js';
|
|
5
8
|
import { RgService, ActiveExclusionError, PermanentExclusionLiftError, ExclusionPeriodNotElapsedError, ExclusionNotFoundError, } from '../service/rg.service.js';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// `transaction(cb)` runs inline; `insert`/`update` `.returning()` yield `returning`.
|
|
9
|
-
function routingDb(cfg) {
|
|
10
|
-
const queues = new Map([
|
|
11
|
-
[rgExclusion, [...(cfg.rgExclusion ?? [])]],
|
|
12
|
-
[userLimit, [...(cfg.userLimit ?? [])]],
|
|
13
|
-
]);
|
|
14
|
-
function selectChain() {
|
|
15
|
-
let table;
|
|
16
|
-
const c = {
|
|
17
|
-
from: (t) => {
|
|
18
|
-
table = t;
|
|
19
|
-
return c;
|
|
20
|
-
},
|
|
21
|
-
innerJoin: () => c,
|
|
22
|
-
where: () => c,
|
|
23
|
-
orderBy: () => c,
|
|
24
|
-
limit: () => c,
|
|
25
|
-
offset: () => c,
|
|
26
|
-
then: (resolve) => {
|
|
27
|
-
const q = queues.get(table);
|
|
28
|
-
resolve(q && q.length > 0 ? q.shift() : []);
|
|
29
|
-
},
|
|
30
|
-
};
|
|
31
|
-
return c;
|
|
32
|
-
}
|
|
33
|
-
const returning = () => Promise.resolve(cfg.returning ?? []);
|
|
34
|
-
const db = {
|
|
35
|
-
transaction: (cb) => cb(db),
|
|
36
|
-
select: () => selectChain(),
|
|
37
|
-
insert: () => {
|
|
38
|
-
const c = {
|
|
39
|
-
values: () => c,
|
|
40
|
-
onConflictDoUpdate: () => c,
|
|
41
|
-
returning,
|
|
42
|
-
then: (r) => r(undefined),
|
|
43
|
-
};
|
|
44
|
-
return c;
|
|
45
|
-
},
|
|
46
|
-
update: () => {
|
|
47
|
-
const c = {
|
|
48
|
-
set: () => c,
|
|
49
|
-
where: () => c,
|
|
50
|
-
returning,
|
|
51
|
-
then: (r) => r(undefined),
|
|
52
|
-
};
|
|
53
|
-
return c;
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
return mockDb(db);
|
|
57
|
-
}
|
|
58
|
-
function makeEvents() {
|
|
59
|
-
return { emit: vi.fn(), on: vi.fn() };
|
|
60
|
-
}
|
|
61
|
-
function makeEnforcement() {
|
|
9
|
+
let db;
|
|
10
|
+
function makeNotifier(email = 'player@example.com') {
|
|
62
11
|
return {
|
|
63
|
-
|
|
64
|
-
|
|
12
|
+
email: mock({ send: vi.fn(async () => undefined) }),
|
|
13
|
+
directory: mock({
|
|
14
|
+
lookupPlayers: vi.fn(async (ids) => ids.map((userId) => mock({ userId, email, language: 'en' }))),
|
|
15
|
+
}),
|
|
16
|
+
templateRenderer: mock({
|
|
17
|
+
render: vi.fn(async () => ({ subject: 'subject', body: 'body' })),
|
|
18
|
+
}),
|
|
65
19
|
};
|
|
66
20
|
}
|
|
67
|
-
function
|
|
21
|
+
function makeService(notifier) {
|
|
22
|
+
const events = makeEventBus();
|
|
23
|
+
const enforcement = mock({
|
|
24
|
+
block: vi.fn(async () => undefined),
|
|
25
|
+
unblock: vi.fn(async () => undefined),
|
|
26
|
+
});
|
|
68
27
|
const svc = new RgService({
|
|
69
|
-
drizzle: db,
|
|
70
|
-
events
|
|
28
|
+
drizzle: db.drizzle,
|
|
29
|
+
events,
|
|
71
30
|
loginEnforcement: enforcement,
|
|
72
|
-
email: null,
|
|
73
|
-
directory: null,
|
|
31
|
+
email: notifier?.email ?? null,
|
|
32
|
+
directory: notifier?.directory ?? null,
|
|
33
|
+
templateRenderer: notifier?.templateRenderer ?? null,
|
|
74
34
|
});
|
|
75
35
|
return { svc, events, enforcement };
|
|
76
36
|
}
|
|
77
|
-
function
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
userId:
|
|
37
|
+
async function seedExclusion(overrides) {
|
|
38
|
+
const [row] = await db.drizzle.db
|
|
39
|
+
.insert(rgExclusion)
|
|
40
|
+
.values({
|
|
41
|
+
userId: randomUUID(),
|
|
82
42
|
kind: 'self_exclusion',
|
|
83
43
|
status: 'active',
|
|
84
44
|
reason: 'gambling concern',
|
|
85
45
|
isPermanent: false,
|
|
86
|
-
|
|
87
|
-
expiresAt: null,
|
|
88
|
-
liftedAt: null,
|
|
89
|
-
liftedReason: null,
|
|
90
|
-
liftedBy: null,
|
|
91
|
-
createdBy: 'admin-1',
|
|
92
|
-
createdAt: now,
|
|
93
|
-
updatedAt: now,
|
|
46
|
+
createdBy: randomUUID(),
|
|
94
47
|
...overrides,
|
|
95
|
-
}
|
|
48
|
+
})
|
|
49
|
+
.returning();
|
|
50
|
+
return row;
|
|
96
51
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
const
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const { svc, events } =
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
})
|
|
52
|
+
async function exclusionsOf(userId) {
|
|
53
|
+
return db.drizzle.db.select().from(rgExclusion).where(eq(rgExclusion.userId, userId));
|
|
54
|
+
}
|
|
55
|
+
const HOURS = 3600_000;
|
|
56
|
+
const future = () => new Date(Date.now() + 200 * 24 * HOURS);
|
|
57
|
+
const past = () => new Date(Date.now() - 1000);
|
|
58
|
+
beforeAll(async () => {
|
|
59
|
+
db = await createTestDb([migrate]);
|
|
60
|
+
});
|
|
61
|
+
afterAll(async () => {
|
|
62
|
+
await db.drop();
|
|
63
|
+
});
|
|
64
|
+
beforeEach(async () => {
|
|
65
|
+
await db.drizzle.db.execute(sql `TRUNCATE ${rgExclusion}, ${userLimit} RESTART IDENTITY CASCADE`);
|
|
66
|
+
});
|
|
67
|
+
describe('RgService.setPlayerLimit (real PG)', () => {
|
|
68
|
+
it('persists a first limit and reports no prior amount', async () => {
|
|
69
|
+
const { svc, events } = makeService();
|
|
70
|
+
const userId = randomUUID();
|
|
71
|
+
const actorId = randomUUID();
|
|
72
|
+
const dto = await svc.setPlayerLimit(userId, { userId, type: 'deposit', amount: '100', minutes: null, period: 'daily' }, actorId);
|
|
73
|
+
expect(Number(dto.amount)).toBe(100);
|
|
74
|
+
expect(events.emit).toHaveBeenCalledWith('rg.limit.set', expect.objectContaining({ userId, actorId, amount: '100', previousAmount: null }));
|
|
75
|
+
});
|
|
76
|
+
it('upserts on the same type and period, carrying the prior amount into the event', async () => {
|
|
77
|
+
const { svc, events } = makeService();
|
|
78
|
+
const userId = randomUUID();
|
|
79
|
+
const actorId = randomUUID();
|
|
80
|
+
await svc.setPlayerLimit(userId, { userId, type: 'deposit', amount: '50', minutes: null, period: 'daily' }, actorId);
|
|
81
|
+
await svc.setPlayerLimit(userId, { userId, type: 'deposit', amount: '100', minutes: null, period: 'daily' }, actorId);
|
|
82
|
+
const rows = await db.drizzle.db.select().from(userLimit).where(eq(userLimit.userId, userId));
|
|
83
|
+
expect(rows).toHaveLength(1);
|
|
84
|
+
expect(Number(rows[0]?.amount)).toBe(100);
|
|
85
|
+
expect(events.emit).toHaveBeenLastCalledWith('rg.limit.set', expect.objectContaining({ previousAmount: '50.00' }));
|
|
86
|
+
});
|
|
87
|
+
it('keeps a different period as its own row', async () => {
|
|
88
|
+
const { svc } = makeService();
|
|
89
|
+
const userId = randomUUID();
|
|
90
|
+
const actorId = randomUUID();
|
|
91
|
+
await svc.setPlayerLimit(userId, { userId, type: 'deposit', amount: '50', minutes: null, period: 'daily' }, actorId);
|
|
92
|
+
await svc.setPlayerLimit(userId, { userId, type: 'deposit', amount: '500', minutes: null, period: 'monthly' }, actorId);
|
|
93
|
+
const rows = await db.drizzle.db.select().from(userLimit).where(eq(userLimit.userId, userId));
|
|
94
|
+
expect(rows).toHaveLength(2);
|
|
95
|
+
});
|
|
96
|
+
it('stores minutes and no amount for a session limit', async () => {
|
|
97
|
+
const { svc } = makeService();
|
|
98
|
+
const userId = randomUUID();
|
|
99
|
+
const dto = await svc.setPlayerLimit(userId, { userId, type: 'session', amount: null, minutes: 60, period: 'session' }, randomUUID());
|
|
100
|
+
expect(dto).toMatchObject({ minutes: 60, amount: null });
|
|
101
|
+
});
|
|
102
|
+
it('emails the player when a mail port, directory, and template renderer are bound', async () => {
|
|
103
|
+
const notifier = makeNotifier();
|
|
104
|
+
const { svc } = makeService(notifier);
|
|
105
|
+
const userId = randomUUID();
|
|
106
|
+
await svc.setPlayerLimit(userId, { userId, type: 'deposit', amount: '100', minutes: null, period: 'daily' }, randomUUID());
|
|
107
|
+
expect(notifier.templateRenderer.render).toHaveBeenCalled();
|
|
108
|
+
expect(notifier.email.send).toHaveBeenCalledWith(expect.objectContaining({ to: 'player@example.com', subject: 'subject', body: 'body' }));
|
|
109
|
+
});
|
|
110
|
+
it('swallows a notification failure once the limit has committed', async () => {
|
|
111
|
+
const notifier = makeNotifier();
|
|
112
|
+
vi.mocked(notifier.email.send).mockRejectedValueOnce(new Error('smtp down'));
|
|
113
|
+
const { svc } = makeService(notifier);
|
|
114
|
+
const userId = randomUUID();
|
|
115
|
+
await expect(svc.setPlayerLimit(userId, { userId, type: 'deposit', amount: '100', minutes: null, period: 'daily' }, randomUUID())).resolves.toMatchObject({ period: 'daily' });
|
|
116
|
+
const rows = await db.drizzle.db.select().from(userLimit).where(eq(userLimit.userId, userId));
|
|
117
|
+
expect(rows).toHaveLength(1);
|
|
123
118
|
});
|
|
124
119
|
});
|
|
125
|
-
describe('RgService.activateCoolingOff', () => {
|
|
126
|
-
it('
|
|
127
|
-
const
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
await svc.activateCoolingOff(USER, { userId: USER, durationHours: 24, reason: 'break' }, ADMIN);
|
|
134
|
-
expect(enforcement.block).toHaveBeenCalledWith(USER, { until: expect.any(Date) });
|
|
120
|
+
describe('RgService.activateCoolingOff (real PG)', () => {
|
|
121
|
+
it('stores an active row and blocks login until its expiry', async () => {
|
|
122
|
+
const { svc, events, enforcement } = makeService();
|
|
123
|
+
const userId = randomUUID();
|
|
124
|
+
await svc.activateCoolingOff(userId, { userId, durationHours: 24, reason: 'break' }, randomUUID());
|
|
125
|
+
const [row] = await exclusionsOf(userId);
|
|
126
|
+
expect(row).toMatchObject({ kind: 'cooling_off', status: 'active', isPermanent: false });
|
|
127
|
+
expect(enforcement.block).toHaveBeenCalledWith(userId, { until: expect.any(Date) });
|
|
135
128
|
expect(enforcement.unblock).not.toHaveBeenCalled();
|
|
136
|
-
expect(events.emit).toHaveBeenCalledWith('rg.cooling_off.activated', expect.objectContaining({ userId
|
|
129
|
+
expect(events.emit).toHaveBeenCalledWith('rg.cooling_off.activated', expect.objectContaining({ userId }));
|
|
137
130
|
});
|
|
138
|
-
it('rejects
|
|
139
|
-
const { svc, enforcement } =
|
|
140
|
-
|
|
131
|
+
it('rejects a second cooling-off while one is still running', async () => {
|
|
132
|
+
const { svc, enforcement } = makeService();
|
|
133
|
+
const userId = randomUUID();
|
|
134
|
+
await seedExclusion({ userId, kind: 'cooling_off', expiresAt: future() });
|
|
135
|
+
await expect(svc.activateCoolingOff(userId, { userId, durationHours: 24, reason: 'break' }, randomUUID())).rejects.toBeInstanceOf(ActiveExclusionError);
|
|
141
136
|
expect(enforcement.block).not.toHaveBeenCalled();
|
|
142
137
|
});
|
|
143
|
-
|
|
138
|
+
it('expires a lapsed cooling-off and lets a fresh one through', async () => {
|
|
139
|
+
const { svc } = makeService();
|
|
140
|
+
const userId = randomUUID();
|
|
141
|
+
const lapsed = await seedExclusion({ userId, kind: 'cooling_off', expiresAt: past() });
|
|
142
|
+
await svc.activateCoolingOff(userId, { userId, durationHours: 24, reason: 'again' }, randomUUID());
|
|
143
|
+
const rows = await exclusionsOf(userId);
|
|
144
|
+
expect(rows).toHaveLength(2);
|
|
145
|
+
expect(rows.find((r) => r.id === lapsed.id)?.status).toBe('expired');
|
|
146
|
+
expect(rows.filter((r) => r.status === 'active')).toHaveLength(1);
|
|
147
|
+
});
|
|
144
148
|
it('keeps an indefinite block when a self-exclusion is still active', async () => {
|
|
145
|
-
const
|
|
146
|
-
const
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
{ kind: 'self_exclusion', expiresAt: null },
|
|
151
|
-
{ kind: 'cooling_off', expiresAt: future() },
|
|
152
|
-
],
|
|
153
|
-
],
|
|
154
|
-
returning: [row],
|
|
155
|
-
});
|
|
156
|
-
const { svc, enforcement } = newSvc(db);
|
|
157
|
-
await svc.activateCoolingOff(USER, { userId: USER, durationHours: 24, reason: 'break' }, ADMIN);
|
|
158
|
-
expect(enforcement.block).toHaveBeenCalledWith(USER, { until: null });
|
|
149
|
+
const { svc, enforcement } = makeService();
|
|
150
|
+
const userId = randomUUID();
|
|
151
|
+
await seedExclusion({ userId, kind: 'self_exclusion', isPermanent: true, expiresAt: null });
|
|
152
|
+
await svc.activateCoolingOff(userId, { userId, durationHours: 24, reason: 'break' }, randomUUID());
|
|
153
|
+
expect(enforcement.block).toHaveBeenCalledWith(userId, { until: null });
|
|
159
154
|
});
|
|
160
155
|
});
|
|
161
|
-
describe('RgService.activateSelfExclusion', () => {
|
|
162
|
-
it('
|
|
163
|
-
const
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
await svc.activateSelfExclusion(USER, { userId: USER, isPermanent: true, reason: 'stop', confirm: true }, ADMIN);
|
|
170
|
-
expect(enforcement.block).toHaveBeenCalledWith(USER, { until: null });
|
|
156
|
+
describe('RgService.activateSelfExclusion (real PG)', () => {
|
|
157
|
+
it('stores a permanent exclusion with no expiry and blocks indefinitely', async () => {
|
|
158
|
+
const { svc, events, enforcement } = makeService();
|
|
159
|
+
const userId = randomUUID();
|
|
160
|
+
await svc.activateSelfExclusion(userId, { userId, isPermanent: true, reason: 'stop', confirm: true }, randomUUID());
|
|
161
|
+
const [row] = await exclusionsOf(userId);
|
|
162
|
+
expect(row).toMatchObject({ kind: 'self_exclusion', isPermanent: true, expiresAt: null });
|
|
163
|
+
expect(enforcement.block).toHaveBeenCalledWith(userId, { until: null });
|
|
171
164
|
expect(events.emit).toHaveBeenCalledWith('rg.self_exclusion.activated', expect.objectContaining({ isPermanent: true, durationMonths: null, expiresAt: null }));
|
|
172
165
|
});
|
|
173
|
-
it('
|
|
174
|
-
const
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
});
|
|
185
|
-
const { svc, events, enforcement } = newSvc(db);
|
|
186
|
-
await svc.activateSelfExclusion(USER_UUID, { userId: USER_UUID, isPermanent: false, durationMonths: 6, reason: 'stop', confirm: true }, ADMIN_UUID);
|
|
187
|
-
expect(enforcement.block).toHaveBeenCalledWith(USER_UUID, { until: null });
|
|
188
|
-
const [topic, payload] = events.emit.mock.calls[0] ?? [];
|
|
189
|
-
expect(topic).toBe('rg.self_exclusion.activated');
|
|
190
|
-
expect(domainEventSchemas['rg.self_exclusion.activated'].parse(payload)).toMatchObject({
|
|
166
|
+
it('stores a fixed-term expiry, keeps the indefinite block, and emits the chosen term', async () => {
|
|
167
|
+
const { svc, events, enforcement } = makeService();
|
|
168
|
+
const userId = randomUUID();
|
|
169
|
+
const actorId = randomUUID();
|
|
170
|
+
await svc.activateSelfExclusion(userId, { userId, isPermanent: false, durationMonths: 6, reason: 'break', confirm: true }, actorId);
|
|
171
|
+
const [row] = await exclusionsOf(userId);
|
|
172
|
+
expect(row?.expiresAt).toBeInstanceOf(Date);
|
|
173
|
+
expect(enforcement.block).toHaveBeenCalledWith(userId, { until: null });
|
|
174
|
+
expect(events.emit).toHaveBeenCalledWith('rg.self_exclusion.activated', expect.objectContaining({
|
|
175
|
+
userId,
|
|
176
|
+
actorId,
|
|
191
177
|
isPermanent: false,
|
|
192
178
|
durationMonths: 6,
|
|
193
|
-
reason: '
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
179
|
+
reason: 'break',
|
|
180
|
+
}));
|
|
181
|
+
});
|
|
182
|
+
it('rejects a second active self-exclusion', async () => {
|
|
183
|
+
const { svc } = makeService();
|
|
184
|
+
const userId = randomUUID();
|
|
185
|
+
await seedExclusion({ userId, kind: 'self_exclusion', isPermanent: true });
|
|
186
|
+
await expect(svc.activateSelfExclusion(userId, { userId, isPermanent: true, reason: 'again', confirm: true }, randomUUID())).rejects.toBeInstanceOf(ActiveExclusionError);
|
|
197
187
|
});
|
|
198
188
|
});
|
|
199
|
-
describe('RgService.liftSelfExclusion', () => {
|
|
200
|
-
it('
|
|
201
|
-
const
|
|
202
|
-
const
|
|
203
|
-
await
|
|
189
|
+
describe('RgService.liftSelfExclusion (real PG)', () => {
|
|
190
|
+
it('refuses to lift a permanent self-exclusion', async () => {
|
|
191
|
+
const { svc, enforcement } = makeService();
|
|
192
|
+
const userId = randomUUID();
|
|
193
|
+
await seedExclusion({ userId, isPermanent: true, expiresAt: null });
|
|
194
|
+
await expect(svc.liftSelfExclusion(userId, { userId, reason: 'ok', confirm: true }, randomUUID())).rejects.toBeInstanceOf(PermanentExclusionLiftError);
|
|
204
195
|
expect(enforcement.unblock).not.toHaveBeenCalled();
|
|
205
196
|
});
|
|
206
|
-
it('
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
await expect(svc.liftSelfExclusion(USER, { userId: USER, reason: 'ok', confirm: true }, ADMIN)).rejects.toBeInstanceOf(ExclusionPeriodNotElapsedError);
|
|
197
|
+
it('refuses to lift before the minimum period has elapsed', async () => {
|
|
198
|
+
const { svc } = makeService();
|
|
199
|
+
const userId = randomUUID();
|
|
200
|
+
await seedExclusion({ userId, isPermanent: false, expiresAt: future() });
|
|
201
|
+
await expect(svc.liftSelfExclusion(userId, { userId, reason: 'ok', confirm: true }, randomUUID())).rejects.toBeInstanceOf(ExclusionPeriodNotElapsedError);
|
|
212
202
|
});
|
|
213
|
-
it('
|
|
214
|
-
const { svc } =
|
|
215
|
-
await expect(svc.liftSelfExclusion(
|
|
203
|
+
it('throws when the player has no active self-exclusion', async () => {
|
|
204
|
+
const { svc } = makeService();
|
|
205
|
+
await expect(svc.liftSelfExclusion(randomUUID(), { userId: randomUUID(), reason: 'ok', confirm: true }, randomUUID())).rejects.toBeInstanceOf(ExclusionNotFoundError);
|
|
216
206
|
});
|
|
217
|
-
it('lifts
|
|
218
|
-
const
|
|
219
|
-
const
|
|
220
|
-
const
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
await
|
|
224
|
-
expect(
|
|
225
|
-
|
|
207
|
+
it('lifts an elapsed exclusion, records the lift metadata, and unblocks', async () => {
|
|
208
|
+
const { svc, events, enforcement } = makeService();
|
|
209
|
+
const userId = randomUUID();
|
|
210
|
+
const actorId = randomUUID();
|
|
211
|
+
const existing = await seedExclusion({ userId, isPermanent: false, expiresAt: past() });
|
|
212
|
+
await svc.liftSelfExclusion(userId, { userId, reason: 'recovered', confirm: true }, actorId);
|
|
213
|
+
const [row] = await exclusionsOf(userId);
|
|
214
|
+
expect(row).toMatchObject({
|
|
215
|
+
id: existing.id,
|
|
216
|
+
status: 'lifted',
|
|
217
|
+
liftedReason: 'recovered',
|
|
218
|
+
liftedBy: actorId,
|
|
219
|
+
});
|
|
220
|
+
expect(row?.liftedAt).toBeInstanceOf(Date);
|
|
221
|
+
expect(enforcement.unblock).toHaveBeenCalledWith(userId);
|
|
222
|
+
expect(events.emit).toHaveBeenCalledWith('rg.self_exclusion.lifted', expect.objectContaining({ userId, actorId }));
|
|
226
223
|
});
|
|
227
|
-
// GROUP 1: lifting the self-exclusion must not clear an unrelated active cooling-off.
|
|
228
224
|
it('recomputes to the remaining cooling-off block instead of unblocking', async () => {
|
|
229
|
-
const
|
|
230
|
-
const
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
});
|
|
235
|
-
const { svc, enforcement } = newSvc(db);
|
|
236
|
-
await svc.liftSelfExclusion(USER, { userId: USER, reason: 'ok', confirm: true }, ADMIN);
|
|
237
|
-
expect(enforcement.block).toHaveBeenCalledWith(USER, { until: expect.any(Date) });
|
|
225
|
+
const { svc, enforcement } = makeService();
|
|
226
|
+
const userId = randomUUID();
|
|
227
|
+
await seedExclusion({ userId, isPermanent: false, expiresAt: past() });
|
|
228
|
+
await seedExclusion({ userId, kind: 'cooling_off', expiresAt: future() });
|
|
229
|
+
await svc.liftSelfExclusion(userId, { userId, reason: 'ok', confirm: true }, randomUUID());
|
|
230
|
+
expect(enforcement.block).toHaveBeenCalledWith(userId, { until: expect.any(Date) });
|
|
238
231
|
expect(enforcement.unblock).not.toHaveBeenCalled();
|
|
239
232
|
});
|
|
233
|
+
it('lets a fresh self-exclusion start once the previous one was lifted', async () => {
|
|
234
|
+
const { svc } = makeService();
|
|
235
|
+
const userId = randomUUID();
|
|
236
|
+
await seedExclusion({ userId, isPermanent: false, expiresAt: past() });
|
|
237
|
+
await svc.liftSelfExclusion(userId, { userId, reason: 'ok', confirm: true }, randomUUID());
|
|
238
|
+
await svc.activateSelfExclusion(userId, { userId, isPermanent: true, reason: 'relapse', confirm: true }, randomUUID());
|
|
239
|
+
const rows = await exclusionsOf(userId);
|
|
240
|
+
expect(rows.filter((r) => r.status === 'active')).toHaveLength(1);
|
|
241
|
+
});
|
|
240
242
|
});
|
|
241
|
-
describe('RgService.liftCoolingOff', () => {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
const
|
|
245
|
-
await expect(svc.liftCoolingOff(
|
|
243
|
+
describe('RgService.liftCoolingOff (real PG)', () => {
|
|
244
|
+
it('throws when the player has no active cooling-off', async () => {
|
|
245
|
+
const { svc } = makeService();
|
|
246
|
+
const userId = randomUUID();
|
|
247
|
+
await expect(svc.liftCoolingOff(userId, { userId, reason: 'ok' }, randomUUID())).rejects.toBeInstanceOf(ExclusionNotFoundError);
|
|
246
248
|
});
|
|
247
|
-
it('lifts
|
|
248
|
-
const
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
|
|
249
|
+
it('lifts an active cooling-off, records the lift metadata, and unblocks', async () => {
|
|
250
|
+
const { svc, events, enforcement } = makeService();
|
|
251
|
+
const userId = randomUUID();
|
|
252
|
+
const actorId = randomUUID();
|
|
253
|
+
const existing = await seedExclusion({ userId, kind: 'cooling_off', expiresAt: future() });
|
|
254
|
+
await svc.liftCoolingOff(userId, { userId, reason: 'support ticket 42' }, actorId);
|
|
255
|
+
const [row] = await exclusionsOf(userId);
|
|
256
|
+
expect(row).toMatchObject({
|
|
257
|
+
id: existing.id,
|
|
258
|
+
kind: 'cooling_off',
|
|
259
|
+
status: 'lifted',
|
|
260
|
+
liftedReason: 'support ticket 42',
|
|
261
|
+
liftedBy: actorId,
|
|
252
262
|
});
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
expect(lifted.status).toBe('lifted');
|
|
256
|
-
expect(enforcement.unblock).toHaveBeenCalledWith(USER);
|
|
257
|
-
expect(events.emit).toHaveBeenCalledWith('rg.cooling_off.lifted', expect.objectContaining({ userId: USER, actorId: ADMIN, reason: 'raised in error' }));
|
|
263
|
+
expect(enforcement.unblock).toHaveBeenCalledWith(userId);
|
|
264
|
+
expect(events.emit).toHaveBeenCalledWith('rg.cooling_off.lifted', expect.objectContaining({ userId, actorId, reason: 'support ticket 42' }));
|
|
258
265
|
});
|
|
259
266
|
it('keeps an indefinite block when the player is also self-excluded', async () => {
|
|
260
|
-
const
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
await svc.liftCoolingOff(USER, { userId: USER, reason: 'ok' }, ADMIN);
|
|
267
|
-
expect(enforcement.block).toHaveBeenCalledWith(USER, { until: null });
|
|
267
|
+
const { svc, enforcement } = makeService();
|
|
268
|
+
const userId = randomUUID();
|
|
269
|
+
await seedExclusion({ userId, kind: 'cooling_off', expiresAt: future() });
|
|
270
|
+
await seedExclusion({ userId, kind: 'self_exclusion', isPermanent: true, expiresAt: null });
|
|
271
|
+
await svc.liftCoolingOff(userId, { userId, reason: 'ok' }, randomUUID());
|
|
272
|
+
expect(enforcement.block).toHaveBeenCalledWith(userId, { until: null });
|
|
268
273
|
expect(enforcement.unblock).not.toHaveBeenCalled();
|
|
269
274
|
});
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
});
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
expect(
|
|
281
|
-
expect(
|
|
275
|
+
});
|
|
276
|
+
describe('RgService.getRgSection (real PG)', () => {
|
|
277
|
+
it('returns the player limits alongside the active exclusions', async () => {
|
|
278
|
+
const { svc } = makeService();
|
|
279
|
+
const userId = randomUUID();
|
|
280
|
+
await svc.setPlayerLimit(userId, { userId, type: 'deposit', amount: '100', minutes: null, period: 'daily' }, randomUUID());
|
|
281
|
+
await seedExclusion({ userId, kind: 'cooling_off', expiresAt: future() });
|
|
282
|
+
await seedExclusion({ userId, kind: 'self_exclusion', isPermanent: true });
|
|
283
|
+
const section = await svc.getRgSection(userId);
|
|
284
|
+
expect(section.limits).toHaveLength(1);
|
|
285
|
+
expect(section.coolingOff).toMatchObject({ kind: 'cooling_off' });
|
|
286
|
+
expect(section.selfExclusion).toMatchObject({ kind: 'self_exclusion' });
|
|
287
|
+
});
|
|
288
|
+
it('treats a lapsed cooling-off as inactive even before the sweep runs', async () => {
|
|
289
|
+
const { svc } = makeService();
|
|
290
|
+
const userId = randomUUID();
|
|
291
|
+
await seedExclusion({ userId, kind: 'cooling_off', expiresAt: past() });
|
|
292
|
+
const section = await svc.getRgSection(userId);
|
|
293
|
+
expect(section.coolingOff).toBeNull();
|
|
294
|
+
});
|
|
295
|
+
it('returns empty state for a player with nothing on file', async () => {
|
|
296
|
+
const { svc } = makeService();
|
|
297
|
+
const section = await svc.getRgSection(randomUUID());
|
|
298
|
+
expect(section).toEqual({ limits: [], coolingOff: null, selfExclusion: null });
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
describe('RgService.expireLapsedCoolingOffs (real PG)', () => {
|
|
302
|
+
it('expires lapsed rows and unblocks the affected players', async () => {
|
|
303
|
+
const { svc, enforcement } = makeService();
|
|
304
|
+
const lapsedUser = randomUUID();
|
|
305
|
+
const runningUser = randomUUID();
|
|
306
|
+
await seedExclusion({ userId: lapsedUser, kind: 'cooling_off', expiresAt: past() });
|
|
307
|
+
await seedExclusion({ userId: runningUser, kind: 'cooling_off', expiresAt: future() });
|
|
308
|
+
await svc.expireLapsedCoolingOffs();
|
|
309
|
+
const [lapsed] = await exclusionsOf(lapsedUser);
|
|
310
|
+
const [running] = await exclusionsOf(runningUser);
|
|
311
|
+
expect(lapsed?.status).toBe('expired');
|
|
312
|
+
expect(running?.status).toBe('active');
|
|
313
|
+
expect(enforcement.unblock).toHaveBeenCalledWith(lapsedUser);
|
|
314
|
+
expect(enforcement.unblock).not.toHaveBeenCalledWith(runningUser);
|
|
315
|
+
});
|
|
316
|
+
it('keeps the indefinite block when the player is also self-excluded', async () => {
|
|
317
|
+
const { svc, enforcement } = makeService();
|
|
318
|
+
const userId = randomUUID();
|
|
319
|
+
await seedExclusion({ userId, kind: 'cooling_off', expiresAt: past() });
|
|
320
|
+
await seedExclusion({ userId, kind: 'self_exclusion', isPermanent: true });
|
|
321
|
+
await svc.expireLapsedCoolingOffs();
|
|
322
|
+
expect(enforcement.block).toHaveBeenCalledWith(userId, { until: null });
|
|
323
|
+
expect(enforcement.unblock).not.toHaveBeenCalled();
|
|
282
324
|
});
|
|
283
325
|
});
|
|
284
326
|
//# sourceMappingURL=rg.service.test.js.map
|