Skip to content

Commit 89be093

Browse files
committed
fix:修复测试
1 parent 6cba3ea commit 89be093

4 files changed

Lines changed: 98 additions & 53 deletions

File tree

‎index.mjs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ const DistributedCacheInvalidator = require('./lib/distributed-cache-invalidator
3131
// 默认导出
3232
export default MonSQLizeClass;
3333

34+
// 🆕 v1.0.9: 导出表达式函数
35+
const { expr, createExpression } = MonSQLizeClass;
36+
3437
// 命名导出
3538
export {
3639
MonSQLizeClass as MonSQLize,
@@ -39,6 +42,8 @@ export {
3942
createRedisCacheAdapter,
4043
TransactionManager,
4144
CacheLockManager,
42-
DistributedCacheInvalidator
45+
DistributedCacheInvalidator,
46+
expr, // 🆕 v1.0.9: 统一表达式函数
47+
createExpression // 🆕 v1.0.9: 表达式函数别名
4348
};
4449

‎test/run-tests.js‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,47 @@ async function runTests() {
339339
console.log('║ 运行 所有测试套件(顺序模式) ║');
340340
console.log('╚═══════════════════════════════════════════════════════════╝\n');
341341

342-
const suites = ['connection', 'find', 'findPage', 'findOne', 'findOneById', 'findByIds', 'findAndCount', 'upsertOne', 'incrementOne', 'count', 'countQueue', 'aggregate', 'distinct', 'explain', 'chaining', 'bookmarks', 'invalidate', 'insertOne', 'insertMany', 'insertBatch', 'updateOne', 'updateMany', 'updateBatch', 'replaceOne', 'findOneAndUpdate', 'findOneAndReplace', 'deleteOne', 'deleteMany', 'deleteBatch', 'findOneAndDelete', 'transaction', 'lock', 'objectIdConversion', 'slowQueryLog', 'watch', 'model', 'utils', 'infrastructure'];
342+
const suites = [
343+
'connection',
344+
'find',
345+
'findPage',
346+
'findOne',
347+
'findOneById',
348+
'findByIds',
349+
'findAndCount',
350+
'upsertOne',
351+
'incrementOne',
352+
'count',
353+
'countQueue',
354+
'aggregate',
355+
'distinct',
356+
'explain',
357+
'chaining',
358+
'bookmarks',
359+
'invalidate',
360+
'insertOne',
361+
'insertMany',
362+
'insertBatch',
363+
'updateOne',
364+
'updateMany',
365+
'updateBatch',
366+
'replaceOne',
367+
'findOneAndUpdate',
368+
'findOneAndReplace',
369+
'deleteOne',
370+
'deleteMany',
371+
'deleteBatch',
372+
'findOneAndDelete',
373+
'transaction',
374+
'lock',
375+
'objectIdConversion',
376+
'slowQueryLog',
377+
'watch',
378+
'model',
379+
'expression-all', // 🆕 v1.0.9: 统一表达式测试套件
380+
'utils',
381+
'infrastructure'
382+
];
343383
let totalPassed = 0;
344384
let totalFailed = 0;
345385
const failedSuites = []; // 收集失败的测试套件

‎test/unit/expression/core/detection.test.js‎

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -44,41 +44,41 @@ describe('Expression Core - Detection', function() {
4444
}
4545
});
4646

47-
describe('$ Factory Function', function() {
47+
describe('expr Factory Function', function() {
4848

4949
it('should create expression object', function() {
50-
const { $ } = MonSQLize;
51-
const expr = $("amount > 100");
50+
const { expr } = MonSQLize;
51+
const expression = expr("amount > 100");
5252

53-
assert(expr !== null && typeof expr === 'object', 'Expression should be an object');
54-
assert.strictEqual(expr.__expr__, 'amount > 100', 'Expression string should match');
55-
assert.strictEqual(expr.__compiled__, false, 'Should not be compiled yet');
53+
assert(expression !== null && typeof expression === 'object', 'Expression should be an object');
54+
assert.strictEqual(expression.__expr__, 'amount > 100', 'Expression string should match');
55+
assert.strictEqual(expression.__compiled__, false, 'Should not be compiled yet');
5656
});
5757

5858
it('should throw error for non-string input', function() {
59-
const { $ } = MonSQLize;
59+
const { expr } = MonSQLize;
6060

6161
assert.throws(() => {
62-
$(123);
62+
expr(123);
6363
}, TypeError, 'Should throw TypeError for number');
6464
});
6565

6666
it('should throw error for empty string', function() {
67-
const { $ } = MonSQLize;
67+
const { expr } = MonSQLize;
6868

6969
assert.throws(() => {
70-
$('');
70+
expr('');
7171
}, Error, 'Should throw Error for empty string');
7272
});
7373
});
7474

7575
describe('Expression Detection', function() {
7676

7777
it('should detect expression in $match stage', async function() {
78-
const { $ } = MonSQLize;
78+
const { expr } = MonSQLize;
7979

8080
const result = await collection('test_orders').aggregate([
81-
{ $match: $("amount > 100") }
81+
{ $match: expr("amount > 100") }
8282
]);
8383

8484
assert(Array.isArray(result), 'Result should be an array');
@@ -98,10 +98,10 @@ describe('Expression Core - Detection', function() {
9898
});
9999

100100
it('should allow mixing old and new syntax', async function() {
101-
const { $ } = MonSQLize;
101+
const { expr } = MonSQLize;
102102

103103
const result = await collection('test_orders').aggregate([
104-
{ $match: $("amount > 100") },
104+
{ $match: expr("amount > 100") },
105105
{ $match: { status: 'paid' } } // 旧语法
106106
]);
107107

@@ -116,20 +116,20 @@ describe('Expression Core - Detection', function() {
116116
describe('Basic Comparison Operators', function() {
117117

118118
it('should compile > operator', async function() {
119-
const { $ } = MonSQLize;
119+
const { expr } = MonSQLize;
120120

121121
const result = await collection('test_orders').aggregate([
122-
{ $match: $("amount > 100") }
122+
{ $match: expr("amount > 100") }
123123
]);
124124

125125
assert.strictEqual(result.length, 2);
126126
});
127127

128128
it('should compile >= operator', async function() {
129-
const { $ } = MonSQLize;
129+
const { expr } = MonSQLize;
130130

131131
const result = await collection('test_orders').aggregate([
132-
{ $match: $("amount >= 150") }
132+
{ $match: expr("amount >= 150") }
133133
]);
134134

135135
// amount >= 150: 150, 200 共2个
@@ -138,10 +138,10 @@ describe('Expression Core - Detection', function() {
138138
});
139139

140140
it('should compile <= operator', async function() {
141-
const { $ } = MonSQLize;
141+
const { expr } = MonSQLize;
142142

143143
const result = await collection('test_orders').aggregate([
144-
{ $match: $("amount <= 75") }
144+
{ $match: expr("amount <= 75") }
145145
]);
146146

147147
// amount <= 75: 50, 75 共2个
@@ -150,31 +150,31 @@ describe('Expression Core - Detection', function() {
150150
});
151151

152152
it('should compile < operator', async function() {
153-
const { $ } = MonSQLize;
153+
const { expr } = MonSQLize;
154154

155155
const result = await collection('test_orders').aggregate([
156-
{ $match: $("amount < 100") }
156+
{ $match: expr("amount < 100") }
157157
]);
158158

159159
assert.strictEqual(result.length, 2);
160160
});
161161

162162
it('should compile === operator', async function() {
163-
const { $ } = MonSQLize;
163+
const { expr } = MonSQLize;
164164

165165
const result = await collection('test_orders').aggregate([
166-
{ $match: $("status === 'paid'") }
166+
{ $match: expr("status === 'paid'") }
167167
]);
168168

169169
assert.strictEqual(result.length, 2);
170170
assert(result.every(r => r.status === 'paid'));
171171
});
172172

173173
it('should compile !== operator', async function() {
174-
const { $ } = MonSQLize;
174+
const { expr } = MonSQLize;
175175

176176
const result = await collection('test_orders').aggregate([
177-
{ $match: $("status !== 'paid'") }
177+
{ $match: expr("status !== 'paid'") }
178178
]);
179179

180180
assert.strictEqual(result.length, 2);
@@ -185,10 +185,10 @@ describe('Expression Core - Detection', function() {
185185
describe('Logical Operators', function() {
186186

187187
it('should compile && (AND) operator', async function() {
188-
const { $ } = MonSQLize;
188+
const { expr } = MonSQLize;
189189

190190
const result = await collection('test_orders').aggregate([
191-
{ $match: $("amount > 100 && status === 'paid'") }
191+
{ $match: expr("amount > 100 && status === 'paid'") }
192192
]);
193193

194194
// amount > 100 且 status === 'paid': id=2(150,paid), id=3(200,paid)
@@ -197,10 +197,10 @@ describe('Expression Core - Detection', function() {
197197
});
198198

199199
it('should compile || (OR) operator', async function() {
200-
const { $ } = MonSQLize;
200+
const { expr } = MonSQLize;
201201

202202
const result = await collection('test_orders').aggregate([
203-
{ $match: $("amount > 150 || status === 'pending'") }
203+
{ $match: expr("amount > 150 || status === 'pending'") }
204204
]);
205205

206206
// amount > 150(id=3:200) 或 status === 'pending'(id=1:50, id=4:75)

‎test/unit/expression/operators/aggregation.test.js‎

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,58 +12,58 @@ describe('Expression - Aggregation Accumulators', function() {
1212

1313
it('should compile PUSH function', function() {
1414
const { expr } = MonSQLize;
15-
const expr = expr("PUSH(tag)");
15+
const expression = expr("PUSH(tag)");
1616

17-
assert(expr.__expr__);
18-
assert.strictEqual(expr.__expr__, "PUSH(tag)");
17+
assert(expression.__expr__);
18+
assert.strictEqual(expression.__expr__, "PUSH(tag)");
1919
});
2020

2121
it('should compile ADD_TO_SET function', function() {
2222
const { expr } = MonSQLize;
23-
const expr = expr("ADD_TO_SET(category)");
23+
const expression = expr("ADD_TO_SET(category)");
2424

25-
assert(expr.__expr__);
26-
assert.strictEqual(expr.__expr__, "ADD_TO_SET(category)");
25+
assert(expression.__expr__);
26+
assert.strictEqual(expression.__expr__, "ADD_TO_SET(category)");
2727
});
2828

2929
it('should compile COUNT function', function() {
3030
const { expr } = MonSQLize;
31-
const expr = expr("COUNT()");
31+
const expression = expr("COUNT()");
3232

33-
assert(expr.__expr__);
34-
assert.strictEqual(expr.__expr__, "COUNT()");
33+
assert(expression.__expr__);
34+
assert.strictEqual(expression.__expr__, "COUNT()");
3535
});
3636

3737
it('should compile SUM function', function() {
3838
const { expr } = MonSQLize;
39-
const expr = expr("SUM(amount)");
39+
const expression = expr("SUM(amount)");
4040

41-
assert(expr.__expr__);
42-
assert.strictEqual(expr.__expr__, "SUM(amount)");
41+
assert(expression.__expr__);
42+
assert.strictEqual(expression.__expr__, "SUM(amount)");
4343
});
4444

4545
it('should compile AVG function', function() {
4646
const { expr } = MonSQLize;
47-
const expr = expr("AVG(price)");
47+
const expression = expr("AVG(price)");
4848

49-
assert(expr.__expr__);
50-
assert.strictEqual(expr.__expr__, "AVG(price)");
49+
assert(expression.__expr__);
50+
assert.strictEqual(expression.__expr__, "AVG(price)");
5151
});
5252

5353
it('should compile MAX function', function() {
5454
const { expr } = MonSQLize;
55-
const expr = expr("MAX(score)");
55+
const expression = expr("MAX(score)");
5656

57-
assert(expr.__expr__);
58-
assert.strictEqual(expr.__expr__, "MAX(score)");
57+
assert(expression.__expr__);
58+
assert.strictEqual(expression.__expr__, "MAX(score)");
5959
});
6060

6161
it('should compile MIN function', function() {
6262
const { expr } = MonSQLize;
63-
const expr = expr("MIN(value)");
63+
const expression = expr("MIN(value)");
6464

65-
assert(expr.__expr__);
66-
assert.strictEqual(expr.__expr__, "MIN(value)");
65+
assert(expression.__expr__);
66+
assert.strictEqual(expression.__expr__, "MIN(value)");
6767
});
6868
});
6969
});

0 commit comments

Comments
 (0)