Skip to content

Commit

Permalink
feat(service): Service skeleton - provider boots up
Browse files Browse the repository at this point in the history
Doesn't do anything else yet, mind.
  • Loading branch information
jezhiggins committed May 28, 2020
1 parent 772d5d5 commit 56883ad
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/components/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {}
3 changes: 3 additions & 0 deletions lib/components/services/localfilestorage/doc/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
description: 'Implements a local filestorage provider for the cloudstorage plugin.'
}
15 changes: 15 additions & 0 deletions lib/components/services/localfilestorage/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class LocalFilestorage {
boot (options) {
const cloudstorage = cloudstorageService(options)
cloudstorage.registerProvider(this)
}
} // class LocalFilestorage

function cloudstorageService (options) {
return options.bootedServices.cloudstorage
} // cloudstorageService

module.exports = {
serviceClass: LocalFilestorage,
bootAfter: ['cloudstorage']
}
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"codecov": "3.7.0",
"conventional-changelog-metahub": "4.0.1",
"cz-conventional-changelog": "3.2.0",
"dirty-chai": "2.0.1",
"mocha": "7.1.2",
"nyc": "15.0.1",
"semantic-release": "17.0.7",
Expand Down
26 changes: 26 additions & 0 deletions test/boot-service-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* eslint-env mocha */

const chai = require('chai')
chai.use(require('dirty-chai'))
const expect = chai.expect

const LocalStorageService = require('../lib/components/services/localfilestorage').serviceClass

describe('Boot localstorage service', () => {
it('localstorage registers with cloudstorage on boot', () => {
let registered = false
const localstorage = new LocalStorageService()

const options = {
bootedServices: {
cloudstorage: {
registerProvider: provider => { registered = (provider === localstorage) }
}
}
}

localstorage.boot(options)

expect(registered).to.be.true()
})
})

0 comments on commit 56883ad

Please sign in to comment.