@tstdl/base 0.93.145 → 0.93.146
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/authentication/tests/authentication.client-service.test.js +15 -19
- package/authentication/tests/authentication.service.test.js +92 -119
- package/notification/tests/notification-client.test.js +39 -50
- package/notification/tests/notification-flow.test.js +204 -238
- package/notification/tests/notification-sse.service.test.js +20 -27
- package/notification/tests/notification-type.service.test.js +17 -20
- package/orm/tests/query-complex.test.js +80 -111
- package/orm/tests/repository-advanced.test.js +100 -143
- package/orm/tests/repository-attributes.test.js +30 -39
- package/orm/tests/repository-compound-primary-key.test.js +67 -75
- package/orm/tests/repository-comprehensive.test.js +76 -101
- package/orm/tests/repository-coverage.test.d.ts +1 -0
- package/orm/tests/repository-coverage.test.js +88 -149
- package/orm/tests/repository-cti-extensive.test.d.ts +1 -0
- package/orm/tests/repository-cti-extensive.test.js +118 -147
- package/orm/tests/repository-cti-mapping.test.d.ts +1 -0
- package/orm/tests/repository-cti-mapping.test.js +29 -42
- package/orm/tests/repository-cti-soft-delete.test.d.ts +1 -0
- package/orm/tests/repository-cti-soft-delete.test.js +25 -37
- package/orm/tests/repository-cti-transactions.test.js +19 -33
- package/orm/tests/repository-cti-upsert-many.test.d.ts +1 -0
- package/orm/tests/repository-cti-upsert-many.test.js +38 -50
- package/orm/tests/repository-cti.test.d.ts +1 -0
- package/orm/tests/repository-cti.test.js +195 -247
- package/orm/tests/repository-expiration.test.d.ts +1 -0
- package/orm/tests/repository-expiration.test.js +46 -59
- package/orm/tests/repository-extra-coverage.test.d.ts +1 -0
- package/orm/tests/repository-extra-coverage.test.js +195 -337
- package/orm/tests/repository-mapping.test.d.ts +1 -0
- package/orm/tests/repository-mapping.test.js +20 -20
- package/orm/tests/repository-regression.test.js +124 -163
- package/orm/tests/repository-search.test.js +30 -44
- package/orm/tests/repository-soft-delete.test.js +54 -79
- package/orm/tests/repository-types.test.js +77 -111
- package/package.json +1 -1
- package/task-queue/tests/worker.test.js +5 -5
- package/testing/README.md +38 -16
- package/testing/integration-setup.d.ts +11 -0
- package/testing/integration-setup.js +57 -30
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** biome-ignore-all lint/nursery/noExcessiveClassesPerFile: <explanation> */
|
|
1
2
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
3
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
4
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -9,16 +10,17 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
10
|
};
|
|
10
11
|
import { sql } from 'drizzle-orm';
|
|
11
12
|
import { beforeAll, describe, expect, test } from 'vitest';
|
|
12
|
-
import { Injector, runInInjectionContext } from '../../injector/index.js';
|
|
13
13
|
import { StringProperty } from '../../schema/index.js';
|
|
14
|
+
import { setupIntegrationTest } from '../../testing/index.js';
|
|
14
15
|
import { Expires, Table, TimeToLive } from '../decorators.js';
|
|
15
16
|
import { Entity } from '../entity.js';
|
|
16
17
|
import { TimestampProperty } from '../schemas/index.js';
|
|
17
|
-
import {
|
|
18
|
-
import { injectRepository } from '../server/repository.js';
|
|
18
|
+
import { getRepository } from '../server/index.js';
|
|
19
19
|
describe('ORM Repository Expiration', () => {
|
|
20
20
|
let injector;
|
|
21
21
|
let db;
|
|
22
|
+
let expirationRepo;
|
|
23
|
+
let ttlRepo;
|
|
22
24
|
const schema = 'test_orm_expiration';
|
|
23
25
|
let ExpirationEntity = class ExpirationEntity extends Entity {
|
|
24
26
|
name;
|
|
@@ -54,14 +56,11 @@ describe('ORM Repository Expiration', () => {
|
|
|
54
56
|
TimeToLive(100, 'hard') // 100ms TTL
|
|
55
57
|
], TtlEntity);
|
|
56
58
|
beforeAll(async () => {
|
|
57
|
-
injector =
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
db = injector.resolve(Database);
|
|
59
|
+
({ injector, database: db } = await setupIntegrationTest({
|
|
60
|
+
orm: { schema },
|
|
61
|
+
}));
|
|
62
|
+
expirationRepo = injector.resolve(getRepository(ExpirationEntity));
|
|
63
|
+
ttlRepo = injector.resolve(getRepository(TtlEntity));
|
|
65
64
|
await db.execute(sql `CREATE SCHEMA IF NOT EXISTS ${sql.identifier(schema)}`);
|
|
66
65
|
await db.execute(sql `DROP TABLE IF EXISTS ${sql.identifier(schema)}.${sql.identifier('expiration_entities')} CASCADE`);
|
|
67
66
|
await db.execute(sql `DROP TABLE IF EXISTS ${sql.identifier(schema)}.${sql.identifier('ttl_entities')} CASCADE`);
|
|
@@ -92,62 +91,50 @@ describe('ORM Repository Expiration', () => {
|
|
|
92
91
|
});
|
|
93
92
|
test('should support TimeToLive decorator', async () => {
|
|
94
93
|
await db.execute(sql `TRUNCATE TABLE ${sql.identifier(schema)}.${sql.identifier('ttl_entities')} CASCADE`);
|
|
95
|
-
await
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const all = await repository.loadAll({ withDeleted: true });
|
|
102
|
-
expect(all).toHaveLength(0);
|
|
103
|
-
});
|
|
94
|
+
const e1 = await ttlRepo.insert(Object.assign(new TtlEntity(), { name: 'Valid' }));
|
|
95
|
+
// Wait 150ms for expiration
|
|
96
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
97
|
+
await ttlRepo.processExpirations();
|
|
98
|
+
const all = await ttlRepo.loadAll({ withDeleted: true });
|
|
99
|
+
expect(all).toHaveLength(0);
|
|
104
100
|
});
|
|
105
101
|
test('should soft delete expired entities', async () => {
|
|
106
102
|
await db.execute(sql `TRUNCATE TABLE ${sql.identifier(schema)}.${sql.identifier('expiration_entities')} CASCADE`);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
expect(withDeleted).toHaveLength(2);
|
|
120
|
-
expect(withDeleted.find((e) => e.id === e1.id).metadata.deleteTimestamp).toBeDefined();
|
|
121
|
-
});
|
|
103
|
+
const now = Date.now();
|
|
104
|
+
const past = now - 10000; // 10s ago
|
|
105
|
+
const future = now + 10000; // 10s in future
|
|
106
|
+
const e1 = await expirationRepo.insert(Object.assign(new ExpirationEntity(), { name: 'Expired', softExpireAt: past }));
|
|
107
|
+
const e2 = await expirationRepo.insert(Object.assign(new ExpirationEntity(), { name: 'Valid', softExpireAt: future }));
|
|
108
|
+
await expirationRepo.processExpirations();
|
|
109
|
+
const all = await expirationRepo.loadAll();
|
|
110
|
+
expect(all).toHaveLength(1);
|
|
111
|
+
expect(all[0].name).toBe('Valid');
|
|
112
|
+
const withDeleted = await expirationRepo.loadAll({ withDeleted: true });
|
|
113
|
+
expect(withDeleted).toHaveLength(2);
|
|
114
|
+
expect(withDeleted.find((e) => e.id === e1.id).metadata.deleteTimestamp).toBeDefined();
|
|
122
115
|
});
|
|
123
116
|
test('should hard delete expired entities', async () => {
|
|
124
117
|
await db.execute(sql `TRUNCATE TABLE ${sql.identifier(schema)}.${sql.identifier('expiration_entities')} CASCADE`);
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
expect(all).toHaveLength(1);
|
|
135
|
-
expect(all[0].name).toBe('Valid');
|
|
136
|
-
});
|
|
118
|
+
const now = Date.now();
|
|
119
|
+
const past = now - 10000;
|
|
120
|
+
const future = now + 10000;
|
|
121
|
+
const e1 = await expirationRepo.insert(Object.assign(new ExpirationEntity(), { name: 'Expired', hardExpireAt: past }));
|
|
122
|
+
const e2 = await expirationRepo.insert(Object.assign(new ExpirationEntity(), { name: 'Valid', hardExpireAt: future }));
|
|
123
|
+
await expirationRepo.processExpirations();
|
|
124
|
+
const all = await expirationRepo.loadAll({ withDeleted: true });
|
|
125
|
+
expect(all).toHaveLength(1);
|
|
126
|
+
expect(all[0].name).toBe('Valid');
|
|
137
127
|
});
|
|
138
128
|
test('should handle mixed expiration', async () => {
|
|
139
129
|
await db.execute(sql `TRUNCATE TABLE ${sql.identifier(schema)}.${sql.identifier('expiration_entities')} CASCADE`);
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const all = await repository.loadAll({ withDeleted: true });
|
|
150
|
-
expect(all).toHaveLength(0);
|
|
151
|
-
});
|
|
130
|
+
const past = Date.now() - 10000;
|
|
131
|
+
await expirationRepo.insert(Object.assign(new ExpirationEntity(), {
|
|
132
|
+
name: 'BothExpired',
|
|
133
|
+
softExpireAt: past,
|
|
134
|
+
hardExpireAt: past,
|
|
135
|
+
}));
|
|
136
|
+
await expirationRepo.processExpirations();
|
|
137
|
+
const all = await expirationRepo.loadAll({ withDeleted: true });
|
|
138
|
+
expect(all).toHaveLength(0);
|
|
152
139
|
});
|
|
153
140
|
});
|