-
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: broken extend logic for ally manager
- Loading branch information
1 parent
745344f
commit 1a722f8
Showing
5 changed files
with
112 additions
and
3 deletions.
There are no files selected for viewing
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
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
File renamed without changes.
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,41 @@ | ||
/* | ||
* @adonisjs/ally | ||
* | ||
* (c) Harminder Virk <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
import { join } from 'path' | ||
import { Filesystem } from '@poppinss/dev-utils' | ||
import { Application } from '@adonisjs/core/build/standalone' | ||
|
||
export const fs = new Filesystem(join(__dirname, '__app')) | ||
|
||
export async function setup(setupProviders?: boolean) { | ||
const application = new Application(fs.basePath, 'web', { | ||
providers: ['@adonisjs/core', '../../providers/AllyProvider'], | ||
}) | ||
|
||
await fs.add( | ||
'config/app.ts', | ||
` | ||
export const profiler = { enabled: true } | ||
export const appKey = 'averylongrandomsecretkey' | ||
export const http = { | ||
trustProxy: () => {}, | ||
cookie: {} | ||
} | ||
` | ||
) | ||
|
||
await application.setup() | ||
|
||
if (setupProviders) { | ||
await application.registerProviders() | ||
await application.bootProviders() | ||
} | ||
|
||
return application | ||
} |
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,68 @@ | ||
/* | ||
* @adonisjs/ally | ||
* | ||
* (c) Harminder Virk <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
import test from 'japa' | ||
import { Ally } from '../src/Ally' | ||
import { AllyManager } from '../src/AllyManager' | ||
import { GithubDriver } from '../src/Drivers/Github' | ||
|
||
import { setup, fs } from '../test-helpers' | ||
|
||
test.group('AllyManager', (group) => { | ||
group.after(async () => { | ||
await fs.cleanup() | ||
}) | ||
|
||
test('make instance of a mapping', async (assert) => { | ||
const app = await setup(true) | ||
const manager = new AllyManager(app, { | ||
github: { | ||
driver: 'github', | ||
}, | ||
}) | ||
|
||
const HttpContext = app.container.resolveBinding('Adonis/Core/HttpContext') | ||
assert.instanceOf(manager.makeMapping(HttpContext.create('/', {}), 'github'), GithubDriver) | ||
}) | ||
|
||
test('register provider as singleton', async (assert) => { | ||
const app = await setup(true) | ||
assert.strictEqual( | ||
app.container.resolveBinding('Adonis/Addons/Ally'), | ||
app.container.resolveBinding('Adonis/Addons/Ally') | ||
) | ||
}) | ||
|
||
test('add ally getter to http context', async (assert) => { | ||
const app = await setup(true) | ||
const HttpContext = app.container.resolveBinding('Adonis/Core/HttpContext') | ||
|
||
assert.instanceOf(HttpContext.create('/', {}).ally, Ally) | ||
}) | ||
|
||
test('extend ally manager to add custom drivers', async (assert) => { | ||
const app = await setup(true) | ||
class MyCustomDriver {} | ||
|
||
const manager = new AllyManager(app, { | ||
foo: { | ||
driver: 'foo', | ||
}, | ||
}) | ||
manager.extend('foo', () => { | ||
return new MyCustomDriver() as any | ||
}) | ||
|
||
const HttpContext = app.container.resolveBinding('Adonis/Core/HttpContext') | ||
assert.instanceOf( | ||
manager.makeMapping(HttpContext.create('/', {}), 'foo' as any), | ||
MyCustomDriver | ||
) | ||
}) | ||
}) |