diff --git a/src/define_config.ts b/src/define_config.ts index 4f0f057..a3f31e2 100644 --- a/src/define_config.ts +++ b/src/define_config.ts @@ -24,6 +24,7 @@ import type { AdonisFSDriverOptions, ServiceConfigProvider, ServiceWithLocalServer, + DriveManagerOptions, } from './types.js' import debug from './debug.js' @@ -33,6 +34,7 @@ import debug from './debug.js' type ResolvedConfig> = { config: { default: keyof Services + fakes: DriveManagerOptions['fakes'] services: { [K in keyof Services]: Services[K] extends ServiceConfigProvider ? A : Services[K] } @@ -45,12 +47,13 @@ type ResolvedConfig> = { */ export function defineConfig>(config: { default: keyof Services + fakes?: DriveManagerOptions['fakes'] services: { [K in keyof Services]: ServiceConfigProvider | Services[K] } }): ConfigProvider> { return configProvider.create(async (app) => { - const { services, default: defaultDisk } = config + const { services, fakes, default: defaultDisk } = config const servicesNames = Object.keys(services) /** @@ -80,6 +83,18 @@ export function defineConfig>(con return { config: { default: defaultDisk, + fakes: { + location: app.tmpPath('drive-fakes'), + urlBuilder: { + async generateURL(key, _) { + return `/drive/fakes/${key}` + }, + async generateSignedURL(key, _, __) { + return `/drive/fakes/signed/${key}` + }, + }, + ...fakes, + }, services: disks, }, locallyServed, diff --git a/tests/define_config.spec.ts b/tests/define_config.spec.ts index 8837aca..e52b750 100644 --- a/tests/define_config.spec.ts +++ b/tests/define_config.spec.ts @@ -28,13 +28,15 @@ test.group('Define config', () => { }, }) - const app = createAppWithRouter() + const app = await createAppWithRouter() const config = await configProvider.resolve(app, provider) assert.deepEqual(config.locallyServed, []) assert.containsSubset(config.config, { default: 'fs', services: {}, }) + assert.exists(config.config.fakes) + assert.equal(config.config.fakes.location, app.tmpPath('drive-fakes')) assert.isFunction(config.config.services.fs) assert.instanceOf(config.config.services.fs(), FSDriver) }) @@ -52,7 +54,7 @@ test.group('Define config', () => { }, }) - const app = createAppWithRouter() + const app = await createAppWithRouter() await assert.rejects( () => configProvider.resolve(app, provider), 'Invalid drive config. Missing "routeBasePath" option in "services.fs" object' @@ -72,7 +74,7 @@ test.group('Define config', () => { }, }) - const app = createAppWithRouter() + const app = await createAppWithRouter() const config = await configProvider.resolve(app, provider) assert.deepEqual(config.locallyServed, [ { @@ -100,7 +102,7 @@ test.group('Define config', () => { }, }) - const app = createAppWithRouter() + const app = await createAppWithRouter() const config = await configProvider.resolve(app, provider) assert.containsSubset(config.config, { default: 's3', @@ -121,7 +123,7 @@ test.group('Define config', () => { }, }) - const app = createAppWithRouter() + const app = await createAppWithRouter() const config = await configProvider.resolve(app, provider) assert.containsSubset(config.config, { default: 'gcs', diff --git a/tests/helpers.ts b/tests/helpers.ts index c911126..fbca5cd 100644 --- a/tests/helpers.ts +++ b/tests/helpers.ts @@ -34,9 +34,9 @@ export function createRouter() { return router } -export function createAppWithRouter() { +export async function createAppWithRouter() { const application = new AppFactory().create(BASE_URL) as unknown as ApplicationService - application.init() + await application.init() application.container.bind('router', () => createRouter()) return application