diff --git a/packages/cli/snapshots/integration/generators/datasource.integration.snapshots.js b/packages/cli/snapshots/integration/generators/datasource.integration.snapshots.js index 008d36503b06..f81f9054da9a 100644 --- a/packages/cli/snapshots/integration/generators/datasource.integration.snapshots.js +++ b/packages/cli/snapshots/integration/generators/datasource.integration.snapshots.js @@ -146,6 +146,65 @@ export class DsDataSource extends juggler.DataSource `; +exports[`lb4 datasource integration correctly coerces setting input of type object and array with config 1`] = ` +import {inject, lifeCycleObserver, LifeCycleObserver} from '@loopback/core'; +import {juggler} from '@loopback/repository'; + +const config = { + name: 'ds', + connector: 'rest', + localConfigOnly: true, + sharedData: {}, + forwardErrorToEnvironment: false, + skipInstall: true, + skipCache: true, + skipLocalCache: true, + force: true, + 'skip-cache': true, + 'skip-install': true, + resolved: '/home/aaqilniz/working-space/patrick/forked/loopback-next/packages/cli/generators/datasource/index.js', + namespace: 'home:aaqilniz:working-space:patrick:forked:loopback-next:packages:cli:datasource', + _: [], + config: '{"name":"ds","connector":"rest","options":"{\\"test\\": \\"value\\"}","operations":"[\\"get\\", \\"post\\"]"}', + yes: true, + 'force-install': false, + 'ask-answered': false, + c: '{"name":"ds","connector":"rest","options":"{\\"test\\": \\"value\\"}","operations":"[\\"get\\", \\"post\\"]"}', + y: [ + '@@_YEOMAN_EMPTY_MARKER_@@', + true + ], + options: { + test: 'value' + }, + operations: [ + 'get', + 'post' + ], + baseURL: null, + crud: false +}; + +// Observe application's life cycle to disconnect the datasource when +// application is stopped. This allows the application to be shut down +// gracefully. The \`stop()\` method is inherited from \`juggler.DataSource\`. +// Learn more at https://loopback.io/doc/en/lb4/Life-cycle.html +@lifeCycleObserver('datasource') +export class DsDataSource extends juggler.DataSource + implements LifeCycleObserver { + static dataSourceName = 'ds'; + static readonly defaultConfig = config; + + constructor( + @inject('datasources.config.ds', {optional: true}) + dsConfig: object = config, + ) { + super(dsConfig); + } +} + +`; + exports[`lb4 datasource integration scaffolds correct file with cloudant input 1`] = ` import {inject, lifeCycleObserver, LifeCycleObserver} from '@loopback/core'; diff --git a/packages/cli/test/integration/generators/datasource.integration.js b/packages/cli/test/integration/generators/datasource.integration.js index 88109f225bb1..81e3207d0ea3 100644 --- a/packages/cli/test/integration/generators/datasource.integration.js +++ b/packages/cli/test/integration/generators/datasource.integration.js @@ -131,6 +131,19 @@ describe('lb4 datasource integration', () => { checkDataSourceFilesAgainstSnapshot(); }); + + it('correctly coerces setting input of type object and array with config', async () => { + await testUtils + .executeGenerator(generator) + .inDir(sandbox.path, () => testUtils.givenLBProject(sandbox.path)) + .withArguments([ + '--config', + `${JSON.stringify(complexCLIInput)}`, + '--yes', + ]); + + checkDataSourceFilesAgainstSnapshot(); + }); }); function checkDataSourceFilesAgainstSnapshot() {