62 lines
2.2 KiB
TypeScript
62 lines
2.2 KiB
TypeScript
import { TestContext } from "../Context";
|
|
import { EntityDict } from "../test-app-domain";
|
|
import { v4 } from 'uuid';
|
|
import assert from 'assert';
|
|
import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
|
|
import { describe, it, before, after } from 'mocha';
|
|
import { DbStore } from "../../lib/types/dbStore";
|
|
|
|
export default (storeGetter: () => DbStore<EntityDict, TestContext>) => {
|
|
|
|
// ==================== 子查询中的表达式测试 ====================
|
|
|
|
it('[12.1]expression in subquery filter', async () => {
|
|
const store = storeGetter();
|
|
const context = new TestContext(store);
|
|
await context.begin();
|
|
|
|
const systemId1 = v4();
|
|
const systemId2 = v4();
|
|
|
|
await store.operate('system', {
|
|
id: v4(),
|
|
action: 'create',
|
|
data: [
|
|
{
|
|
id: systemId1,
|
|
name: 'system_a',
|
|
description: 'test',
|
|
folder: '/a',
|
|
application$system: [
|
|
{ id: v4(), action: 'create', data: { id: v4(), name: 'app_a1', description: 't', type: 'web' } },
|
|
{ id: v4(), action: 'create', data: { id: v4(), name: 'app_a2', description: 't', type: 'web' } },
|
|
]
|
|
},
|
|
{
|
|
id: systemId2,
|
|
name: 'system_b',
|
|
description: 'test',
|
|
folder: '/b',
|
|
application$system: [
|
|
{ id: v4(), action: 'create', data: { id: v4(), name: 'other_b1', description: 't', type: 'web' } },
|
|
]
|
|
}
|
|
]
|
|
} as EntityDict['system']['CreateMulti'], context, {});
|
|
await context.commit();
|
|
|
|
// 查询: 存在以 'app_' 开头的 application 的 system
|
|
const r1 = await context.select('system', {
|
|
data: { id: 1, name: 1 },
|
|
filter: {
|
|
id: { $in: [systemId1, systemId2] },
|
|
application$system: {
|
|
name: { $startsWith: 'app_' }
|
|
}
|
|
}
|
|
}, {});
|
|
|
|
assert(r1.length === 1 && r1[0].id === systemId1, `Subquery with expression failed`);
|
|
});
|
|
|
|
} |