Imported follow-ups with no person, company, or deal stayed on the board because only linked prior records were archived. Co-authored-by: Cursor <cursoragent@cursor.com>
88 lines
3.1 KiB
TypeScript
88 lines
3.1 KiB
TypeScript
import { describe, it } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import {
|
|
activityPriorWhere,
|
|
dealPriorWhere,
|
|
listPriorLens,
|
|
personPriorWhere,
|
|
} from '../src/common/prior-archive';
|
|
|
|
const now = new Date('2026-10-15T08:00:00.000Z');
|
|
|
|
describe('بایگانی اطلاعات قبل', () => {
|
|
it('بدون مجوز فیلتر نمیگذارد', () => {
|
|
assert.deepEqual(personPriorWhere('off'), {});
|
|
assert.deepEqual(dealPriorWhere(undefined, now), {});
|
|
});
|
|
|
|
it('کار جاری شخص قبلی را کنار میگذارد و معاملهٔ بازِ موعددار را نگه میدارد', () => {
|
|
assert.deepEqual(personPriorWhere('current'), { importSource: { not: 'didar' } });
|
|
const where = dealPriorWhere('current', now);
|
|
assert.equal(where.OR?.length, 2);
|
|
assert.deepEqual(where.OR?.[1], {
|
|
importSource: 'didar',
|
|
status: 'open',
|
|
expectedCloseAt: { gt: now },
|
|
});
|
|
});
|
|
|
|
it('بایگانی فقط قبلیها را میآورد و استثنای باز را برمیدارد', () => {
|
|
const where = activityPriorWhere('archive', now);
|
|
assert.equal(where.importSource, 'didar');
|
|
assert.deepEqual(where.NOT, {
|
|
importSource: 'didar',
|
|
status: 'open',
|
|
dueAt: { gt: now },
|
|
});
|
|
});
|
|
|
|
it('فعالیت قدیمی روی شخص قبلی از کار جاری کنار میرود', () => {
|
|
const cutoff = new Date('2026-10-01T00:00:00.000Z');
|
|
const current = JSON.parse(JSON.stringify(activityPriorWhere('current', now, cutoff))) as {
|
|
OR: [
|
|
{
|
|
NOT: {
|
|
OR: [
|
|
{ importSource: string },
|
|
{
|
|
createdAt: { lt: string };
|
|
OR: Array<{ person?: { OR: Array<Record<string, string>> } }>;
|
|
},
|
|
];
|
|
};
|
|
},
|
|
{ status: string; dueAt: { gt: string } },
|
|
];
|
|
};
|
|
const linked = current.OR[0].NOT.OR[1];
|
|
assert.equal(linked.createdAt.lt, cutoff.toISOString());
|
|
assert.deepEqual(linked.OR[0], {
|
|
person: {
|
|
OR: [{ importSource: 'didar' }, { previousImportSource: 'didar' }],
|
|
},
|
|
});
|
|
assert.deepEqual(linked.OR[3], {
|
|
personId: null,
|
|
companyId: null,
|
|
dealId: null,
|
|
dueAt: { lt: cutoff.toISOString() },
|
|
});
|
|
assert.deepEqual(current.OR[1], { status: 'open', dueAt: { gt: now.toISOString() } });
|
|
|
|
const archive = JSON.parse(JSON.stringify(activityPriorWhere('archive', now, cutoff))) as {
|
|
AND: [unknown, { NOT: { status: string; dueAt: { gt: string } } }];
|
|
};
|
|
assert.deepEqual(archive.AND[0], current.OR[0].NOT);
|
|
assert.deepEqual(archive.AND[1], {
|
|
NOT: { status: 'open', dueAt: { gt: now.toISOString() } },
|
|
});
|
|
});
|
|
|
|
it('جستجوی کار جاری شخص قبلی را پیدا میکند', () => {
|
|
assert.equal(listPriorLens('current', 'علی', false), 'off');
|
|
assert.equal(listPriorLens('current', ' ', false), 'current');
|
|
assert.equal(listPriorLens('archive', 'علی', false), 'archive');
|
|
assert.equal(listPriorLens('current', '', true), 'off');
|
|
});
|
|
});
|