Skip to content

Commit

Permalink
feat(cli): change location fixtures service/repository
Browse files Browse the repository at this point in the history
  • Loading branch information
marioestradarosa committed Sep 27, 2018
1 parent 9bafc6d commit d4f5b5c
Show file tree
Hide file tree
Showing 10 changed files with 260 additions and 324 deletions.
3 changes: 0 additions & 3 deletions packages/cli/generators/service/index.js
Expand Up @@ -77,7 +77,6 @@ module.exports = class ServiceGenerator extends ArtifactGenerator {
* Ask for Service Name
*/
async promptArtifactName() {
if (this.shouldExit()) return false;
debug('Prompting for service name');

if (this.options.name) {
Expand All @@ -100,8 +99,6 @@ module.exports = class ServiceGenerator extends ArtifactGenerator {
}

async promptDataSourceName() {
if (this.shouldExit()) return false;

debug('Prompting for a datasource ');
let cmdDatasourceName;
let datasourcesList;
Expand Down
89 changes: 89 additions & 0 deletions packages/cli/test/fixtures/repository/index.js
@@ -0,0 +1,89 @@
const DATASOURCE_APP_PATH = 'src/datasources';
const MODEL_APP_PATH = 'src/models';
const CONFIG_PATH = '.';
const DUMMY_CONTENT = '--DUMMY VALUE--';
const fs = require('fs');

exports.SANDBOX_FILES = [
{
path: CONFIG_PATH,
file: 'myconfig.json',
content: JSON.stringify({
datasource: 'dbmem',
model: 'decoratordefined',
}),
},
{
path: DATASOURCE_APP_PATH,
file: 'dbkv.datasource.json',
content: JSON.stringify({
name: 'dbkv',
connector: 'kv-redis',
}),
},
{
path: DATASOURCE_APP_PATH,
file: 'dbkv.datasource.ts',
content: DUMMY_CONTENT,
},
{
path: DATASOURCE_APP_PATH,
file: 'dbmem.datasource.json',
content: JSON.stringify({
name: 'dbmem',
connector: 'memory',
}),
},
{
path: DATASOURCE_APP_PATH,
file: 'dbmem.datasource.ts',
content: DUMMY_CONTENT,
},
{
path: DATASOURCE_APP_PATH,
file: 'restdb.datasource.json',
content: JSON.stringify({
name: 'restdb',
connector: 'rest',
}),
},
{
path: DATASOURCE_APP_PATH,
file: 'restdb.datasource.ts',
content: DUMMY_CONTENT,
},
{
path: MODEL_APP_PATH,
file: 'decoratordefined.model.ts',
content: fs.readFileSync(
require.resolve('./models/decoratordefined.model.txt'),
{
encoding: 'utf-8',
},
),
},
{
path: MODEL_APP_PATH,
file: 'defaultmodel.model.ts',
content: fs.readFileSync(
require.resolve('./models/defaultmodel.model.txt'),
{
encoding: 'utf-8',
},
),
},
{
path: MODEL_APP_PATH,
file: 'multi-word.model.ts',
content: fs.readFileSync(require.resolve('./models/multi-word.model.txt'), {
encoding: 'utf-8',
}),
},
{
path: MODEL_APP_PATH,
file: 'invalid-id.model.ts',
content: fs.readFileSync(require.resolve('./models/invalid-id.model.txt'), {
encoding: 'utf-8',
}),
},
];
@@ -0,0 +1,17 @@
import {Entity, model} from '@loopback/repository';

@model({
name: 'Product',
properties: {
thePK: {type: 'number', id: true},
name: {type: 'string', required: true},
},
})
export class DecoratorDefined extends Entity {
thePK: number;
name: string;

constructor(data?: Partial<DecoratorDefined>) {
super(data);
}
}
@@ -0,0 +1,26 @@
import {Entity, model, property} from '@loopback/repository';

@model()
export class DefaultModel extends Entity {
@property({
type: 'number',
id: true,
default: 0,
})
id?: number;

@property({
type: 'string',
})
desc?: string;

@property({
type: 'number',
default: 0,
})
balance?: number;

constructor(data?: Partial<DefaultModel>) {
super(data);
}
}
20 changes: 20 additions & 0 deletions packages/cli/test/fixtures/repository/models/invalid-id.model.txt
@@ -0,0 +1,20 @@
import {Entity, model, property} from '@loopback/repository';

@model()
export class InvalidID extends Entity {
@property({
type: 'string',
required: true,
default: 0,
})
id: string;

@property({
type: 'string',
})
desc?: string;

constructor(data?: Partial<InvalidID>) {
super(data);
}
}
20 changes: 20 additions & 0 deletions packages/cli/test/fixtures/repository/models/multi-word.model.txt
@@ -0,0 +1,20 @@
import {Entity, model, property} from '@loopback/repository';

@model()
export class MultiWord extends Entity {
@property({
type: 'string',
id: true,
default: 0,
})
pk?: string;

@property({
type: 'string',
})
desc?: string;

constructor(data?: Partial<MultiWord>) {
super(data);
}
}
61 changes: 61 additions & 0 deletions packages/cli/test/fixtures/service/index.js
@@ -0,0 +1,61 @@
const DATASOURCE_APP_PATH = 'src/datasources';
const CONFIG_PATH = '.';
const DUMMY_CONTENT = '--DUMMY VALUE--';

exports.SANDBOX_FILES = [
{
path: CONFIG_PATH,
file: 'mysoapconfig.json',
content: JSON.stringify({
name: 'MultiWordService',
datasource: 'myds',
}),
},
{
path: CONFIG_PATH,
file: 'myrestconfig.json',
content: JSON.stringify({
name: 'myservice',
datasource: 'restdb',
}),
},
{
path: DATASOURCE_APP_PATH,
file: 'myds.datasource.json',
content: JSON.stringify({
name: 'myds',
connector: 'soap',
}),
},
{
path: DATASOURCE_APP_PATH,
file: 'myds.datasource.ts',
content: DUMMY_CONTENT,
},
{
path: DATASOURCE_APP_PATH,
file: 'dbmem.datasource.json',
content: JSON.stringify({
name: 'dbmem',
connector: 'memory',
}),
},
{
path: DATASOURCE_APP_PATH,
file: 'dbmem.datasource.ts',
content: DUMMY_CONTENT,
},
{
path: DATASOURCE_APP_PATH,
file: 'restdb.datasource.json',
content: JSON.stringify({
name: 'restdb',
connector: 'rest',
}),
},
{
path: DATASOURCE_APP_PATH,
file: 'restdb.datasource.ts',
content: DUMMY_CONTENT,
},
];

0 comments on commit d4f5b5c

Please sign in to comment.