@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
|
@@ -7,19 +7,19 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
import { beforeAll, describe, expect, test } from 'vitest';
|
|
11
10
|
import { sql } from 'drizzle-orm';
|
|
11
|
+
import { beforeAll, describe, expect, test } from 'vitest';
|
|
12
|
+
import { Singleton } from '../../injector/decorators.js';
|
|
12
13
|
import { StringProperty } from '../../schema/index.js';
|
|
14
|
+
import { setupIntegrationTest } from '../../testing/index.js';
|
|
15
|
+
import { ChildEntity, Column, Inheritance, Table } from '../decorators.js';
|
|
13
16
|
import { Entity } from '../entity.js';
|
|
14
|
-
import { Column, Inheritance, ChildEntity, Table } from '../decorators.js';
|
|
15
17
|
import { getRepository } from '../server/repository.js';
|
|
16
|
-
import { configureOrm, Database } from '../server/index.js';
|
|
17
|
-
import { Injector, runInInjectionContext } from '../../injector/index.js';
|
|
18
18
|
import { Transactional } from '../server/transactional.js';
|
|
19
|
-
import { Singleton } from '../../injector/decorators.js';
|
|
20
19
|
describe('ORM Repository CTI Transactions (Integration)', () => {
|
|
21
20
|
let injector;
|
|
22
21
|
let db;
|
|
22
|
+
let service;
|
|
23
23
|
const schema = 'test_orm_cti_transactions';
|
|
24
24
|
let Parent = class Parent extends Entity {
|
|
25
25
|
type;
|
|
@@ -66,18 +66,10 @@ describe('ORM Repository CTI Transactions (Integration)', () => {
|
|
|
66
66
|
Singleton()
|
|
67
67
|
], TestService);
|
|
68
68
|
beforeAll(async () => {
|
|
69
|
-
injector =
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
host: '127.0.0.1',
|
|
74
|
-
port: 5432,
|
|
75
|
-
user: 'tstdl',
|
|
76
|
-
password: 'wf7rq6glrk5jykne',
|
|
77
|
-
database: 'tstdl',
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
db = injector.resolve(Database);
|
|
69
|
+
({ injector, database: db } = await setupIntegrationTest({
|
|
70
|
+
orm: { schema },
|
|
71
|
+
}));
|
|
72
|
+
service = injector.resolve(TestService);
|
|
81
73
|
await db.execute(sql `CREATE SCHEMA IF NOT EXISTS ${sql.identifier(schema)}`);
|
|
82
74
|
await db.execute(sql `DROP TABLE IF EXISTS ${sql.identifier(schema)}.${sql.identifier('children')} CASCADE`);
|
|
83
75
|
await db.execute(sql `DROP TABLE IF EXISTS ${sql.identifier(schema)}.${sql.identifier('parents')} CASCADE`);
|
|
@@ -104,23 +96,17 @@ describe('ORM Repository CTI Transactions (Integration)', () => {
|
|
|
104
96
|
`);
|
|
105
97
|
});
|
|
106
98
|
test('should rollback inheritance inserts across multiple tables on service error', async () => {
|
|
107
|
-
await
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
expect(parentRows).toHaveLength(0);
|
|
113
|
-
expect(childRows).toHaveLength(0);
|
|
114
|
-
});
|
|
99
|
+
await expect(service.createTwo('ShouldRollback', 'Fails', true)).rejects.toThrow('Planned failure');
|
|
100
|
+
const { rows: parentRows } = await db.execute(sql `SELECT * FROM ${sql.identifier(schema)}.${sql.identifier('parents')}`);
|
|
101
|
+
const { rows: childRows } = await db.execute(sql `SELECT * FROM ${sql.identifier(schema)}.${sql.identifier('children')}`);
|
|
102
|
+
expect(parentRows).toHaveLength(0);
|
|
103
|
+
expect(childRows).toHaveLength(0);
|
|
115
104
|
});
|
|
116
105
|
test('should commit inheritance inserts across multiple tables on success', async () => {
|
|
117
|
-
await
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
expect(parentRows).toHaveLength(2);
|
|
123
|
-
expect(childRows).toHaveLength(2);
|
|
124
|
-
});
|
|
106
|
+
await service.createTwo('C1', 'C2', false);
|
|
107
|
+
const { rows: parentRows } = await db.execute(sql `SELECT * FROM ${sql.identifier(schema)}.${sql.identifier('parents')}`);
|
|
108
|
+
const { rows: childRows } = await db.execute(sql `SELECT * FROM ${sql.identifier(schema)}.${sql.identifier('children')}`);
|
|
109
|
+
expect(parentRows).toHaveLength(2);
|
|
110
|
+
expect(childRows).toHaveLength(2);
|
|
125
111
|
});
|
|
126
112
|
});
|
|
@@ -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,15 +10,16 @@ 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 { ChildEntity, Column, Inheritance, Table } from '../decorators.js';
|
|
15
16
|
import { Entity } from '../entity.js';
|
|
16
|
-
import {
|
|
17
|
-
import { injectRepository } from '../server/repository.js';
|
|
17
|
+
import { getRepository } from '../server/index.js';
|
|
18
18
|
describe('ORM Repository CTI UpsertMany (Integration)', () => {
|
|
19
19
|
let injector;
|
|
20
20
|
let db;
|
|
21
|
+
let itemRepo;
|
|
22
|
+
let bookRepo;
|
|
21
23
|
const schema = 'test_orm_cti_upsert_many';
|
|
22
24
|
let Item = class Item extends Entity {
|
|
23
25
|
type;
|
|
@@ -48,18 +50,11 @@ describe('ORM Repository CTI UpsertMany (Integration)', () => {
|
|
|
48
50
|
ChildEntity('book')
|
|
49
51
|
], Book);
|
|
50
52
|
beforeAll(async () => {
|
|
51
|
-
injector =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
port: 5432,
|
|
57
|
-
user: 'tstdl',
|
|
58
|
-
password: 'wf7rq6glrk5jykne',
|
|
59
|
-
database: 'tstdl',
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
db = injector.resolve(Database);
|
|
53
|
+
({ injector, database: db } = await setupIntegrationTest({
|
|
54
|
+
orm: { schema },
|
|
55
|
+
}));
|
|
56
|
+
itemRepo = injector.resolve(getRepository(Item));
|
|
57
|
+
bookRepo = injector.resolve(getRepository(Book));
|
|
63
58
|
await db.execute(sql `CREATE SCHEMA IF NOT EXISTS ${sql.identifier(schema)}`);
|
|
64
59
|
await db.execute(sql `DROP TABLE IF EXISTS ${sql.identifier(schema)}.${sql.identifier('books')} CASCADE`);
|
|
65
60
|
await db.execute(sql `DROP TABLE IF EXISTS ${sql.identifier(schema)}.${sql.identifier('items')} CASCADE`);
|
|
@@ -86,42 +81,35 @@ describe('ORM Repository CTI UpsertMany (Integration)', () => {
|
|
|
86
81
|
`);
|
|
87
82
|
});
|
|
88
83
|
test('should upsertMany child entities (insert and update mixed)', async () => {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const loaded2 = await bookRepo.load(inserted2.id);
|
|
110
|
-
expect(loaded2.title).toBe('Book 2');
|
|
111
|
-
});
|
|
84
|
+
// 1. Insert initial books
|
|
85
|
+
const book1 = Object.assign(new Book(), { title: 'Book 1', author: 'Author 1' });
|
|
86
|
+
const book2 = Object.assign(new Book(), { title: 'Book 2', author: 'Author 2' });
|
|
87
|
+
const [inserted1, inserted2] = await bookRepo.insertMany([book1, book2]);
|
|
88
|
+
// 2. Prepare upsert payload: update book1, new book3
|
|
89
|
+
const update1 = Object.assign(new Book(), { id: inserted1.id, title: 'Book 1 Updated', author: 'Author 1 Updated' });
|
|
90
|
+
const book3 = Object.assign(new Book(), { title: 'Book 3', author: 'Author 3' });
|
|
91
|
+
const results = await bookRepo.upsertMany('id', [update1, book3]);
|
|
92
|
+
expect(results).toHaveLength(2);
|
|
93
|
+
const updated1 = results.find((b) => b.id === inserted1.id);
|
|
94
|
+
const inserted3 = results.find((b) => b.title === 'Book 3');
|
|
95
|
+
expect(updated1).toBeDefined();
|
|
96
|
+
expect(updated1.title).toBe('Book 1 Updated');
|
|
97
|
+
expect(updated1.author).toBe('Author 1 Updated');
|
|
98
|
+
expect(inserted3).toBeDefined();
|
|
99
|
+
expect(inserted3.id).toBeDefined();
|
|
100
|
+
expect(inserted3.author).toBe('Author 3');
|
|
101
|
+
// Verify book2 is untouched
|
|
102
|
+
const loaded2 = await bookRepo.load(inserted2.id);
|
|
103
|
+
expect(loaded2.title).toBe('Book 2');
|
|
112
104
|
});
|
|
113
105
|
test('should polymorphic tryLoadByQuery', async () => {
|
|
114
|
-
await
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
expect(loaded).toBeDefined();
|
|
123
|
-
expect(loaded).toBeInstanceOf(Book);
|
|
124
|
-
expect(loaded.author).toBe('Unique Author');
|
|
125
|
-
});
|
|
106
|
+
await bookRepo.insert(Object.assign(new Book(), { title: 'Unique Book', author: 'Unique Author' }));
|
|
107
|
+
// Load via Item repo using a book-specific property (should fail if not joined, but here we query by title)
|
|
108
|
+
// Querying by book-specific property requires casting query or using raw sql if repository type doesn't have it.
|
|
109
|
+
// But we can query by base property 'title'.
|
|
110
|
+
const loaded = await itemRepo.tryLoadByQuery({ title: 'Unique Book' }, { includeSubclasses: true });
|
|
111
|
+
expect(loaded).toBeDefined();
|
|
112
|
+
expect(loaded).toBeInstanceOf(Book);
|
|
113
|
+
expect(loaded.author).toBe('Unique Author');
|
|
126
114
|
});
|
|
127
115
|
});
|