Skip to content

Commit

Permalink
feat(cli): add test for inclusion cli
Browse files Browse the repository at this point in the history
  • Loading branch information
Agnes Lin committed Oct 2, 2019
1 parent 7892d48 commit 4b7a0bf
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/cli/generators/relation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ module.exports = class RelationGenerator extends ArtifactGenerator {

async promptRegisterInclusionResolver() {
// should we let users decide the relation is traversable?
// or promt a warning msg: 'Notice not all models are traversable'
return this.prompt([
{
type: 'confirm',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,11 +436,13 @@ describe('lb4 relation', function() {
relationType: 'belongsTo',
sourceModel: 'OrderClass',
destinationModel: 'CustomerClass',
isInclusionResolverRegistered: false,
},
{
relationType: 'belongsTo',
sourceModel: 'OrderClassType',
destinationModel: 'CustomerClassType',
isInclusionResolverRegistered: false,
},
];

Expand Down Expand Up @@ -510,7 +512,7 @@ describe('lb4 relation', function() {
const singleWordClassConstractor = [
/public readonly customer: BelongsToAccessor<Customer, typeof Order\.prototype\.id>;\n/,
/constructor\(@inject\('datasources\.db'\) dataSource: DbDataSource, @repository\.getter\('CustomerRepository'\) protected customerRepositoryGetter: Getter<CustomerRepository>,\) \{\n/,
/super\(Order, dataSource\);\n {4}this\.customer = this\.createBelongsToAccessorFor\('customer', customerRepositoryGetter,\);\n {2}\}\n/,
/super\(Order, dataSource\);\n {4}this\.customer = this\.createBelongsToAccessorFor\('customer', customerRepositoryGetter,\);\n/,
];

const multiWordClassConstractor = [
Expand Down Expand Up @@ -540,6 +542,29 @@ describe('lb4 relation', function() {
assert.fileContent(sourceRepositoryFile, regex);
});
});

it('registers the inclusion resolver for the relation', async () => {
const singleWordClassConstractor = [
/this\.registerInclusionResolver\('customer', this\.customer\.inclusionResolver\);\n {2}\}\n/,
];
const multiWordClassConstractor = [];
const typeClassConstractor = [];

const sourceRepositoryFile = path.join(
SANDBOX_PATH,
REPOSITORY_APP_PATH,
repositoryFileName[i],
);

const updateConstructorRegEx = [
singleWordClassConstractor,
multiWordClassConstractor,
typeClassConstractor,
];
updateConstructorRegEx[i].forEach(regex => {
assert.fileContent(sourceRepositoryFile, regex);
});
});
}

context('generate model relation for existing property name', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -711,11 +711,13 @@ describe('lb4 relation HasMany', function() {
relationType: 'hasMany',
sourceModel: 'CustomerClass',
destinationModel: 'OrderClass',
isInclusionResolverRegistered: false,
},
{
relationType: 'hasMany',
sourceModel: 'CustomerClassType',
destinationModel: 'OrderClassType',
isInclusionResolverRegistered: false,
},
];

Expand Down Expand Up @@ -778,12 +780,11 @@ describe('lb4 relation HasMany', function() {
assert.fileContent(sourceRepositoryFile, regex);
});
});

it('repository has updated constructor', async () => {
const singleWordClassConstractor = [
/public readonly orders: HasManyRepositoryFactory<Order, typeof Customer\.prototype\.id>;\n/,
/constructor\(\@inject\('datasources\.db'\) dataSource: DbDataSource, \@repository\.getter\('OrderRepository'\) protected orderRepositoryGetter: Getter<OrderRepository>,\) \{\n/,
/super\(Customer, dataSource\);\n {4}this.orders = this.createHasManyRepositoryFactoryFor\('orders', orderRepositoryGetter,\);\n {2}\}\n/,
/super\(Customer, dataSource\);\n {4}this.orders = this.createHasManyRepositoryFactoryFor\('orders', orderRepositoryGetter,\);\n/,
];

const multiWordClassConstractor = [
Expand Down Expand Up @@ -812,6 +813,29 @@ describe('lb4 relation HasMany', function() {
assert.fileContent(sourceRepositoryFile, regex);
});
});

it('registers the inclusion resolver for the relation', async () => {
const singleWordClassConstractor = [
/this\.registerInclusionResolver\('orders', this\.orders\.inclusionResolver\);\n {2}\}\n/,
];
const multiWordClassConstractor = [];
const typeClassConstractor = [];

const sourceRepositoryFile = path.join(
SANDBOX_PATH,
REPOSITORY_APP_PATH,
repositoryFileName[i],
);

const updateConstructorRegEx = [
singleWordClassConstractor,
multiWordClassConstractor,
typeClassConstractor,
];
updateConstructorRegEx[i].forEach(regex => {
assert.fileContent(sourceRepositoryFile, regex);
});
});
}
});
});

0 comments on commit 4b7a0bf

Please sign in to comment.