complete tests
This commit is contained in:
		
							
								
								
									
										7
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								index.js
									
									
									
									
									
								
							| @@ -11,10 +11,9 @@ module.exports = function (app, modulefolder, opts) { | |||||||
|   for (const f of fs.readdirSync(modulefolder)) { |   for (const f of fs.readdirSync(modulefolder)) { | ||||||
|     const regex = /(.*?)-(.*?)\.js/; |     const regex = /(.*?)-(.*?)\.js/; | ||||||
|     let [, method, url] = regex.exec(f); |     let [, method, url] = regex.exec(f); | ||||||
|     url = |     url = '/' + url + '/'; | ||||||
|       '/' + |     url = url | ||||||
|       url |       .replace(/^\/root/i, '/') | ||||||
|         .replace(/^root/i, '') |  | ||||||
|       .replace(/\./g, '/') |       .replace(/\./g, '/') | ||||||
|       .replace(/\/+/g, '/'); |       .replace(/\/+/g, '/'); | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										31
									
								
								test/main.js
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								test/main.js
									
									
									
									
									
								
							| @@ -1,4 +1,4 @@ | |||||||
| const { describe, it } = require('mocha'); | const { describe, it, beforeEach } = require('mocha'); | ||||||
| const expect = require('chai').expect; | const expect = require('chai').expect; | ||||||
|  |  | ||||||
| const requestor = require('../index'); | const requestor = require('../index'); | ||||||
| @@ -23,8 +23,12 @@ const mock = { | |||||||
| }; | }; | ||||||
|  |  | ||||||
| describe('requestor', () => { | describe('requestor', () => { | ||||||
|  |   beforeEach(() => { | ||||||
|  |     mock.registered = {}; | ||||||
|  |   }); | ||||||
|  |  | ||||||
|   it('should detect all requests on root', () => { |   it('should detect all requests on root', () => { | ||||||
|     requestor(mock, './test/onroot', {}); |     requestor(mock, './test/root', {}); | ||||||
|     expect(mock.registered).to.have.all.keys([ |     expect(mock.registered).to.have.all.keys([ | ||||||
|       'post-/', |       'post-/', | ||||||
|       'get-/', |       'get-/', | ||||||
| @@ -33,4 +37,27 @@ describe('requestor', () => { | |||||||
|       'all-/' |       'all-/' | ||||||
|     ]); |     ]); | ||||||
|   }); |   }); | ||||||
|  |  | ||||||
|  |   it('should detect requests on root.subfolder', () => { | ||||||
|  |     requestor(mock, './test/root.sub', {}); | ||||||
|  |     expect(mock.registered).to.have.all.keys([ | ||||||
|  |       'post-/sub/', | ||||||
|  |       'get-/sub/', | ||||||
|  |       'put-/sub/', | ||||||
|  |       'delete-/sub/', | ||||||
|  |       'all-/sub/' | ||||||
|  |     ]); | ||||||
|  |   }); | ||||||
|  |  | ||||||
|  |   it('should detect requests on subfolder', () => { | ||||||
|  |     requestor(mock, './test/sub', {}); | ||||||
|  |     expect(mock.registered).to.have.all.keys([ | ||||||
|  |       'post-/sub/', | ||||||
|  |       'get-/sub/', | ||||||
|  |       'put-/sub/', | ||||||
|  |       'delete-/sub/', | ||||||
|  |       'all-/sub/', | ||||||
|  |       'get-/sub/lv1/lv2/lv3/' | ||||||
|  |     ]); | ||||||
|  |   }); | ||||||
| }); | }); | ||||||
|   | |||||||
							
								
								
									
										3
									
								
								test/root/all-root.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								test/root/all-root.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | |||||||
|  | module.exports = (req, res, next, opts) => { | ||||||
|  |   // dummy endpoint: do nothing | ||||||
|  | }; | ||||||
							
								
								
									
										3
									
								
								test/root/delete-root.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								test/root/delete-root.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | |||||||
|  | module.exports = (req, res, next, opts) => { | ||||||
|  |   // dummy endpoint: do nothing | ||||||
|  | }; | ||||||
							
								
								
									
										3
									
								
								test/root/get-root.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								test/root/get-root.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | |||||||
|  | module.exports = (req, res, next, opts) => { | ||||||
|  |   // dummy endpoint: do nothing | ||||||
|  | }; | ||||||
							
								
								
									
										3
									
								
								test/root/not-root.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								test/root/not-root.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | |||||||
|  | module.exports = (req, res, next, opts) => { | ||||||
|  |   // dummy endpoint: do nothing | ||||||
|  | }; | ||||||
							
								
								
									
										3
									
								
								test/root/post-root.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								test/root/post-root.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | |||||||
|  | module.exports = (req, res, next, opts) => { | ||||||
|  |   // dummy endpoint: do nothing | ||||||
|  | }; | ||||||
							
								
								
									
										3
									
								
								test/root/put-root.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								test/root/put-root.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | |||||||
|  | module.exports = (req, res, next, opts) => { | ||||||
|  |   // dummy endpoint: do nothing | ||||||
|  | }; | ||||||
							
								
								
									
										3
									
								
								test/sub/all-sub.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								test/sub/all-sub.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | |||||||
|  | module.exports = (req, res, next, opts) => { | ||||||
|  |   // dummy endpoint: do nothing | ||||||
|  | }; | ||||||
							
								
								
									
										3
									
								
								test/sub/delete-sub.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								test/sub/delete-sub.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | |||||||
|  | module.exports = (req, res, next, opts) => { | ||||||
|  |   // dummy endpoint: do nothing | ||||||
|  | }; | ||||||
							
								
								
									
										3
									
								
								test/sub/get-sub.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								test/sub/get-sub.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | |||||||
|  | module.exports = (req, res, next, opts) => { | ||||||
|  |   // dummy endpoint: do nothing | ||||||
|  | }; | ||||||
							
								
								
									
										0
									
								
								test/sub/get-sub.lv1.lv2.lv3.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								test/sub/get-sub.lv1.lv2.lv3.js
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										3
									
								
								test/sub/not-sub.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								test/sub/not-sub.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | |||||||
|  | module.exports = (req, res, next, opts) => { | ||||||
|  |   // dummy endpoint: do nothing | ||||||
|  | }; | ||||||
							
								
								
									
										3
									
								
								test/sub/post-sub.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								test/sub/post-sub.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | |||||||
|  | module.exports = (req, res, next, opts) => { | ||||||
|  |   // dummy endpoint: do nothing | ||||||
|  | }; | ||||||
							
								
								
									
										3
									
								
								test/sub/put-sub.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								test/sub/put-sub.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | |||||||
|  | module.exports = (req, res, next, opts) => { | ||||||
|  |   // dummy endpoint: do nothing | ||||||
|  | }; | ||||||
		Reference in New Issue
	
	Block a user