"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var consts_1 = require("../consts");
var approval_engine_1 = require("../approval_engine");
jest.mock('../AI', function () { return ({ callAIReview: jest.fn() }); });
jest.mock('../notification', function () { return ({ sendNotifications: jest.fn() }); });
jest.mock('../agent', function () { return ({
    getReviewerAgentsInfo: jest.fn().mockResolvedValue({ userIds: ['agent-1'], clientUserIds: [] }),
}); });
jest.mock('../content_hub', function () { return ({ inventoryApprovalMaterial: jest.fn() }); });
jest.mock('../image_comparison', function () { return ({ isModifiedSubmission: jest.fn().mockResolvedValue(false) }); });
jest.mock('../material', function () { return (tslib_1.__assign(tslib_1.__assign({}, jest.requireActual('../material')), { getApproverFieldByType: jest.requireActual('../material').getApproverFieldByType, getUserReviewedAllMaterialsStatus: jest.fn().mockResolvedValue(consts_1.ApprovalStatus.approved), uploadBulkDocToOneDrive: jest.fn(), downloadBulkFromOneDriveDoc: jest.fn(), getOneDriveMaterials: jest.fn().mockResolvedValue([]), getPendingUploadsToOneDriveMaterials: jest.fn().mockResolvedValue([]), deleteBulkDocOneDriveShareLink: jest.fn() })); });
jest.mock('../../const', function () { return ({
    DCO_TYPES: ['MD-PO1-PO18'],
}); });
function makeMaterialApproval(overrides) {
    if (overrides === void 0) { overrides = {}; }
    return tslib_1.__assign({ _id: 'test-approval-id', classification: 'Brand KV', social_media: '', followers: 0, kol_classification: '', brief_flow_number: '', brief_flow: '', autonumber: '', name: 'Test Approval', product: 'Test Product', material_type: '', campaign_type: '', launch_time: '', available_channels: '', communication_context: '', content_rule: '', custom_tags: '', expiry_date: '', effective_date: '', bgm: '', subtitles: '', music_copyright: '', font_copyright: '', copyright_music: '', copyright_front: '', material_owner: '', child_files: 'no', kids_reviewer: '', kids_approval_status: '', kids_file_name: '', materials_quantity: 0, reviewer: [], assistance: '', approval_status: '', approval_materials_quantity: 0, ns_reviewer: ['ns-user-1'], ns_assistance: '', ns_approval_status: '', ns_materials_quantity: 0, legal_reviewer: ['legal-user-1'], legal_assistance: '', legal_approval_status: '', legal_materials_quantity: 0, sra_reviewer: ['sra-user-1'], sra_assistance: '', sra_approval_status: '', sra_materials_quantity: 0, ca_reviewer: ['ca-user-1'], ca_assistance: '', ca_approval_status: '', ca_materials_quantity: 0, owner: 'owner-user-1', current_step: consts_1.Step.draft, owner_department: '', review_status: '', person_pending_approve: '', person_view: '', person_approved: '', launch: '', postpone_launch_date: '', aunch_time: '', instance_state: '', space: 'test-space', materials_uploaded_to_onedrive_status: '', materials_xml_to_word_status: '', material_owner_id: '', external_submitted: false, is_external: false, internal_collaborator: '', is_skip_approver: false, pepsico_flow_rule: 'rule-1', shop_tag: '', pre_reviewer: '', pre_ns_reviewer: '', pre_sra_reviewer: '', pre_ca_reviewer: '', pre_legal_reviewer: '', pre_approval_status: '', pre_ns_approval_status: '', pre_sra_approval_status: '', pre_ca_approval_status: '', pre_legal_approval_status: '' }, overrides);
}
function createMockDB(options) {
    var _this = this;
    if (options === void 0) { options = {}; }
    var ruleFormula = options.ruleFormula || '${false}';
    var approvalRecords = {};
    var processRecords = [];
    var getObject = function (name) {
        if (name === 'pepsico_material_approval') {
            return {
                findOne: jest.fn(function (id) { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
                    return [2, approvalRecords[id]];
                }); }); }),
                update: jest.fn(function (id, data) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
                    return tslib_1.__generator(this, function (_a) {
                        approvalRecords[id] = tslib_1.__assign(tslib_1.__assign({}, approvalRecords[id]), data);
                        return [2, approvalRecords[id]];
                    });
                }); }),
                directUpdate: jest.fn(function (id, data) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
                    return tslib_1.__generator(this, function (_a) {
                        approvalRecords[id] = tslib_1.__assign(tslib_1.__assign({}, approvalRecords[id]), data);
                        return [2, approvalRecords[id]];
                    });
                }); }),
                find: jest.fn(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
                    return [2, Object.values(approvalRecords)];
                }); }); }),
            };
        }
        if (name === 'pepsico_approval_process') {
            return {
                find: jest.fn(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
                    return [2, processRecords];
                }); }); }),
                insert: jest.fn(function (data) { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
                    processRecords.push(data);
                    return [2, data];
                }); }); }),
                update: jest.fn(function (id, data) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
                    var idx;
                    return tslib_1.__generator(this, function (_a) {
                        idx = processRecords.findIndex(function (p) { return p._id === id; });
                        if (idx >= 0)
                            processRecords[idx] = tslib_1.__assign(tslib_1.__assign({}, processRecords[idx]), data);
                        return [2, processRecords[idx]];
                    });
                }); }),
                directUpdate: jest.fn(function (id, data) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
                    var idx;
                    return tslib_1.__generator(this, function (_a) {
                        idx = processRecords.findIndex(function (p) { return p._id === id; });
                        if (idx >= 0)
                            processRecords[idx] = tslib_1.__assign(tslib_1.__assign({}, processRecords[idx]), data);
                        return [2, processRecords[idx]];
                    });
                }); }),
                count: jest.fn(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
                    return [2, processRecords.length];
                }); }); }),
            };
        }
        if (name === 'pepsico_flow_rule') {
            return {
                findOne: jest.fn(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
                    return tslib_1.__generator(this, function (_a) {
                        return [2, ({
                                _id: 'rule-1',
                                name: ruleFormula,
                                skip_approve: null,
                            })];
                    });
                }); }),
                find: jest.fn(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
                    return tslib_1.__generator(this, function (_a) {
                        return [2, [{
                                    _id: 'rule-1',
                                    name: ruleFormula,
                                    skip_approve: null,
                                }]];
                    });
                }); }),
            };
        }
        if (name === 'pepsico_material') {
            return {
                find: jest.fn(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
                    return [2, []];
                }); }); }),
                directFind: jest.fn(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
                    return [2, []];
                }); }); }),
            };
        }
        return {
            find: jest.fn(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
                return [2, []];
            }); }); }),
            findOne: jest.fn(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
                return [2, null];
            }); }); }),
            update: jest.fn(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
                return [2, null];
            }); }); }),
            directUpdate: jest.fn(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
                return [2, null];
            }); }); }),
            insert: jest.fn(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
                return [2, null];
            }); }); }),
            count: jest.fn(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
                return [2, 0];
            }); }); }),
        };
    };
    return { approvalRecords: approvalRecords, processRecords: processRecords, getObject: getObject };
}
function createMockCtx(userId, db, options) {
    if (userId === void 0) { userId = 'user-1'; }
    var mockDB = db || createMockDB(options);
    return {
        ctx: {
            meta: {
                user: {
                    userId: userId,
                    name: 'Test User',
                    is_space_admin: false,
                    organization: { _id: 'org-1' },
                },
            },
            getObject: mockDB.getObject,
        },
        db: mockDB,
    };
}
describe('submitPreReviewContent', function () {
    describe('validation', function () {
        test('throws on invalid approval status', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
            var ctx;
            return tslib_1.__generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        ctx = createMockCtx().ctx;
                        return [4, expect((0, approval_engine_1.submitPreReviewContent)(ctx, 'test-id', 'invalid')).rejects.toThrow('无效的审核状态')];
                    case 1:
                        _a.sent();
                        return [2];
                }
            });
        }); });
        test('throws when current_step is not pre_review', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
            var _a, ctx, db, approval;
            return tslib_1.__generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        _a = createMockCtx('pre-user-1'), ctx = _a.ctx, db = _a.db;
                        approval = makeMaterialApproval({
                            current_step: consts_1.Step.departmental_review,
                            person_pending_approve: 'pre-user-1',
                            pre_reviewer: 'pre-user-1',
                        });
                        db.approvalRecords['test-id'] = approval;
                        return [4, expect((0, approval_engine_1.submitPreReviewContent)(ctx, 'test-id', consts_1.ApprovalStatus.approved)).rejects.toThrow('当前步骤不是预审步骤')];
                    case 1:
                        _b.sent();
                        return [2];
                }
            });
        }); });
        test('throws when user is not a pending pre-reviewer', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
            var _a, ctx, db, approval;
            return tslib_1.__generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        _a = createMockCtx('wrong-user'), ctx = _a.ctx, db = _a.db;
                        approval = makeMaterialApproval({
                            current_step: consts_1.Step.pre_review,
                            person_pending_approve: ['pre-user-1'],
                            pre_reviewer: 'pre-user-1',
                        });
                        db.approvalRecords['test-id'] = approval;
                        return [4, expect((0, approval_engine_1.submitPreReviewContent)(ctx, 'test-id', consts_1.ApprovalStatus.approved)).rejects.toThrow('您不是当前预审人')];
                    case 1:
                        _b.sent();
                        return [2];
                }
            });
        }); });
        test('throws when user cannot be mapped to a pre-review field', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
            var _a, ctx, db, approval;
            return tslib_1.__generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        _a = createMockCtx('unknown-pre-user'), ctx = _a.ctx, db = _a.db;
                        approval = makeMaterialApproval({
                            current_step: consts_1.Step.pre_review,
                            person_pending_approve: ['unknown-pre-user'],
                        });
                        db.approvalRecords['test-id'] = approval;
                        return [4, expect((0, approval_engine_1.submitPreReviewContent)(ctx, 'test-id', consts_1.ApprovalStatus.approved)).rejects.toThrow('无法确定预审字段')];
                    case 1:
                        _b.sent();
                        return [2];
                }
            });
        }); });
    });
    describe('field mapping', function () {
        test('maps pre_reviewer user to pre_approval_status field', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
            var _a, ctx, db, approval, e_1;
            return tslib_1.__generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        _a = createMockCtx('pre-user-1'), ctx = _a.ctx, db = _a.db;
                        approval = makeMaterialApproval({
                            _id: 'test-id',
                            current_step: consts_1.Step.pre_review,
                            person_pending_approve: ['pre-user-1'],
                            pre_reviewer: 'pre-user-1',
                            pre_approval_status: '',
                        });
                        db.approvalRecords['test-id'] = approval;
                        _b.label = 1;
                    case 1:
                        _b.trys.push([1, 3, , 4]);
                        return [4, (0, approval_engine_1.submitPreReviewContent)(ctx, 'test-id', consts_1.ApprovalStatus.approved)];
                    case 2:
                        _b.sent();
                        return [3, 4];
                    case 3:
                        e_1 = _b.sent();
                        expect(e_1.message).not.toContain('无法确定预审字段');
                        return [3, 4];
                    case 4: return [2];
                }
            });
        }); });
        test('maps pre_ns_reviewer user to pre_ns_approval_status field', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
            var _a, ctx, db, approval, e_2;
            return tslib_1.__generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        _a = createMockCtx('pre-ns-user'), ctx = _a.ctx, db = _a.db;
                        approval = makeMaterialApproval({
                            _id: 'test-id',
                            current_step: consts_1.Step.pre_review,
                            person_pending_approve: ['pre-ns-user'],
                            pre_ns_reviewer: 'pre-ns-user',
                        });
                        db.approvalRecords['test-id'] = approval;
                        _b.label = 1;
                    case 1:
                        _b.trys.push([1, 3, , 4]);
                        return [4, (0, approval_engine_1.submitPreReviewContent)(ctx, 'test-id', consts_1.ApprovalStatus.approved)];
                    case 2:
                        _b.sent();
                        return [3, 4];
                    case 3:
                        e_2 = _b.sent();
                        expect(e_2.message).not.toContain('无法确定预审字段');
                        return [3, 4];
                    case 4: return [2];
                }
            });
        }); });
        test('maps pre_legal_reviewer user to pre_legal_approval_status field', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
            var _a, ctx, db, approval, e_3;
            return tslib_1.__generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        _a = createMockCtx('pre-legal-user'), ctx = _a.ctx, db = _a.db;
                        approval = makeMaterialApproval({
                            _id: 'test-id',
                            current_step: consts_1.Step.pre_review,
                            person_pending_approve: ['pre-legal-user'],
                            pre_legal_reviewer: 'pre-legal-user',
                        });
                        db.approvalRecords['test-id'] = approval;
                        _b.label = 1;
                    case 1:
                        _b.trys.push([1, 3, , 4]);
                        return [4, (0, approval_engine_1.submitPreReviewContent)(ctx, 'test-id', consts_1.ApprovalStatus.approved)];
                    case 2:
                        _b.sent();
                        return [3, 4];
                    case 3:
                        e_3 = _b.sent();
                        expect(e_3.message).not.toContain('无法确定预审字段');
                        return [3, 4];
                    case 4: return [2];
                }
            });
        }); });
        test('maps pre_sra_reviewer user to pre_sra_approval_status field', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
            var _a, ctx, db, approval, e_4;
            return tslib_1.__generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        _a = createMockCtx('pre-sra-user'), ctx = _a.ctx, db = _a.db;
                        approval = makeMaterialApproval({
                            _id: 'test-id',
                            current_step: consts_1.Step.pre_review,
                            person_pending_approve: ['pre-sra-user'],
                            pre_sra_reviewer: 'pre-sra-user',
                        });
                        db.approvalRecords['test-id'] = approval;
                        _b.label = 1;
                    case 1:
                        _b.trys.push([1, 3, , 4]);
                        return [4, (0, approval_engine_1.submitPreReviewContent)(ctx, 'test-id', consts_1.ApprovalStatus.approved)];
                    case 2:
                        _b.sent();
                        return [3, 4];
                    case 3:
                        e_4 = _b.sent();
                        expect(e_4.message).not.toContain('无法确定预审字段');
                        return [3, 4];
                    case 4: return [2];
                }
            });
        }); });
        test('maps pre_ca_reviewer user to pre_ca_approval_status field', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
            var _a, ctx, db, approval, e_5;
            return tslib_1.__generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        _a = createMockCtx('pre-ca-user'), ctx = _a.ctx, db = _a.db;
                        approval = makeMaterialApproval({
                            _id: 'test-id',
                            current_step: consts_1.Step.pre_review,
                            person_pending_approve: ['pre-ca-user'],
                            pre_ca_reviewer: 'pre-ca-user',
                        });
                        db.approvalRecords['test-id'] = approval;
                        _b.label = 1;
                    case 1:
                        _b.trys.push([1, 3, , 4]);
                        return [4, (0, approval_engine_1.submitPreReviewContent)(ctx, 'test-id', consts_1.ApprovalStatus.approved)];
                    case 2:
                        _b.sent();
                        return [3, 4];
                    case 3:
                        e_5 = _b.sent();
                        expect(e_5.message).not.toContain('无法确定预审字段');
                        return [3, 4];
                    case 4: return [2];
                }
            });
        }); });
        test('delegates can be resolved via approval_process record type', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
            var _a, ctx, db, approval, e_6;
            return tslib_1.__generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        _a = createMockCtx('delegate-user'), ctx = _a.ctx, db = _a.db;
                        approval = makeMaterialApproval({
                            _id: 'test-id',
                            current_step: consts_1.Step.pre_review,
                            person_pending_approve: ['delegate-user'],
                        });
                        db.approvalRecords['test-id'] = approval;
                        db.processRecords.push({
                            _id: 'process-1',
                            owner: 'delegate-user',
                            pepsico_material_approval: 'test-id',
                            current_step: consts_1.Step.pre_review,
                            space: 'test-space',
                            approved: 'progess',
                            type: consts_1.ProcessApprovalType.PreNS,
                        });
                        _b.label = 1;
                    case 1:
                        _b.trys.push([1, 3, , 4]);
                        return [4, (0, approval_engine_1.submitPreReviewContent)(ctx, 'test-id', consts_1.ApprovalStatus.approved)];
                    case 2:
                        _b.sent();
                        return [3, 4];
                    case 3:
                        e_6 = _b.sent();
                        expect(e_6.message).not.toContain('无法确定预审字段');
                        return [3, 4];
                    case 4: return [2];
                }
            });
        }); });
    });
});
describe('approvalContent — pre-review step', function () {
    test('personnel pre-review: approves and advances to personnel_review', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
        var db, ctx, approval, result;
        return tslib_1.__generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    db = createMockDB({ ruleFormula: '${true}' });
                    ctx = createMockCtx('pre-user-1', db).ctx;
                    approval = makeMaterialApproval({
                        _id: 'test-id',
                        current_step: consts_1.Step.pre_review,
                        person_pending_approve: ['pre-user-1'],
                        pre_reviewer: 'pre-user-1',
                        pre_approval_status: '',
                        pepsico_flow_rule: 'rule-1',
                    });
                    db.approvalRecords['test-id'] = approval;
                    return [4, approval_engine_1.approvalContent.call({}, ctx, 'test-id', { approveField: 'pre_approval_status' })];
                case 1:
                    result = _a.sent();
                    expect(result).toEqual({});
                    expect(db.approvalRecords['test-id'].current_step).toBe(consts_1.Step.personnel_review);
                    return [2];
            }
        });
    }); });
    test('departmental pre-review: waits for all pre-reviewers to complete', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
        var db, ctx, approval, result;
        return tslib_1.__generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    db = createMockDB({ ruleFormula: '${false}' });
                    ctx = createMockCtx('pre-ns-user', db).ctx;
                    approval = makeMaterialApproval({
                        _id: 'test-id',
                        current_step: consts_1.Step.pre_review,
                        person_pending_approve: ['pre-ns-user', 'pre-ca-user'],
                        pre_ns_reviewer: 'pre-ns-user',
                        pre_ns_approval_status: '',
                        pre_ca_reviewer: 'pre-ca-user',
                        pre_ca_approval_status: '',
                        pepsico_flow_rule: 'rule-1',
                    });
                    db.approvalRecords['test-id'] = approval;
                    return [4, approval_engine_1.approvalContent.call({}, ctx, 'test-id', { approveField: 'pre_ns_approval_status' })];
                case 1:
                    result = _a.sent();
                    expect(result).toEqual({});
                    return [2];
            }
        });
    }); });
});
describe('rejectContent — pre-review step', function () {
    test('departmental pre-review rejection: waits for all pre-reviewers', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
        var db, ctx, approval, result;
        return tslib_1.__generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    db = createMockDB({ ruleFormula: '${false}' });
                    ctx = createMockCtx('pre-ns-user', db).ctx;
                    approval = makeMaterialApproval({
                        _id: 'test-id',
                        current_step: consts_1.Step.pre_review,
                        person_pending_approve: ['pre-ns-user', 'pre-ca-user'],
                        pre_ns_reviewer: 'pre-ns-user',
                        pre_ns_approval_status: '',
                        pre_ca_reviewer: 'pre-ca-user',
                        pre_ca_approval_status: '',
                        pepsico_flow_rule: 'rule-1',
                    });
                    db.approvalRecords['test-id'] = approval;
                    return [4, approval_engine_1.rejectContent.call({}, ctx, 'test-id', { approveField: 'pre_ns_approval_status' })];
                case 1:
                    result = _a.sent();
                    expect(result).toEqual({});
                    return [2];
            }
        });
    }); });
});
describe('Pre-review departmental aggregation', function () {
    test('all departments approved → proceeds to departmental_review (approved)', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
        var db, ctx, approval, result, updatedRecord;
        return tslib_1.__generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    db = createMockDB({ ruleFormula: '${false}' });
                    ctx = createMockCtx('pre-ns-user', db).ctx;
                    approval = makeMaterialApproval({
                        _id: 'test-id',
                        current_step: consts_1.Step.pre_review,
                        person_pending_approve: ['pre-ns-user'],
                        pre_ns_reviewer: 'pre-ns-user',
                        pre_ns_approval_status: '',
                        pre_ca_reviewer: 'pre-ca-user',
                        pre_ca_approval_status: true,
                        pepsico_flow_rule: 'rule-1',
                    });
                    db.approvalRecords['test-id'] = approval;
                    return [4, approval_engine_1.approvalContent.call({}, ctx, 'test-id', { approveField: 'pre_ns_approval_status' })];
                case 1:
                    result = _a.sent();
                    expect(result).toEqual({});
                    updatedRecord = db.approvalRecords['test-id'];
                    expect(updatedRecord.current_step).toBe(consts_1.Step.departmental_review);
                    return [2];
            }
        });
    }); });
    test('some departments rejected → marks rejected depts, advances if others can proceed', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
        var db, ctx, approval, result, updated;
        return tslib_1.__generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    db = createMockDB({ ruleFormula: '${false}' });
                    ctx = createMockCtx('pre-ca-user', db).ctx;
                    approval = makeMaterialApproval({
                        _id: 'test-id',
                        current_step: consts_1.Step.pre_review,
                        person_pending_approve: ['pre-ca-user'],
                        pre_ns_reviewer: 'pre-ns-user',
                        pre_ns_approval_status: true,
                        pre_ca_reviewer: 'pre-ca-user',
                        pre_ca_approval_status: '',
                        pepsico_flow_rule: 'rule-1',
                    });
                    db.approvalRecords['test-id'] = approval;
                    return [4, approval_engine_1.rejectContent.call({}, ctx, 'test-id', { approveField: 'pre_ca_approval_status' })];
                case 1:
                    result = _a.sent();
                    expect(result).toEqual({});
                    updated = db.approvalRecords['test-id'];
                    expect(updated.ca_approval_status).toBe(false);
                    expect(updated.current_step).toBe(consts_1.Step.departmental_review);
                    return [2];
            }
        });
    }); });
    test('all departments rejected and no non-pre-review depts → rejects to submitter_revisions', function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
        var db, ctx, approval, result, updated;
        return tslib_1.__generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    db = createMockDB({ ruleFormula: '${false}' });
                    ctx = createMockCtx('pre-ca-user', db).ctx;
                    approval = makeMaterialApproval({
                        _id: 'test-id',
                        current_step: consts_1.Step.pre_review,
                        person_pending_approve: ['pre-ca-user'],
                        pre_ns_reviewer: 'pre-ns-user',
                        pre_ns_approval_status: false,
                        pre_legal_reviewer: 'pre-legal-user',
                        pre_legal_approval_status: false,
                        pre_sra_reviewer: 'pre-sra-user',
                        pre_sra_approval_status: false,
                        pre_ca_reviewer: 'pre-ca-user',
                        pre_ca_approval_status: '',
                        pepsico_flow_rule: 'rule-1',
                    });
                    db.approvalRecords['test-id'] = approval;
                    return [4, approval_engine_1.rejectContent.call({}, ctx, 'test-id', { approveField: 'pre_ca_approval_status' })];
                case 1:
                    result = _a.sent();
                    expect(result).toEqual({});
                    updated = db.approvalRecords['test-id'];
                    expect(updated.ns_approval_status).toBe(false);
                    expect(updated.legal_approval_status).toBe(false);
                    expect(updated.sra_approval_status).toBe(false);
                    expect(updated.ca_approval_status).toBe(false);
                    expect(updated.current_step).toBe(consts_1.Step.submitter_revisions);
                    return [2];
            }
        });
    }); });
});
//# sourceMappingURL=pre_review_flow.test.js.map