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

[Bug] enitites parsed from fixtures are empty and fail to persist #171

Open
DanielMenke opened this issue May 26, 2021 · 2 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@DanielMenke
Copy link

Your Environment

Software Version(s)
typeorm-fixtures 1.9.1
Node 15
npm/Yarn 1.22.5
Operating System Ubuntu

Hi there, thanks for this project.

I am currently trying to integrate it in the tests of my nest project, but cant get it to work properly.

When I try to get these fixtures

entity: Customer
items:
  customer1:
    company: '{{name.firstName}}'
    customerNumber: '{{datatype.number}}'
    baseFeeType: 'none'
    devices:
      - device1
  customer2:
    company: '{{name.firstName}}'
    customerNumber: '{{datatype.number}}'
    baseFeeType: 'monthly'
    devices:
      - device2
  customer3:
    company: '{{name.firstName}}'
    customerNumber: '{{datatype.number}}'
    baseFeeType: 'quarterly'
    devices:
      - device3
  customer4:
    company: '{{name.firstName}}'
    customerNumber: '{{datatype.number}}'
    baseFeeType: 'annually'
    devices:
      - device4

persisted to my test database with this code:

describe('BillingService', () => {
  let service: BillingService;

  beforeEach(async () => {
    const module: TestingModule = await Test.createTestingModule({
      imports: [
        SessionModule,
        TypeOrmModule.forRoot(testConfig),
        TypeOrmModule.forFeature([Bill]),
      ],
      providers: [BillingService],
    })
      .overrideProvider(TwilioService)
      .useValue({})
      .compile();

    const app = module.createNestApplication();
    await app.init();
    service = module.get<BillingService>(BillingService);

    const loader = new Loader();
    loader.load(__dirname + '/fixtures');
    const resolver = new Resolver();
    const fixtures = resolver.resolve(loader.fixtureConfigs);

    const connection: Connection = module.get(Connection);
    const builder = new Builder(connection, new Parser());

    for (const fixture of fixturesIterator(fixtures)) {
      const entity = await builder.build(fixture);
      console.log(entity);
      await getRepository(entity.constructor.name).save(entity);
    }
  });

  it('should be defined', () => {
    expect(service).toBeDefined();
  });
});

the console.log() always prints Customer {}, which is the correct type of entity, but empty, meaning it does not contain any of the fields mentioned in the fixture yaml, which again crashes the save call, because the database restrictions are not fullfilled.

Any suggestions what I can try to make it work?

@DanielMenke DanielMenke added the bug Something isn't working label May 26, 2021
@DanielMenke DanielMenke changed the title [Bug] [Bug] enitites parsed from fixtures are empty and fail to persist May 26, 2021
@wodka
Copy link

wodka commented Sep 11, 2022

for me this was having a @Exclude() annotation from class-transformer in the top of the entity.

@DanielMenke
Copy link
Author

@wodka this seems to help, although I would like to be able to still use the @Exclude annotation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants