-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add unit tests for route namespaces (#410)
- Loading branch information
1 parent
29dab32
commit 73579fb
Showing
1 changed file
with
112 additions
and
0 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,112 @@ | ||
// @flow | ||
import { expect } from 'chai'; | ||
import { it, describe, before, beforeEach } from 'mocha'; | ||
|
||
import Namespace from '../namespace'; | ||
|
||
import setType from '../../../utils/set-type'; | ||
import { getTestApp } from '../../../../test/utils/get-test-app'; | ||
|
||
import type Controller from '../../controller'; | ||
|
||
describe('module "router/namespace"', () => { | ||
describe('class Namespace', () => { | ||
describe('#constructor()', () => { | ||
let root; | ||
let controller: Controller; | ||
let controllers; | ||
let createRootNamespace; | ||
const expectNamspaceToBeValid = (subject: Namespace, name, path) => { | ||
expect(subject).to.be.an.instanceof(Namespace); | ||
expect(subject).to.have.property('name', name); | ||
expect(subject).to.have.property('path', path); | ||
expect(subject).to.have.property('namespace', root); | ||
expect(subject).to.have.property('controller', controller); | ||
expect(subject).to.have.property('controllers', controllers); | ||
}; | ||
|
||
before(async () => { | ||
const app = await getTestApp(); | ||
|
||
controllers = app.controllers; | ||
|
||
controller = setType(() => { | ||
return controllers.get('admin/application'); | ||
}); | ||
|
||
createRootNamespace = (): Namespace => new Namespace({ | ||
controllers, | ||
path: '/', | ||
name: 'root', | ||
controller: setType(() => { | ||
return app.controllers.get('application'); | ||
}) | ||
}); | ||
}); | ||
|
||
beforeEach(() => { | ||
root = createRootNamespace(); | ||
}); | ||
|
||
it('constructs a valid instance of `Namespace`', () => { | ||
const subject = new Namespace({ | ||
controller, | ||
controllers, | ||
name: 'admin', | ||
path: '/admin', | ||
namespace: root | ||
}); | ||
|
||
expectNamspaceToBeValid(subject, 'admin', '/admin'); | ||
}); | ||
|
||
it('normalizes a name with a leading /', () => { | ||
const subject = new Namespace({ | ||
controller, | ||
controllers, | ||
name: '/admin', | ||
path: '/admin', | ||
namespace: root | ||
}); | ||
|
||
expectNamspaceToBeValid(subject, 'admin', '/admin'); | ||
}); | ||
|
||
it('normalizes a name with a trailing /', () => { | ||
const subject = new Namespace({ | ||
controller, | ||
controllers, | ||
name: 'admin/', | ||
path: '/admin', | ||
namespace: root | ||
}); | ||
|
||
expectNamspaceToBeValid(subject, 'admin', '/admin'); | ||
}); | ||
|
||
it('normalizes a path missing a leading /', () => { | ||
const subject = new Namespace({ | ||
controller, | ||
controllers, | ||
name: 'admin', | ||
path: 'admin', | ||
namespace: root | ||
}); | ||
|
||
expectNamspaceToBeValid(subject, 'admin', '/admin'); | ||
}); | ||
|
||
it('normalizes a path with a trailing /', () => { | ||
const subject = new Namespace({ | ||
controller, | ||
controllers, | ||
path: '/admin/', | ||
name: 'admin', | ||
namespace: root | ||
}); | ||
|
||
expectNamspaceToBeValid(subject, 'admin', '/admin'); | ||
}); | ||
}); | ||
}); | ||
}); |