-
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.
fix: children one layer deep cannot resolve their parent controller (#…
…662) * fix: children one layer deep cannot resolve their parent controller/serializer * test: add unit tests for create-parent-builder util
- Loading branch information
1 parent
c8f0254
commit d9c538e
Showing
2 changed files
with
80 additions
and
3 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
src/packages/loader/builder/test/create-parent-builder.test.js
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,71 @@ | ||
// @flow | ||
import { posix } from 'path'; | ||
|
||
import { expect } from 'chai'; | ||
import { describe, it, beforeEach } from 'mocha'; | ||
|
||
import Controller from '../../../controller'; | ||
import Serializer from '../../../serializer'; | ||
import { FreezeableMap } from '../../../freezeable'; | ||
import createParentBuilder from '../utils/create-parent-builder'; | ||
|
||
describe('module "loader/builder"', () => { | ||
describe('util createParentBuilder()', () => { | ||
let subject; | ||
|
||
class ApplicationController extends Controller {} | ||
class ApiApplicationController extends Controller {} | ||
class ApiV1ApplicationController extends Controller {} | ||
|
||
beforeEach(() => { | ||
subject = createParentBuilder((key, target, parent) => { | ||
const namespace = posix.dirname(key).replace('.', ''); | ||
|
||
// $FlowIgnore | ||
const serializer = new Serializer({ | ||
namespace, | ||
model: null, | ||
parent: null | ||
}); | ||
|
||
return Reflect.construct(target, [{ | ||
parent, | ||
namespace, | ||
serializer, | ||
model: null | ||
}]); | ||
}); | ||
}); | ||
|
||
it('correctly builds parent objects', () => { | ||
subject(new FreezeableMap([ | ||
['root', new FreezeableMap([ | ||
['application', ApplicationController] | ||
])], | ||
['api', new FreezeableMap([ | ||
['application', ApiApplicationController] | ||
])], | ||
['api/v1', new FreezeableMap([ | ||
['application', ApiV1ApplicationController] | ||
])] | ||
])).forEach(({ key, parent }) => { | ||
switch (key) { | ||
case 'root': | ||
expect(parent).to.be.an.instanceOf(ApplicationController); | ||
break; | ||
|
||
case 'api': | ||
expect(parent).to.be.an.instanceOf(ApiApplicationController); | ||
break; | ||
|
||
case 'api/v1': | ||
expect(parent).to.be.an.instanceOf(ApiV1ApplicationController); | ||
break; | ||
|
||
default: | ||
throw new Error(`Unexpected key "${key}".`); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); |
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