|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const chai = require('chai'); |
| 4 | +const ruleModule = require('./../../../src/rules/description-format'); |
| 5 | +const lint = ruleModule.lint; |
| 6 | +const ruleType = ruleModule.ruleType; |
| 7 | + |
| 8 | +const should = chai.should(); |
| 9 | + |
| 10 | +describe('description-format Unit Tests', function() { |
| 11 | + context('a rule type value should be exported', function() { |
| 12 | + it('it should equal "object"', function() { |
| 13 | + ruleType.should.equal('object'); |
| 14 | + }); |
| 15 | + }); |
| 16 | + |
| 17 | + context('when package.json has node with incorrect format', function() { |
| 18 | + it('LintIssue object should be returned', function() { |
| 19 | + const packageJsonData = { |
| 20 | + description: true |
| 21 | + }; |
| 22 | + const config = { |
| 23 | + requireCapitalFirstLetter: true, |
| 24 | + requireEndingPeriod: true |
| 25 | + }; |
| 26 | + const response = lint(packageJsonData, 'error', config); |
| 27 | + |
| 28 | + response.lintId.should.equal('description-format'); |
| 29 | + response.severity.should.equal('error'); |
| 30 | + response.node.should.equal('description'); |
| 31 | + response.lintMessage.should.equal('Type should be a string'); |
| 32 | + }); |
| 33 | + }); |
| 34 | + |
| 35 | + context('when package.json has node with lowercase first letter', function() { |
| 36 | + it('LintIssue object should be returned', function() { |
| 37 | + const packageJsonData = { |
| 38 | + description: 'lowercase' |
| 39 | + }; |
| 40 | + const config = { |
| 41 | + requireCapitalFirstLetter: true |
| 42 | + }; |
| 43 | + const response = lint(packageJsonData, 'error', config); |
| 44 | + |
| 45 | + response.lintId.should.equal('description-format'); |
| 46 | + response.severity.should.equal('error'); |
| 47 | + response.node.should.equal('description'); |
| 48 | + response.lintMessage.should.equal('The description should start with a capital letter. It currently starts with l.'); |
| 49 | + }); |
| 50 | + }); |
| 51 | + |
| 52 | + context('when package.json has node without period at end', function() { |
| 53 | + it('LintIssue object should be returned', function() { |
| 54 | + const packageJsonData = { |
| 55 | + description: 'My description' |
| 56 | + }; |
| 57 | + const config = { |
| 58 | + requireEndingPeriod: true |
| 59 | + }; |
| 60 | + const response = lint(packageJsonData, 'error', config); |
| 61 | + |
| 62 | + response.lintId.should.equal('description-format'); |
| 63 | + response.severity.should.equal('error'); |
| 64 | + response.node.should.equal('description'); |
| 65 | + response.lintMessage.should.equal('The description should end with a period.'); |
| 66 | + }); |
| 67 | + }); |
| 68 | + |
| 69 | + context('when package.json has node with correct format', function() { |
| 70 | + it('LintIssue object should be returned', function() { |
| 71 | + const packageJsonData = { |
| 72 | + description: 'My description.' |
| 73 | + }; |
| 74 | + const config = { |
| 75 | + requireCapitalFirstLetter: true, |
| 76 | + requireEndingPeriod: true |
| 77 | + }; |
| 78 | + const response = lint(packageJsonData, 'error', config); |
| 79 | + |
| 80 | + response.should.be.true; |
| 81 | + }); |
| 82 | + }); |
| 83 | + |
| 84 | + context('when no rule config passed', function() { |
| 85 | + it('true should be returned', function() { |
| 86 | + const packageJsonData = { |
| 87 | + description: 'lowercase' |
| 88 | + }; |
| 89 | + const config = {}; |
| 90 | + const response = lint(packageJsonData, 'error', config); |
| 91 | + |
| 92 | + response.should.be.true; |
| 93 | + }); |
| 94 | + }); |
| 95 | + |
| 96 | + context('when package.json does not have node', function() { |
| 97 | + it('true should be returned', function() { |
| 98 | + const packageJsonData = {}; |
| 99 | + const config = { |
| 100 | + requireCapitalFirstLetter: true, |
| 101 | + requireEndingPeriod: true |
| 102 | + }; |
| 103 | + const response = lint(packageJsonData, 'error', config); |
| 104 | + |
| 105 | + response.should.be.true; |
| 106 | + }); |
| 107 | + }); |
| 108 | +}); |
0 commit comments