-
-
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.
- Loading branch information
1 parent
72f7ebc
commit dee4752
Showing
10 changed files
with
332 additions
and
23 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* @adonisjs/ally | ||
* | ||
* (c) AdonisJS | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
import { test } from '@japa/runner' | ||
import { HttpContextFactory } from '@adonisjs/core/factories/http' | ||
|
||
import { AllyManager } from '../src/ally_manager.js' | ||
import { GithubDriver } from '../src/drivers/github.js' | ||
|
||
test.group('Ally manager', () => { | ||
test('create an instance of a driver', ({ assert, expectTypeOf }) => { | ||
const ctx = new HttpContextFactory().create() | ||
|
||
const ally = new AllyManager( | ||
{ | ||
github: ($ctx) => { | ||
return new GithubDriver($ctx, { | ||
clientId: '', | ||
clientSecret: '', | ||
callbackUrl: '', | ||
}) | ||
}, | ||
}, | ||
ctx | ||
) | ||
|
||
assert.instanceOf(ally.use('github'), GithubDriver) | ||
assert.strictEqual(ally.use('github'), ally.use('github')) | ||
expectTypeOf(ally.use).parameters.toEqualTypeOf<['github']>() | ||
expectTypeOf(ally.use('github')).toMatchTypeOf<GithubDriver>() | ||
}) | ||
|
||
test('throw error when making an unknown driver', () => { | ||
const ctx = new HttpContextFactory().create() | ||
|
||
const ally = new AllyManager({}, ctx) | ||
;(ally.use as any)('github') | ||
}).throws( | ||
'Unknown ally provider "github". Make sure it is registered inside the config/ally.ts file' | ||
) | ||
}) |
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,51 @@ | ||
/* | ||
* @adonisjs/static | ||
* | ||
* (c) AdonisJS | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
import { test } from '@japa/runner' | ||
import { fileURLToPath } from 'node:url' | ||
import { IgnitorFactory } from '@adonisjs/core/factories' | ||
import Configure from '@adonisjs/core/commands/configure' | ||
|
||
const BASE_URL = new URL('./tmp/', import.meta.url) | ||
|
||
test.group('Configure', (group) => { | ||
group.each.setup(({ context }) => { | ||
context.fs.baseUrl = BASE_URL | ||
context.fs.basePath = fileURLToPath(BASE_URL) | ||
}) | ||
|
||
test('create config file and register provider', async ({ assert }) => { | ||
const ignitor = new IgnitorFactory() | ||
.withCoreProviders() | ||
.withCoreConfig() | ||
.create(BASE_URL, { | ||
importer: (filePath) => { | ||
if (filePath.startsWith('./') || filePath.startsWith('../')) { | ||
return import(new URL(filePath, BASE_URL).href) | ||
} | ||
|
||
return import(filePath) | ||
}, | ||
}) | ||
|
||
const app = ignitor.createApp('web') | ||
await app.init() | ||
await app.boot() | ||
|
||
const ace = await app.container.make('ace') | ||
const command = await ace.create(Configure, ['../../index.js']) | ||
await command.exec() | ||
|
||
await assert.fileExists('config/ally.ts') | ||
await assert.fileExists('contracts/ally.ts') | ||
await assert.fileExists('.adonisrc.json') | ||
await assert.fileContains('.adonisrc.json', '@adonisjs/ally/ally_provider') | ||
await assert.fileContains('config/ally.ts', 'defineConfig') | ||
}) | ||
}) |
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,37 @@ | ||
/* | ||
* @adonisjs/ally | ||
* | ||
* (c) AdonisJS | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
import { test } from '@japa/runner' | ||
import { HttpContextFactory } from '@adonisjs/core/factories/http' | ||
|
||
import { AllyManager, defineConfig } from '../index.js' | ||
import { GithubDriver } from '../src/drivers/github.js' | ||
import type { GithubDriverContract } from '../src/types.js' | ||
|
||
test.group('Define config', () => { | ||
test('define manager config from user defined config', ({ assert, expectTypeOf }) => { | ||
const managerConfig = defineConfig({ | ||
github: { | ||
driver: 'github', | ||
clientId: '', | ||
clientSecret: '', | ||
callbackUrl: '', | ||
scopes: ['admin:org'], | ||
}, | ||
}) | ||
|
||
const ctx = new HttpContextFactory().create() | ||
const ally = new AllyManager(managerConfig, ctx) | ||
|
||
assert.instanceOf(ally.use('github'), GithubDriver) | ||
assert.strictEqual(ally.use('github'), ally.use('github')) | ||
expectTypeOf(ally.use).parameters.toEqualTypeOf<['github']>() | ||
expectTypeOf(ally.use('github')).toMatchTypeOf<GithubDriverContract>() | ||
}) | ||
}) |
Oops, something went wrong.