From a77b29777c5dddd2e3e6538dace960644a9add4a Mon Sep 17 00:00:00 2001 From: Agnes Lin Date: Mon, 7 Oct 2019 18:06:07 -0400 Subject: [PATCH] fix: update tests to use template string --- .../relation/belongs-to-relation.generator.js | 35 +++++++---------- .../relation/has-many-relation.generator.js | 39 ++++++------------- ...lation.belongs-to.integration.snapshots.js | 3 +- ...relation.has-many.integration.snapshots.js | 17 ++++---- .../relation.belongs-to.integration.js | 2 +- .../relation.has-many.integration.js | 2 +- 6 files changed, 38 insertions(+), 60 deletions(-) diff --git a/packages/cli/generators/relation/belongs-to-relation.generator.js b/packages/cli/generators/relation/belongs-to-relation.generator.js index eb24d63121b9..dc85a55fae09 100644 --- a/packages/cli/generators/relation/belongs-to-relation.generator.js +++ b/packages/cli/generators/relation/belongs-to-relation.generator.js @@ -103,7 +103,7 @@ module.exports = class BelongsToRelationGenerator extends BaseRelationGenerator getBelongsTo(className, relationName, fktype) { return { - decorators: [{name: 'belongsTo', arguments: ['() => ' + className]}], + decorators: [{name: 'belongsTo', arguments: [`() => ${className}`]}], name: relationName, type: fktype, }; @@ -132,26 +132,21 @@ module.exports = class BelongsToRelationGenerator extends BaseRelationGenerator _getRepositoryRelationPropertyType() { return ( - 'BelongsToAccessor<' + - utils.toClassName(this.artifactInfo.dstModelClass) + - ', typeof ' + - utils.toClassName(this.artifactInfo.srcModelClass) + - '.prototype.' + - this.artifactInfo.srcModelPrimaryKey + - '>' + `BelongsToAccessor<` + + `${utils.toClassName(this.artifactInfo.dstModelClass)}` + + `, typeof ${utils.toClassName(this.artifactInfo.srcModelClass)}` + + `.prototype.${this.artifactInfo.srcModelPrimaryKey}>` ); } _addCreatorToRepositoryConstructor(classConstructor) { + const relationPropertyName = this._getRepositoryRelationPropertyName(); const statement = - 'this.' + - this._getRepositoryRelationPropertyName() + - ' = ' + - "this.createBelongsToAccessorFor('" + - this.artifactInfo.relationName.replace(/Id$/, '') + - "', " + - utils.camelCase(this.artifactInfo.dstRepositoryClassName) + - 'Getter,);'; + `this.${relationPropertyName} = ` + + `this.createBelongsToAccessorFor('` + + `${this.artifactInfo.relationName.replace(/Id$/, '')}',` + + ` ${utils.camelCase(this.artifactInfo.dstRepositoryClassName)}` + + `Getter,);`; classConstructor.insertStatements(1, statement); } @@ -159,12 +154,8 @@ module.exports = class BelongsToRelationGenerator extends BaseRelationGenerator const relationPropertyName = this._getRepositoryRelationPropertyName(); if (options.registerInclusionResolver) { const statement = - "this.registerInclusionResolver('" + - relationPropertyName + - "', " + - 'this.' + - relationPropertyName + - '.inclusionResolver);'; + `this.registerInclusionResolver(` + + `'${relationPropertyName}', this.${relationPropertyName}.inclusionResolver);`; classConstructor.insertStatements(2, statement); } } diff --git a/packages/cli/generators/relation/has-many-relation.generator.js b/packages/cli/generators/relation/has-many-relation.generator.js index 310499c07af3..3c2e4199b169 100644 --- a/packages/cli/generators/relation/has-many-relation.generator.js +++ b/packages/cli/generators/relation/has-many-relation.generator.js @@ -137,14 +137,12 @@ module.exports = class HasManyRelationGenerator extends BaseRelationGenerator { let relationDecorator = [ { name: 'hasMany', - arguments: [ - '() => ' + className + " ,{keyTo: '" + foreignKeyName + "'}", - ], + arguments: [`() => ${className}, {keyTo: '${foreignKeyName}'}`], }, ]; if (isDefaultForeignKey) { relationDecorator = [ - {name: 'hasMany', arguments: ['() => ' + className]}, + {name: 'hasMany', arguments: [`() => ${className}`]}, ]; } @@ -172,28 +170,19 @@ module.exports = class HasManyRelationGenerator extends BaseRelationGenerator { } _getRepositoryRelationPropertyType() { - return ( - 'HasManyRepositoryFactory<' + - utils.toClassName(this.artifactInfo.dstModelClass) + - ', typeof ' + - utils.toClassName(this.artifactInfo.srcModelClass) + - '.prototype.' + - this.artifactInfo.srcModelPrimaryKey + - '>' - ); + return `HasManyRepositoryFactory<${utils.toClassName( + this.artifactInfo.dstModelClass, + )}, typeof ${utils.toClassName( + this.artifactInfo.srcModelClass, + )}.prototype.${this.artifactInfo.srcModelPrimaryKey}>`; } _addCreatorToRepositoryConstructor(classConstructor) { const relationPropertyName = this._getRepositoryRelationPropertyName(); const statement = - 'this.' + - relationPropertyName + - ' = ' + - "this.createHasManyRepositoryFactoryFor('" + - relationPropertyName + - "', " + - utils.camelCase(this.artifactInfo.dstRepositoryClassName) + - 'Getter,);'; + `this.${relationPropertyName} = ` + + `this.createHasManyRepositoryFactoryFor('${relationPropertyName}', ` + + `${utils.camelCase(this.artifactInfo.dstRepositoryClassName)}Getter,);`; classConstructor.insertStatements(1, statement); } @@ -201,12 +190,8 @@ module.exports = class HasManyRelationGenerator extends BaseRelationGenerator { const relationPropertyName = this._getRepositoryRelationPropertyName(); if (options.registerInclusionResolver) { const statement = - "this.registerInclusionResolver('" + - relationPropertyName + - "', " + - 'this.' + - relationPropertyName + - '.inclusionResolver);'; + `this.registerInclusionResolver(` + + `'${relationPropertyName}', this.${relationPropertyName}.inclusionResolver);`; classConstructor.insertStatements(2, statement); } } diff --git a/packages/cli/snapshots/integration/generators/relation.belongs-to.integration.snapshots.js b/packages/cli/snapshots/integration/generators/relation.belongs-to.integration.snapshots.js index 59c7625bdcb6..0876c78d3123 100644 --- a/packages/cli/snapshots/integration/generators/relation.belongs-to.integration.snapshots.js +++ b/packages/cli/snapshots/integration/generators/relation.belongs-to.integration.snapshots.js @@ -33,7 +33,7 @@ export class OrderRepository extends DefaultCrudRepository< `; exports[ - `lb4 relation checks generated source class repository answers {"relationType":"belongsTo","sourceModel":"OrderClass","destinationModel":"CustomerClass","registerInclusionResolver":false} generates OrderClass repository file with different inputs 1` + `lb4 relation checks generated source class repository answers {"relationType":"belongsTo","sourceModel":"OrderClass","destinationModel":"CustomerClass","registerInclusionResolver":true} generates OrderClass repository file with different inputs 1` ] = ` import {DefaultCrudRepository, repository, BelongsToAccessor} from '@loopback/repository'; import {OrderClass, CustomerClass} from '../models'; @@ -51,6 +51,7 @@ export class OrderClassRepository extends DefaultCrudRepository< constructor(@inject('datasources.myDB') dataSource: MyDBDataSource, @repository.getter('CustomerClassRepository') protected customerClassRepositoryGetter: Getter,) { super(OrderClass, dataSource); this.customerClass = this.createBelongsToAccessorFor('customerClassCustNumber', customerClassRepositoryGetter,); + this.registerInclusionResolver('customerClass', this.customerClass.inclusionResolver); } } diff --git a/packages/cli/snapshots/integration/generators/relation.has-many.integration.snapshots.js b/packages/cli/snapshots/integration/generators/relation.has-many.integration.snapshots.js index d6011ef7508f..ea4cc772e472 100644 --- a/packages/cli/snapshots/integration/generators/relation.has-many.integration.snapshots.js +++ b/packages/cli/snapshots/integration/generators/relation.has-many.integration.snapshots.js @@ -33,7 +33,7 @@ export class CustomerRepository extends DefaultCrudRepository< `; exports[ - `lb4 relation HasMany checks generated source class repository answers {"relationType":"hasMany","sourceModel":"CustomerClass","destinationModel":"OrderClass","registerInclusionResolver":false} generates CustomerClass repository file with different inputs 1` + `lb4 relation HasMany checks generated source class repository answers {"relationType":"hasMany","sourceModel":"CustomerClass","destinationModel":"OrderClass","registerInclusionResolver":true} generates CustomerClass repository file with different inputs 1` ] = ` import {DefaultCrudRepository, repository, HasManyRepositoryFactory} from '@loopback/repository'; import {CustomerClass, OrderClass} from '../models'; @@ -51,6 +51,7 @@ export class CustomerClassRepository extends DefaultCrudRepository< constructor(@inject('datasources.myDB') dataSource: MyDBDataSource, @repository.getter('OrderClassRepository') protected orderClassRepositoryGetter: Getter,) { super(CustomerClass, dataSource); this.orderClasses = this.createHasManyRepositoryFactoryFor('orderClasses', orderClassRepositoryGetter,); + this.registerInclusionResolver('orderClasses', this.orderClasses.inclusionResolver); } } @@ -448,7 +449,7 @@ export class Customer extends Entity { }) name?: string; - @hasMany(() => Order ,{keyTo: 'mykey'}) + @hasMany(() => Order, {keyTo: 'mykey'}) orders: Order[]; constructor(data?: Partial) { @@ -508,7 +509,7 @@ export class CustomerClass extends Entity { }) name?: string; - @hasMany(() => OrderClass ,{keyTo: 'mykey'}) + @hasMany(() => OrderClass, {keyTo: 'mykey'}) orderClasses: OrderClass[]; constructor(data?: Partial) { @@ -567,7 +568,7 @@ export class CustomerClassType extends Entity { }) name?: string; - @hasMany(() => OrderClassType ,{keyTo: 'mykey'}) + @hasMany(() => OrderClassType, {keyTo: 'mykey'}) orderClassTypes: OrderClassType[]; constructor(data?: Partial) { @@ -687,7 +688,7 @@ export class CustomerClass extends Entity { }) name?: string; - @hasMany(() => OrderClass ,{keyTo: 'customerClassCustNumber'}) + @hasMany(() => OrderClass, {keyTo: 'customerClassCustNumber'}) myOrders: OrderClass[]; constructor(data?: Partial) { @@ -746,7 +747,7 @@ export class CustomerClassType extends Entity { }) name?: string; - @hasMany(() => OrderClassType ,{keyTo: 'customerClassTypeCustNumber'}) + @hasMany(() => OrderClassType, {keyTo: 'customerClassTypeCustNumber'}) myOrders: OrderClassType[]; constructor(data?: Partial) { @@ -835,7 +836,7 @@ export class CustomerClass extends Entity { }) name?: string; - @hasMany(() => OrderClass ,{keyTo: 'customerClassCustNumber'}) + @hasMany(() => OrderClass, {keyTo: 'customerClassCustNumber'}) orderClasses: OrderClass[]; constructor(data?: Partial) { @@ -864,7 +865,7 @@ export class CustomerClassType extends Entity { }) name?: string; - @hasMany(() => OrderClassType ,{keyTo: 'customerClassTypeCustNumber'}) + @hasMany(() => OrderClassType, {keyTo: 'customerClassTypeCustNumber'}) orderClassTypes: OrderClassType[]; constructor(data?: Partial) { diff --git a/packages/cli/test/integration/generators/relation.belongs-to.integration.js b/packages/cli/test/integration/generators/relation.belongs-to.integration.js index 5f864e594806..54b1e2cb519a 100644 --- a/packages/cli/test/integration/generators/relation.belongs-to.integration.js +++ b/packages/cli/test/integration/generators/relation.belongs-to.integration.js @@ -343,7 +343,7 @@ describe('lb4 relation', function() { relationType: 'belongsTo', sourceModel: 'OrderClass', destinationModel: 'CustomerClass', - registerInclusionResolver: false, + registerInclusionResolver: true, }, { relationType: 'belongsTo', diff --git a/packages/cli/test/integration/generators/relation.has-many.integration.js b/packages/cli/test/integration/generators/relation.has-many.integration.js index 0e7b7ef7fd03..d49e9041a1f8 100644 --- a/packages/cli/test/integration/generators/relation.has-many.integration.js +++ b/packages/cli/test/integration/generators/relation.has-many.integration.js @@ -338,7 +338,7 @@ describe('lb4 relation HasMany', function() { relationType: 'hasMany', sourceModel: 'CustomerClass', destinationModel: 'OrderClass', - registerInclusionResolver: false, + registerInclusionResolver: true, }, { relationType: 'hasMany',