-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- ControllerFactory.js now uses echoHandler to support international …
…messages. - coverage added for ControllerFactory.js
- Loading branch information
Showing
26 changed files
with
452 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
jest.mock('../lib/Builder'); | ||
|
||
const ControllerFactory = require('../lib/ControllerFactory'); | ||
|
||
describe('ControllerFactory test', () => { | ||
const errorSpy = []; | ||
const conf = { | ||
spy: [], | ||
corei18n: 'en', | ||
logger: { | ||
error (message) { | ||
errorSpy.push(message); | ||
} | ||
} | ||
}; | ||
const $ = { | ||
call: 'Dependency Manager Call Pointer' | ||
}; | ||
|
||
const routerSpy = []; | ||
const mockRouter = { get (route) { routerSpy.push(route); } } | ||
|
||
ControllerFactory(conf).build(mockRouter, $); | ||
|
||
test('a router is supplied to the build method', () => { | ||
expect(conf.spy.length).toBe(1); | ||
expect(typeof conf.spy[0]['Controller']).toBe('function'); | ||
}); | ||
|
||
test('a controller is legitimately assigned to router', () => { | ||
const controllerSpy = []; | ||
conf.spy[0]['Controller']( | ||
(dependencyManager) => { | ||
controllerSpy.push(dependencyManager); | ||
return { 'GET /someAction': 'someAction method' }; | ||
}, 'valid'); | ||
|
||
expect(controllerSpy[0]).toBe('Dependency Manager Call Pointer'); | ||
expect(routerSpy.length).toBe(1); | ||
expect(routerSpy[0]).toBe('/valid/someAction'); | ||
}); | ||
|
||
test('index controller is assigned without prefix', () => { | ||
const controllerSpy = []; | ||
conf.spy[0]['Controller']( | ||
(dependencyManager) => { | ||
controllerSpy.push(dependencyManager); | ||
return { 'GET /someAction': 'someAction method' }; | ||
}, 'Index'); | ||
|
||
expect(routerSpy.length).toBe(2); | ||
expect(routerSpy[1]).toBe('/someAction'); | ||
}); | ||
|
||
test('a controller has an invalid action', () => { | ||
const controllerSpy = []; | ||
conf.spy[0]['Controller']( | ||
(dependencyManager) => { | ||
controllerSpy.push(dependencyManager); | ||
return { 'GET/someAction': 'someAction method' }; | ||
}, 'invalid'); | ||
|
||
expect(errorSpy.length).toBe(2); | ||
expect(errorSpy[0]).toBe('failed'); | ||
expect(errorSpy[1]).toBe('badVerb: GET/someAction'); | ||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.