Skip to content

Commit

Permalink
feat: expose original client (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
paolochiodi authored Oct 20, 2020
1 parent 3085248 commit 896324c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ These are the available options:
- `namespace` (optional). If present, the plugin will add the secret values to `fastify.secrets.namespace` instead of `fastify.secrets`.
- `concurrency` (optional, defaults to 5). How many concurrent call will be made to `client.get`. This is handled by `fastify-secrets-core` and it's transparent to the implementation.

The plugin will also expose the original Client for uses outside of fastify (i.e. db migrations and scripts)

#### Example

Assuming a plugin is built as per the previous examples, it can be used as
Expand Down
5 changes: 4 additions & 1 deletion lib/build-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,13 @@ function buildPlugin(Client, pluginOpts) {
}
}

return fp(FastifySecretsPlugin, {
const plugin = fp(FastifySecretsPlugin, {
fastify: '3.x',
...pluginOpts
})
plugin.Client = Client

return plugin
}

module.exports = buildPlugin
8 changes: 6 additions & 2 deletions test/build-plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { test, beforeEach } = require('tap')
const sinon = require('sinon')
const proxyquire = require('proxyquire')

const fp = sinon.spy()
const fp = sinon.stub()
const buildPlugin = proxyquire('../lib/build-plugin', {
'fastify-plugin': fp
})
Expand All @@ -23,10 +23,12 @@ beforeEach(async () => {
sinon.resetHistory()
sinon.reset()
sinon.restore()

fp.returns({})
})

test('builds a fastify plugin', (t) => {
buildPlugin(Client, {
const plugin = buildPlugin(Client, {
option: 'option1'
})

Expand All @@ -37,6 +39,8 @@ test('builds a fastify plugin', (t) => {
t.equal(opts.fastify, '3.x', 'adds option for fastify support')
t.equal(opts.option, 'option1', 'forward provided options')

t.equal(plugin.Client, Client, 'also exports client')

t.end()
})

Expand Down

0 comments on commit 896324c

Please sign in to comment.