Skip to content

Commit

Permalink
improvement: rename to
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Jun 20, 2020
1 parent 7d8398c commit 4563a00
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 33 deletions.
5 changes: 4 additions & 1 deletion adonis-typings/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ declare module '@ioc:Adonis/Lucid/Factory' {
lorem: {
sentence (count?: number): string,
},
internet: {
password (): string,
},
},
sequence: {
username: string,
Expand Down Expand Up @@ -271,7 +274,7 @@ declare module '@ioc:Adonis/Lucid/Factory' {
/**
* Define a relationship on another factory
*/
related<K extends ExtractModelRelations<InstanceType<Model>>, Relation extends any> (
relation<K extends ExtractModelRelations<InstanceType<Model>>, Relation extends any> (
relation: K,
callback: Relation,
): this & { relations: { [P in K]: Relation } }
Expand Down
2 changes: 1 addition & 1 deletion example/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const UserF = F
.state('active', (user) => {
user.username = 'virk'
})
.related('profile', () => ProfileF)
.relation('profile', () => ProfileF)
.build()

UserF.with('profile', 1).merge({})
5 changes: 5 additions & 0 deletions src/Factory/FactoryContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export class FactoryContext implements FactoryContextContract {
return ''
},
},
internet: {
password () {
return ''
},
},
}

public sequence = {
Expand Down
2 changes: 1 addition & 1 deletion src/Factory/FactoryModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class FactoryModel<Model extends LucidModel> implements FactoryModelContr
/**
* Define a relationship on another factory
*/
public related<K extends ExtractModelRelations<InstanceType<Model>>> (
public relation<K extends ExtractModelRelations<InstanceType<Model>>> (
relation: Extract<K, string>,
callback: any,
): any {
Expand Down
12 changes: 6 additions & 6 deletions test/factory/belongs-to-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ test.group('Factory | BelongTo | make', (group) => {
displayName: 'virk',
}
})
.related('user', () => factory)
.relation('user', () => factory)
.build()

const factory = new FactoryModel(User, () => {
Expand Down Expand Up @@ -115,7 +115,7 @@ test.group('Factory | BelongTo | make', (group) => {
displayName: 'virk',
}
})
.related('user', () => factory)
.relation('user', () => factory)
.build()

const factory = new FactoryModel(User, () => {
Expand Down Expand Up @@ -178,7 +178,7 @@ test.group('Factory | BelongTo | create', (group) => {
displayName: 'virk',
}
})
.related('user', () => factory)
.relation('user', () => factory)
.build()

const factory = new FactoryModel(User, () => {
Expand Down Expand Up @@ -221,7 +221,7 @@ test.group('Factory | BelongTo | create', (group) => {
displayName: 'virk',
}
})
.related('user', () => factory)
.relation('user', () => factory)
.build()

const factory = new FactoryModel(User, () => {
Expand Down Expand Up @@ -267,7 +267,7 @@ test.group('Factory | BelongTo | create', (group) => {
displayName: 'virk',
}
})
.related('user', () => factory)
.relation('user', () => factory)
.build()

const factory = new FactoryModel(User, () => {
Expand Down Expand Up @@ -315,7 +315,7 @@ test.group('Factory | BelongTo | create', (group) => {
displayName: 'virk',
}
})
.related('user', () => factory)
.relation('user', () => factory)
.build()

/**
Expand Down
6 changes: 3 additions & 3 deletions test/factory/factory-model.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ test.group('Factory | Factory Model', (group) => {
User.boot()

function relatedFn () {}
const factory = new FactoryModel(User, () => new User()).related('profile', relatedFn)
const factory = new FactoryModel(User, () => new User()).relation('profile', relatedFn)
assert.property(factory.relations, 'profile')
assert.instanceOf(factory.relations.profile, FactoryHasOne)
})
Expand Down Expand Up @@ -150,7 +150,7 @@ test.group('Factory | Factory Model', (group) => {
return profileFactory
}

const factory = new FactoryModel(User, () => new User()).related('profile', relatedFn)
const factory = new FactoryModel(User, () => new User()).relation('profile', relatedFn)
assert.instanceOf(factory.getRelation('profile'), FactoryHasOne)
assert.deepEqual(factory.getRelation('profile').relation, User.$getRelation('profile')!)
})
Expand Down Expand Up @@ -187,7 +187,7 @@ test.group('Factory | Factory Model', (group) => {
public username: string
}

const factory = () => new FactoryModel(User, () => new User()).related('profile' as any, () => {})
const factory = () => new FactoryModel(User, () => new User()).relation('profile' as any, () => {})
assert.throw(
factory,
'Cannot define "profile" relationship. The relationship must exist on the "User" model first'
Expand Down
16 changes: 8 additions & 8 deletions test/factory/has-many.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ test.group('Factory | HasMany | make', (group) => {
const factory = new FactoryModel(User, () => {
return {}
})
.related('posts', () => postFactory)
.relation('posts', () => postFactory)
.build()

const user = await factory.with('posts').make()
Expand Down Expand Up @@ -121,7 +121,7 @@ test.group('Factory | HasMany | make', (group) => {
const factory = new FactoryModel(User, () => {
return {}
})
.related('posts', () => postFactory)
.relation('posts', () => postFactory)
.build()

const user = await factory
Expand Down Expand Up @@ -169,7 +169,7 @@ test.group('Factory | HasMany | make', (group) => {
const factory = new FactoryModel(User, () => {
return {}
})
.related('posts', () => postFactory)
.relation('posts', () => postFactory)
.build()

const user = await factory
Expand Down Expand Up @@ -237,7 +237,7 @@ test.group('Factory | HasMany | create', (group) => {
const factory = new FactoryModel(User, () => {
return {}
})
.related('posts', () => postFactory)
.relation('posts', () => postFactory)
.build()

const user = await factory.with('posts').create()
Expand Down Expand Up @@ -282,7 +282,7 @@ test.group('Factory | HasMany | create', (group) => {
const factory = new FactoryModel(User, () => {
return {}
})
.related('posts', () => postFactory)
.relation('posts', () => postFactory)
.build()

const user = await factory
Expand Down Expand Up @@ -330,7 +330,7 @@ test.group('Factory | HasMany | create', (group) => {
const factory = new FactoryModel(User, () => {
return {}
})
.related('posts', () => postFactory)
.relation('posts', () => postFactory)
.build()

const user = await factory
Expand Down Expand Up @@ -382,7 +382,7 @@ test.group('Factory | HasMany | create', (group) => {
const factory = new FactoryModel(User, () => {
return {}
})
.related('posts', () => postFactory)
.relation('posts', () => postFactory)
.build()

const user = await factory
Expand Down Expand Up @@ -430,7 +430,7 @@ test.group('Factory | HasMany | create', (group) => {
const factory = new FactoryModel(User, () => {
return {}
})
.related('posts', () => postFactory)
.relation('posts', () => postFactory)
.build()

try {
Expand Down
12 changes: 6 additions & 6 deletions test/factory/has-one.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ test.group('Factory | HasOne | make', (group) => {
const factory = new FactoryModel(User, () => {
return {}
})
.related('profile', () => profileFactory)
.relation('profile', () => profileFactory)
.build()

const user = await factory.with('profile').make()
Expand Down Expand Up @@ -120,7 +120,7 @@ test.group('Factory | HasOne | make', (group) => {
const factory = new FactoryModel(User, () => {
return {}
})
.related('profile', () => profileFactory)
.relation('profile', () => profileFactory)
.build()

const user = await factory
Expand Down Expand Up @@ -184,7 +184,7 @@ test.group('Factory | HasOne | create', (group) => {
const factory = new FactoryModel(User, () => {
return {}
})
.related('profile', () => profileFactory)
.relation('profile', () => profileFactory)
.build()

const user = await factory.with('profile').create()
Expand Down Expand Up @@ -228,7 +228,7 @@ test.group('Factory | HasOne | create', (group) => {
const factory = new FactoryModel(User, () => {
return {}
})
.related('profile', () => profileFactory)
.relation('profile', () => profileFactory)
.build()

const user = await factory
Expand Down Expand Up @@ -275,7 +275,7 @@ test.group('Factory | HasOne | create', (group) => {
const factory = new FactoryModel(User, () => {
return {}
})
.related('profile', () => profileFactory)
.relation('profile', () => profileFactory)
.build()

const user = await factory.with('profile').create()
Expand Down Expand Up @@ -319,7 +319,7 @@ test.group('Factory | HasOne | create', (group) => {
const factory = new FactoryModel(User, () => {
return {}
})
.related('profile', () => profileFactory)
.relation('profile', () => profileFactory)
.build()

try {
Expand Down
14 changes: 7 additions & 7 deletions test/factory/many-to-many.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ test.group('Factory | ManyToMany | make', (group) => {
const factory = new FactoryModel(User, () => {
return {}
})
.related('skills', () => postFactory)
.relation('skills', () => postFactory)
.build()

const user = await factory.with('skills').make()
Expand Down Expand Up @@ -120,7 +120,7 @@ test.group('Factory | ManyToMany | make', (group) => {
const factory = new FactoryModel(User, () => {
return {}
})
.related('skills', () => postFactory)
.relation('skills', () => postFactory)
.build()

const user = await factory.with('skills', 1, (related) => {
Expand Down Expand Up @@ -167,7 +167,7 @@ test.group('Factory | ManyToMany | make', (group) => {
const factory = new FactoryModel(User, () => {
return {}
})
.related('skills', () => postFactory)
.relation('skills', () => postFactory)
.build()

const user = await factory.with('skills', 2, (related) => {
Expand Down Expand Up @@ -236,7 +236,7 @@ test.group('Factory | ManyToMany | create', (group) => {
const factory = new FactoryModel(User, () => {
return {}
})
.related('skills', () => postFactory)
.relation('skills', () => postFactory)
.build()

const user = await factory.with('skills').create()
Expand Down Expand Up @@ -284,7 +284,7 @@ test.group('Factory | ManyToMany | create', (group) => {
const factory = new FactoryModel(User, () => {
return {}
})
.related('skills', () => postFactory)
.relation('skills', () => postFactory)
.build()

const user = await factory
Expand Down Expand Up @@ -335,7 +335,7 @@ test.group('Factory | ManyToMany | create', (group) => {
const factory = new FactoryModel(User, () => {
return {}
})
.related('skills', () => postFactory)
.relation('skills', () => postFactory)
.build()

const user = await factory
Expand Down Expand Up @@ -397,7 +397,7 @@ test.group('Factory | ManyToMany | create', (group) => {
const factory = new FactoryModel(User, () => {
return {}
})
.related('skills', () => postFactory)
.relation('skills', () => postFactory)
.build()

try {
Expand Down

0 comments on commit 4563a00

Please sign in to comment.