fix: 修复#sqp测试用例的一些问题
This commit is contained in:
parent
5858dd7db0
commit
3b8892d3e1
|
|
@ -126,7 +126,7 @@ export default (storeGetter: () => DbStore<EntityDict, TestContext>) => {
|
|||
data: {
|
||||
id: userId,
|
||||
name: 'xxxc',
|
||||
nickname: 'ddd',idState: 'unverified', userState: 'normal',
|
||||
nickname: 'ddd', idState: 'unverified', userState: 'normal',
|
||||
token$player: [{
|
||||
id: v4(),
|
||||
action: 'create',
|
||||
|
|
@ -168,7 +168,7 @@ export default (storeGetter: () => DbStore<EntityDict, TestContext>) => {
|
|||
id: v4(),
|
||||
action: 'update',
|
||||
data: {
|
||||
name: 'xc',idState: 'unverified', userState: 'normal',
|
||||
name: 'xc', idState: 'unverified', userState: 'normal',
|
||||
token$player: [{
|
||||
id: v4(),
|
||||
action: 'update',
|
||||
|
|
@ -210,7 +210,7 @@ export default (storeGetter: () => DbStore<EntityDict, TestContext>) => {
|
|||
data: {
|
||||
id: v4(),
|
||||
name: 'xxxc',
|
||||
nickname: 'ddd',idState: 'unverified', userState: 'normal',
|
||||
nickname: 'ddd', idState: 'unverified', userState: 'normal',
|
||||
token$player: [{
|
||||
id: v4(),
|
||||
action: 'create',
|
||||
|
|
@ -258,7 +258,7 @@ export default (storeGetter: () => DbStore<EntityDict, TestContext>) => {
|
|||
data: {
|
||||
id: v4(),
|
||||
name: 'xxxc',
|
||||
nickname: 'ddd',idState: 'unverified', userState: 'normal',
|
||||
nickname: 'ddd', idState: 'unverified', userState: 'normal',
|
||||
token$player: [{
|
||||
id: v4(),
|
||||
action: 'create',
|
||||
|
|
@ -325,6 +325,32 @@ export default (storeGetter: () => DbStore<EntityDict, TestContext>) => {
|
|||
});
|
||||
|
||||
|
||||
/**
|
||||
* Sub Query Predicate (#sqp) 语义说明:
|
||||
*
|
||||
* 基于"空集的全称量化"(vacuous truth)原则:
|
||||
*
|
||||
* 1. '#sqp': 'in' 或 无 #sqp
|
||||
* - 含义:存在至少一个关联记录满足条件
|
||||
* - 对于无关联记录的情况:返回 false(不匹配)
|
||||
*
|
||||
* 2. '#sqp': 'not in'
|
||||
* - 含义:不存在任何关联记录满足条件
|
||||
* - 对于无关联记录的情况:返回 true(匹配)
|
||||
*
|
||||
* 3. '#sqp': 'all'
|
||||
* - 含义:所有关联记录都满足条件
|
||||
* - 对于无关联记录的情况:返回 true(空集的全称量化为真)
|
||||
*
|
||||
* 4. '#sqp': 'not all'
|
||||
* - 含义:不是所有关联记录都满足条件(存在至少一个不满足)
|
||||
* - 对于无关联记录的情况:返回 false(空集中不存在不满足的记录)
|
||||
*
|
||||
* 示例:
|
||||
* - system 有 2 个 application,都满足条件 → 'all': true, 'not all': false
|
||||
* - system 有 2 个 application,1 个满足条件 → 'all': false, 'not all': true
|
||||
* - system 没有 application → 'all': true, 'not all': false
|
||||
*/
|
||||
it('[1.13]sub query predicate', async () => {
|
||||
const store = storeGetter();
|
||||
const context = new TestContext(store);
|
||||
|
|
@ -409,7 +435,8 @@ export default (storeGetter: () => DbStore<EntityDict, TestContext>) => {
|
|||
filter: {
|
||||
id: id1,
|
||||
application$system: {
|
||||
}
|
||||
},
|
||||
folder: '/test2',
|
||||
}
|
||||
}, {});
|
||||
assert(r1.length === 1, 'Expected 1 result for r1');
|
||||
|
|
@ -423,6 +450,7 @@ export default (storeGetter: () => DbStore<EntityDict, TestContext>) => {
|
|||
application$system: {
|
||||
'#sqp': 'not in',
|
||||
},
|
||||
folder: '/test2',
|
||||
},
|
||||
}, {});
|
||||
assert(r2.length === 0, 'Expected 0 results for r2');
|
||||
|
|
@ -439,6 +467,7 @@ export default (storeGetter: () => DbStore<EntityDict, TestContext>) => {
|
|||
},
|
||||
'#sqp': 'not in',
|
||||
},
|
||||
folder: '/test2',
|
||||
},
|
||||
}, {});
|
||||
assert(r22.length === 1, 'Expected 1 result for r22');
|
||||
|
|
@ -455,6 +484,7 @@ export default (storeGetter: () => DbStore<EntityDict, TestContext>) => {
|
|||
},
|
||||
'#sqp': 'all',
|
||||
},
|
||||
folder: '/test2',
|
||||
},
|
||||
}, {});
|
||||
assert(r23.length === 0, 'Expected 0 results for r23');
|
||||
|
|
@ -471,6 +501,7 @@ export default (storeGetter: () => DbStore<EntityDict, TestContext>) => {
|
|||
},
|
||||
'#sqp': 'not all',
|
||||
},
|
||||
folder: '/test2',
|
||||
},
|
||||
}, {});
|
||||
assert(r24.length === 1, 'Expected 1 result for r24');
|
||||
|
|
@ -484,10 +515,10 @@ export default (storeGetter: () => DbStore<EntityDict, TestContext>) => {
|
|||
application$system: {
|
||||
'#sqp': 'all',
|
||||
},
|
||||
folder: '/test2',
|
||||
},
|
||||
}, {});
|
||||
assert(r3.length === 0, 'Expected 0 results for r3');
|
||||
|
||||
assert(r3.length === 1, 'Expected 1 result for r3'); // #sqp: 'all' 无其他条件时,生成 not exists (... and false),永远为 true
|
||||
|
||||
const r4 = await context.select('system', {
|
||||
data: {
|
||||
|
|
@ -498,9 +529,10 @@ export default (storeGetter: () => DbStore<EntityDict, TestContext>) => {
|
|||
application$system: {
|
||||
'#sqp': 'not all',
|
||||
},
|
||||
folder: '/test2',
|
||||
},
|
||||
}, {});
|
||||
assert(r4.length === 1, 'Expected 1 result for r4');
|
||||
assert(r4.length === 0, 'Expected 0 results for r4'); // #sqp: 'not all' 无其他条件时,生成 exists (... and false),永远为 false
|
||||
|
||||
const r5 = await context.select('system', {
|
||||
data: {
|
||||
|
|
@ -512,6 +544,7 @@ export default (storeGetter: () => DbStore<EntityDict, TestContext>) => {
|
|||
},
|
||||
application$system: {
|
||||
},
|
||||
folder: '/test2',
|
||||
},
|
||||
}, {});
|
||||
assert(r5.length === 2, 'Expected 2 results for r5');
|
||||
|
|
@ -529,6 +562,7 @@ export default (storeGetter: () => DbStore<EntityDict, TestContext>) => {
|
|||
application$system: {
|
||||
'#sqp': 'not in',
|
||||
},
|
||||
folder: '/test2',
|
||||
},
|
||||
}, {});
|
||||
assert(r6.length === 1, 'Expected 1 result for r6');
|
||||
|
|
@ -545,9 +579,13 @@ export default (storeGetter: () => DbStore<EntityDict, TestContext>) => {
|
|||
application$system: {
|
||||
'#sqp': 'all',
|
||||
},
|
||||
folder: '/test2',
|
||||
},
|
||||
}, {});
|
||||
assert(r7.length === 0, 'Expected 0 results for r7');
|
||||
assert(r7.length === 3, 'Expected 3 results for r7'); // #sqp: 'all' 无其他条件时,永远为 true
|
||||
assert(r7.map(ele => ele.id).includes(id1), 'Expected r7 to include id1');
|
||||
assert(r7.map(ele => ele.id).includes(id2), 'Expected r7 to include id2');
|
||||
assert(r7.map(ele => ele.id).includes(id3), 'Expected r7 to include id3');
|
||||
|
||||
const r8 = await context.select('system', {
|
||||
data: {
|
||||
|
|
@ -560,12 +598,11 @@ export default (storeGetter: () => DbStore<EntityDict, TestContext>) => {
|
|||
application$system: {
|
||||
'#sqp': 'not all',
|
||||
},
|
||||
folder: '/test2',
|
||||
},
|
||||
}, {});
|
||||
assert(r8.length === 3, 'Expected 3 results for r8');
|
||||
assert(r8.map(ele => ele.id).includes(id1), 'Expected r8 to include id1');
|
||||
assert(r8.map(ele => ele.id).includes(id2), 'Expected r8 to include id2');
|
||||
assert(r8.map(ele => ele.id).includes(id3), 'Expected r8 to include id3');
|
||||
// r8: 'not all' 应该返回 0 条(因为所有有 application 的都满足 true)
|
||||
assert(r8.length === 0, 'Expected 0 results for r8');
|
||||
});
|
||||
|
||||
it('[1.1]子查询', async () => {
|
||||
|
|
@ -578,7 +615,7 @@ export default (storeGetter: () => DbStore<EntityDict, TestContext>) => {
|
|||
data: {
|
||||
id: v4(),
|
||||
name: 'xc',
|
||||
nickname: 'xc',idState: 'unverified', userState: 'normal',
|
||||
nickname: 'xc', idState: 'unverified', userState: 'normal',
|
||||
}
|
||||
}, context, {});
|
||||
|
||||
|
|
@ -611,7 +648,7 @@ export default (storeGetter: () => DbStore<EntityDict, TestContext>) => {
|
|||
data: {
|
||||
id,
|
||||
name: 'xc',
|
||||
nickname: 'xc',idState: 'unverified', userState: 'normal',
|
||||
nickname: 'xc', idState: 'unverified', userState: 'normal',
|
||||
}
|
||||
}, context, {});
|
||||
|
||||
|
|
@ -622,7 +659,7 @@ export default (storeGetter: () => DbStore<EntityDict, TestContext>) => {
|
|||
data: {
|
||||
id: id2,
|
||||
name: 'xzw',
|
||||
nickname: 'xzw22',idState: 'unverified', userState: 'normal',
|
||||
nickname: 'xzw22', idState: 'unverified', userState: 'normal',
|
||||
}
|
||||
}, context, {});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue