Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Roadmap to 2.0 #3

Closed
6 of 12 tasks
RobinCK opened this issue Jan 2, 2019 · 7 comments
Closed
6 of 12 tasks

Roadmap to 2.0 #3

RobinCK opened this issue Jan 2, 2019 · 7 comments

Comments

@RobinCK
Copy link
Owner

RobinCK commented Jan 2, 2019

  • $ref support (fixture scope)
  • config support
  • configure faker locale (implemented in 1.8.0)
  • optional data
  • reference to property
  • extend fixtures file
  • logger / debug
  • integration tests
  • class-transformer support
  • require option for registred ts-node and other
  • support tree repository
  • optional ignoreDecorators [true/false] class-transformer decorators are ignored #87
@RobinCK RobinCK pinned this issue Jan 6, 2019
@diegolaciar
Copy link

+1 Integration tests

@byCedric
Copy link

Would love to see some "helper methods" to create fixtures from tests. 😄

@thonythony
Copy link

thonythony commented Jun 8, 2019

Hello @RobinCK, is support tree repository ready (as you checked in your list) ? I need this feature, if you have already developed, can you release it please (in 2.0.0-alpha by example) ?

@RobinCK
Copy link
Owner Author

RobinCK commented Jun 9, 2019

@aynik
Copy link

aynik commented Jan 30, 2020

Looks like at the moment we cannot use @references when we define relation columns with @RelationId(). Is there a plan to support this?

@kop7
Copy link

kop7 commented Feb 20, 2020

+1 configure faker locale

@RobinCK RobinCK unpinned this issue Mar 11, 2020
@RobinCK RobinCK pinned this issue Mar 11, 2020
@maximelafarie
Copy link

maximelafarie commented Mar 31, 2020

For those who are looking for a way to add custom and localized content to database, I share with you my workaround:

Add a processor to your entity:

entity: User
processor: ../processor/user.processor.ts # <-- the `processor` folder is at the same level than `src`
items:
  user{1..100}:
    produit: '@produit{1..5}'
    groupe: '@groupe{1..4}'
    bio: '{{lorem.paragraph}}'

In your processor, you can do the following (I let some of my custom methods and getters so you have an example of what you can do inside your processor):

⚠️ You don't have to install faker, it'll already import the one required by typeorm-fixtures!

import { IProcessor } from 'typeorm-fixtures-cli';
import { User } from '../src/user/user.entity';

import * as faker from 'faker';
faker.locale = 'fr'; // <-- Whatever locale you want

export default class UserProcessor implements IProcessor<User> {

  private randomNumberBetween(min: number, max: number): number {
    return Math.floor(Math.random() * (max - min + 1)) + min;
  }

  private get nameEmail(): object {
    const nom = faker.name.lastName();
    const prenom = faker.name.firstName();
    const email = `${prenom.toLowerCase()}.${nom.toLowerCase()}@domain.io`;

    return { nom, prenom, email };
  }

  private get randomAddress(): string {
    return `${this.randomNumberBetween(1, 100)} rue ${faker.address.streetName}`;
  }

  preProcess(name: string, object: any): any {
    // Add any prop you want to customize in your fixture
    return {
      ...object,
      ...this.nameEmail,
      civilite: this.randomNumberBetween(1, 2),
      telephone: faker.phone.phoneNumber,
      adresse: this.randomAddress,
      codePostal: faker.address.zipCode,
      ville: faker.address.city,
    };
  }

  postProcess(name: string, object: { [key: string]: any }): void {
    // Do some processing after data is persisted
  }
}

P.S.: If you're looking for the original faker repo, the one used by typeorm-fixtures is https://github.com/practicalmeteor/meteor-faker (it's slightly the same documentation).

Hope it will help you guys! 🤘

@RobinCK RobinCK closed this as completed Jul 11, 2022
@RobinCK RobinCK unpinned this issue Jul 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants