1+ // import { expect } from 'chai'
2+ const { expect} = require ( 'chai' )
3+ // import rules from './index'
4+ const rules = require ( './index' )
5+
6+ const httpRule = rules [ 'no-duplicate-http-in-urls' ]
7+ const reports = [ ]
8+ const fakeContext = {
9+ report : ( { location, message } ) => {
10+ console . log ( `Error Report` )
11+ reports . push ( { location, message} )
12+ }
13+ }
14+
15+ describe ( '' , ( ) => {
16+ const fakeFlowConfig = { }
17+ it ( 'should report not report error if no nodes' , ( ) => {
18+ // Arrange
19+ const nodes = [ ]
20+ const createdFunction = httpRule . create ( fakeContext , fakeFlowConfig )
21+ // Act
22+ createdFunction . start ( fakeFlowConfig )
23+ nodes . forEach ( node => createdFunction [ "type:http in" ] ( node ) )
24+ createdFunction . end ( fakeFlowConfig )
25+ // Assert
26+ expect ( reports . length ) . to . equal ( 0 )
27+ } )
28+ it ( 'should report warning if two duplicate nodes' , ( ) => {
29+ // Arrange
30+ const nodeWithUrl = {
31+ config : {
32+ method : "GET" ,
33+ url : "http://nodered.org"
34+ }
35+ }
36+ const nodes = [ { id :1 , ...nodeWithUrl } , { id :2 , ...nodeWithUrl } ]
37+ const createdFunction = httpRule . create ( fakeContext , fakeFlowConfig )
38+ // Act
39+ createdFunction . start ( fakeFlowConfig )
40+ nodes . forEach ( node => createdFunction [ "type:http in" ] ( node ) )
41+ createdFunction . end ( fakeFlowConfig )
42+ // Assert
43+ expect ( reports . length ) . to . equal ( 1 )
44+ } )
45+ } )
0 commit comments