From 4563a00d9b7cc90b87de90a775a80d29feb7eb28 Mon Sep 17 00:00:00 2001 From: Harminder virk Date: Tue, 26 May 2020 22:23:37 +0530 Subject: [PATCH] improvement: rename to --- adonis-typings/factory.ts | 5 ++++- example/index.ts | 2 +- src/Factory/FactoryContext.ts | 5 +++++ src/Factory/FactoryModel.ts | 2 +- test/factory/belongs-to-spec.ts | 12 ++++++------ test/factory/factory-model.spec.ts | 6 +++--- test/factory/has-many.spec.ts | 16 ++++++++-------- test/factory/has-one.spec.ts | 12 ++++++------ test/factory/many-to-many.spec.ts | 14 +++++++------- 9 files changed, 41 insertions(+), 33 deletions(-) diff --git a/adonis-typings/factory.ts b/adonis-typings/factory.ts index fcf5fd76..56832f24 100644 --- a/adonis-typings/factory.ts +++ b/adonis-typings/factory.ts @@ -82,6 +82,9 @@ declare module '@ioc:Adonis/Lucid/Factory' { lorem: { sentence (count?: number): string, }, + internet: { + password (): string, + }, }, sequence: { username: string, @@ -271,7 +274,7 @@ declare module '@ioc:Adonis/Lucid/Factory' { /** * Define a relationship on another factory */ - related>, Relation extends any> ( + relation>, Relation extends any> ( relation: K, callback: Relation, ): this & { relations: { [P in K]: Relation } } diff --git a/example/index.ts b/example/index.ts index 159235f6..e7518d00 100644 --- a/example/index.ts +++ b/example/index.ts @@ -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({}) diff --git a/src/Factory/FactoryContext.ts b/src/Factory/FactoryContext.ts index bcf37b5e..7819ff4f 100644 --- a/src/Factory/FactoryContext.ts +++ b/src/Factory/FactoryContext.ts @@ -17,6 +17,11 @@ export class FactoryContext implements FactoryContextContract { return '' }, }, + internet: { + password () { + return '' + }, + }, } public sequence = { diff --git a/src/Factory/FactoryModel.ts b/src/Factory/FactoryModel.ts index 46ec8497..9d6aaf62 100644 --- a/src/Factory/FactoryModel.ts +++ b/src/Factory/FactoryModel.ts @@ -105,7 +105,7 @@ export class FactoryModel implements FactoryModelContr /** * Define a relationship on another factory */ - public related>> ( + public relation>> ( relation: Extract, callback: any, ): any { diff --git a/test/factory/belongs-to-spec.ts b/test/factory/belongs-to-spec.ts index 8b22f8bb..40ffe09b 100644 --- a/test/factory/belongs-to-spec.ts +++ b/test/factory/belongs-to-spec.ts @@ -72,7 +72,7 @@ test.group('Factory | BelongTo | make', (group) => { displayName: 'virk', } }) - .related('user', () => factory) + .relation('user', () => factory) .build() const factory = new FactoryModel(User, () => { @@ -115,7 +115,7 @@ test.group('Factory | BelongTo | make', (group) => { displayName: 'virk', } }) - .related('user', () => factory) + .relation('user', () => factory) .build() const factory = new FactoryModel(User, () => { @@ -178,7 +178,7 @@ test.group('Factory | BelongTo | create', (group) => { displayName: 'virk', } }) - .related('user', () => factory) + .relation('user', () => factory) .build() const factory = new FactoryModel(User, () => { @@ -221,7 +221,7 @@ test.group('Factory | BelongTo | create', (group) => { displayName: 'virk', } }) - .related('user', () => factory) + .relation('user', () => factory) .build() const factory = new FactoryModel(User, () => { @@ -267,7 +267,7 @@ test.group('Factory | BelongTo | create', (group) => { displayName: 'virk', } }) - .related('user', () => factory) + .relation('user', () => factory) .build() const factory = new FactoryModel(User, () => { @@ -315,7 +315,7 @@ test.group('Factory | BelongTo | create', (group) => { displayName: 'virk', } }) - .related('user', () => factory) + .relation('user', () => factory) .build() /** diff --git a/test/factory/factory-model.spec.ts b/test/factory/factory-model.spec.ts index a627ef9d..be4391f5 100644 --- a/test/factory/factory-model.spec.ts +++ b/test/factory/factory-model.spec.ts @@ -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) }) @@ -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')!) }) @@ -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' diff --git a/test/factory/has-many.spec.ts b/test/factory/has-many.spec.ts index 0c9e74e4..132516a9 100644 --- a/test/factory/has-many.spec.ts +++ b/test/factory/has-many.spec.ts @@ -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() @@ -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 @@ -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 @@ -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() @@ -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 @@ -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 @@ -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 @@ -430,7 +430,7 @@ test.group('Factory | HasMany | create', (group) => { const factory = new FactoryModel(User, () => { return {} }) - .related('posts', () => postFactory) + .relation('posts', () => postFactory) .build() try { diff --git a/test/factory/has-one.spec.ts b/test/factory/has-one.spec.ts index 1f56b821..51954ede 100644 --- a/test/factory/has-one.spec.ts +++ b/test/factory/has-one.spec.ts @@ -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() @@ -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 @@ -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() @@ -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 @@ -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() @@ -319,7 +319,7 @@ test.group('Factory | HasOne | create', (group) => { const factory = new FactoryModel(User, () => { return {} }) - .related('profile', () => profileFactory) + .relation('profile', () => profileFactory) .build() try { diff --git a/test/factory/many-to-many.spec.ts b/test/factory/many-to-many.spec.ts index d89d2726..7d1d691b 100644 --- a/test/factory/many-to-many.spec.ts +++ b/test/factory/many-to-many.spec.ts @@ -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() @@ -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) => { @@ -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) => { @@ -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() @@ -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 @@ -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 @@ -397,7 +397,7 @@ test.group('Factory | ManyToMany | create', (group) => { const factory = new FactoryModel(User, () => { return {} }) - .related('skills', () => postFactory) + .relation('skills', () => postFactory) .build() try {