UNPKG

declapract

Version:

A tool to declaratively define best practices, maintainable evolve them, and scalably enforce them.

95 lines 4.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const domain_1 = require("../../../domain"); const getRequiredActionForFile_1 = require("./getRequiredActionForFile"); describe('getRequiredActionForFile', () => { it('should find that if all the evaluations passed, the action is no change', () => { const action = (0, getRequiredActionForFile_1.getRequiredActionForFile)({ evaluations: [ { result: domain_1.FileEvaluationResult.PASS }, ], }); expect(action).toEqual(domain_1.RequiredAction.NO_CHANGE); }); it('should find that if an evaluation has failed a fixable best practice, the action is fix automatic', () => { const action = (0, getRequiredActionForFile_1.getRequiredActionForFile)({ evaluations: [ { result: domain_1.FileEvaluationResult.FAIL, path: '__path__', practice: {}, checks: [ { purpose: domain_1.FileCheckPurpose.BEST_PRACTICE, result: domain_1.FileEvaluationResult.FAIL, path: '__path__', fix: (() => '__new_contents__'), // fix is defined for the only check it has }, ], }, ], }); expect(action).toEqual(domain_1.RequiredAction.FIX_AUTOMATIC); }); it('should find that if an evaluation has failed a non-fixable best practice, the action is fix manual', () => { const action = (0, getRequiredActionForFile_1.getRequiredActionForFile)({ evaluations: [ { result: domain_1.FileEvaluationResult.FAIL, path: '__path__', practice: {}, checks: [ { purpose: domain_1.FileCheckPurpose.BEST_PRACTICE, result: domain_1.FileEvaluationResult.FAIL, path: '__path__', fix: null, // fix is NOT defined for the only check it has }, ], }, ], }); expect(action).toEqual(domain_1.RequiredAction.FIX_MANUAL); }); it('should find that if an evaluation has failed a fixable bad practice, the action is fix automatic', () => { const action = (0, getRequiredActionForFile_1.getRequiredActionForFile)({ evaluations: [ { result: domain_1.FileEvaluationResult.FAIL, path: '__path__', practice: {}, checks: [ { purpose: domain_1.FileCheckPurpose.BAD_PRACTICE, result: domain_1.FileEvaluationResult.FAIL, path: '__path__', fix: (() => '__new_contents__'), // fix is defined for the only check it has }, ], }, ], }); expect(action).toEqual(domain_1.RequiredAction.FIX_AUTOMATIC); }); it('should find that if an evaluation has failed a non-fixable bad practice, the action is fix manual', () => { const action = (0, getRequiredActionForFile_1.getRequiredActionForFile)({ evaluations: [ { result: domain_1.FileEvaluationResult.FAIL, path: '__path__', practice: {}, checks: [ { purpose: domain_1.FileCheckPurpose.BAD_PRACTICE, result: domain_1.FileEvaluationResult.FAIL, path: '__path__', fix: null, // fix is NOT defined for the only check it has }, ], }, ], }); expect(action).toEqual(domain_1.RequiredAction.FIX_MANUAL); }); }); //# sourceMappingURL=getRequiredActionForFile.test.js.map