duckfficer-method-di
loads duckfficer-method entities from a path to provide a pleasure-di container
Installation
$ npm i duckfficer-method-di --save
# or
$ yarn add duckfficer-method-di
Features
- builds an object appending all method found in given paths
- validates input
- validates output
- emits events
builds an object appending all method found in given paths
const container = duckfficerMethodDi({
Gateway: 'gateways',
Service: 'services'
}, {
baseDir: path.join(__dirname, './__tests__/fixtures')
})
const { OrderService } = container
t.deepEqual(await OrderService.payment({
id: '123',
amount: 99
}), {
id: '123',
result: 'paying 99$'
})
validates input
const container = duckfficerMethodDi({
Gateway: 'gateways',
Service: 'services'
}, {
baseDir: path.join(__dirname, './__tests__/fixtures')
})
const { PayPalGateway } = container
const { originalError } = await t.throwsAsync(() => PayPalGateway.pay('100'), {
message: 'Invalid input'
})
t.like(originalError, {
message: 'Invalid number'
})
validates output
const container = duckfficerMethodDi({
Gateway: 'gateways',
Service: 'services'
}, {
baseDir: path.join(__dirname, './__tests__/fixtures')
})
const { PayPalGateway } = container
const { originalError } = await t.throwsAsync(() => PayPalGateway.pay(0), {
message: 'Invalid output'
})
t.like(originalError, {
message: 'Invalid string'
})
emits events
const container = duckfficerMethodDi({
Gateway: 'gateways',
Service: 'services'
}, {
baseDir: path.join(__dirname, './__tests__/fixtures')
})
const { PayPalGateway } = container
PayPalGateway.on('Paid', (payload) => {
t.log(payload)
t.pass()
})
return PayPalGateway.pay(100)
Object
duckfficerMethodDi(pathResolvers, [baseDir], [methodsPath]) ⇒ Param | Type | Default |
---|---|---|
pathResolvers | Object |
|
[baseDir] | String |
process.cwd() |
[methodsPath] | String |
methods |
Returns: Object
- container
License
© 2020-present Martin Rafael Gonzalez tin@devtin.io