-
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.
refactor: cleanup unecessary controller props (#420)
* refactor: cleanup unecessary controller props * test: test against custom routes and model-less controllers
- Loading branch information
1 parent
a12bcad
commit 0e6ec39
Showing
7 changed files
with
189 additions
and
215 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
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
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,103 @@ | ||
// @flow | ||
import { expect } from 'chai'; | ||
import { it, describe, before } from 'mocha'; | ||
|
||
import { defaultParamsFor } from '../index'; | ||
|
||
import setType from '../../../../../utils/set-type'; | ||
import { getTestApp } from '../../../../../../test/utils/get-test-app'; | ||
|
||
import type Controller from '../../../../controller'; | ||
|
||
describe('module "router/route/params"', () => { | ||
describe('#defaultParamsFor()', () => { | ||
let getController; | ||
|
||
before(async () => { | ||
const { controllers } = await getTestApp(); | ||
|
||
getController = (name: string): Controller => setType(() => { | ||
return controllers.get(name); | ||
}); | ||
}); | ||
|
||
describe('with collection route', () => { | ||
let params; | ||
let controller; | ||
|
||
before(() => { | ||
controller = getController('posts'); | ||
params = defaultParamsFor({ | ||
controller, | ||
type: 'collection' | ||
}); | ||
}); | ||
|
||
it('contains sort', () => { | ||
expect(params).to.include.keys('sort'); | ||
}); | ||
|
||
it('contains page cursor', () => { | ||
expect(params).to.include.keys('page'); | ||
expect(params.page).to.include.keys('size', 'number'); | ||
}); | ||
|
||
it('contains model fields', () => { | ||
const { model, serializer: { attributes } } = controller; | ||
|
||
expect(params.fields).to.include.keys(model.resourceName); | ||
expect(params.fields[model.resourceName]).to.deep.equal(attributes); | ||
}); | ||
}); | ||
|
||
describe('with member route', () => { | ||
let params; | ||
let controller; | ||
|
||
before(() => { | ||
controller = getController('posts'); | ||
params = defaultParamsFor({ | ||
controller, | ||
type: 'member' | ||
}); | ||
}); | ||
|
||
it('contains model fields', () => { | ||
const { model, serializer: { attributes } } = controller; | ||
|
||
expect(params.fields).to.include.keys(model.resourceName); | ||
expect(params.fields[model.resourceName]).to.deep.equal(attributes); | ||
}); | ||
}); | ||
|
||
describe('with custom route', () => { | ||
let params; | ||
|
||
before(() => { | ||
params = defaultParamsFor({ | ||
type: 'custom', | ||
controller: getController('posts') | ||
}); | ||
}); | ||
|
||
it('is an empty object literal', () => { | ||
expect(params).to.deep.equal({}); | ||
}); | ||
}); | ||
|
||
describe('with model-less controller', () => { | ||
let params; | ||
|
||
before(() => { | ||
params = defaultParamsFor({ | ||
type: 'custom', | ||
controller: getController('health') | ||
}); | ||
}); | ||
|
||
it('is an empty object literal', () => { | ||
expect(params).to.deep.equal({}); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.