diff --git a/lib/rules/no-duplicate-html-in-url.spec.js b/lib/rules/no-duplicate-html-in-url.spec.js new file mode 100644 index 0000000..c3d86fb --- /dev/null +++ b/lib/rules/no-duplicate-html-in-url.spec.js @@ -0,0 +1,45 @@ +// import { expect } from 'chai' +const {expect} = require('chai') +// import rules from './index' +const rules = require('./index') + +const httpRule = rules['no-duplicate-http-in-urls'] +const reports = [] +const fakeContext = { + report: ({ location, message }) => { + console.log(`Error Report`) + reports.push({location, message}) + } +} + +describe('', () => { + const fakeFlowConfig = {} + it('should report not report error if no nodes', () => { + // Arrange + const nodes = [] + const createdFunction = httpRule.create(fakeContext, fakeFlowConfig) + // Act + createdFunction.start(fakeFlowConfig) + nodes.forEach(node => createdFunction["type:http in"](node)) + createdFunction.end(fakeFlowConfig) + // Assert + expect(reports.length).to.equal(0) + }) + it('should report warning if two duplicate nodes', () => { + // Arrange + const nodeWithUrl = { + config: { + method: "GET", + url: "http://nodered.org" + } + } + const nodes = [{id:1, ...nodeWithUrl},{id:2, ...nodeWithUrl}] + const createdFunction = httpRule.create(fakeContext, fakeFlowConfig) + // Act + createdFunction.start(fakeFlowConfig) + nodes.forEach(node => createdFunction["type:http in"](node)) + createdFunction.end(fakeFlowConfig) + // Assert + expect(reports.length).to.equal(1) + }) +}) \ No newline at end of file diff --git a/package.json b/package.json index ee15ccc..1c8a552 100644 --- a/package.json +++ b/package.json @@ -37,10 +37,14 @@ "nrlint-rules-eslint": "dist/nrlint-rules-function-eslint.html" } }, + "mocha": { + "spec": ["lib/rules/*.spec.js"] + }, "devDependencies": { "chai": "*", "fs-extra": "^10.0.0", "html-minifier": "^4.0.0", + "mocha": "^9.1.3", "webpack": "^5.37.1", "webpack-cli": "^4.7.0" },