This file contains hidden or 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
const SomeDependency = require('some-dependency') | |
const { TopLevelProcess } = require('./topLevelProcess') | |
describe('Stubbing a dependency passed to a constructor in an exported Node process', () => { | |
it('works as you would expect', () => { | |
const stubbedDependency = stub(new SomeDependency()) | |
new TopLevelProcess(stubbedDependency).start() | |
expect(/* something to have happened when `start()` is called */) |
This file contains hidden or 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
const proxyquire = require('proxyquire') | |
const SomeDependency = require('some-dependency') | |
describe('Stubbing a dependency passed to a constructor in a Node process', () => { | |
it('is not particularly elegant', () => { | |
const stubbedDependency = stub(new SomeDependency()) | |
const StubbedDependencyConstructor = () => stubbedDependency | |
proxyquire('./topLevelProcess', { 'some-dependency': StubbedDependencyConstructor }) | |
This file contains hidden or 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
const SomeDependency = require('some-dependency') | |
class TopLevelProcess { | |
constructor (someDependency) { ... } | |
start () { ... } | |
} | |
const process = new TopLevelProcess(new SomeDependency()) | |
process.start() |
This file contains hidden or 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
const SomeDependency = require('some-dependency') | |
class TopLevelProcess { | |
constructor (someDependency) { ... } | |
start () { ... } | |
} | |
const isNodeProcess = require.main === module | |
if (isNodeProcess) { | |
new TopLevelProcess(new SomeDependency()).start() |
This file contains hidden or 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
function (user, context, callback) { | |
var namespace = 'https://tojs.io/'; | |
context.accessToken[namespace + 'user_authorization'] = { | |
groups: user.app_metadata.groups, | |
roles: user.app_metadata.roles, | |
permissions: user.app_metadata.permissions | |
}; | |
return callback(null, user, context); | |
} |