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: Couldn't extract the type #20

Closed
upMKuhn opened this issue Aug 6, 2021 · 9 comments
Closed

Bug: Couldn't extract the type #20

upMKuhn opened this issue Aug 6, 2021 · 9 comments
Labels
question Further information is requested

Comments

@upMKuhn
Copy link

upMKuhn commented Aug 6, 2021

Error: Couldn't extract the type of "checkId". Use @fixture({ type: () => Foo }).

Hi there,
thank you for your library. I think i stumbled upon a bug. Can you have a quick look, maybe I did something wrong here.

Stituation

    factory = new FixtureFactory();
    factory.register([OrderFileFake]); // works
    // factory.register([OrderFileFake, CheckFake]); // breaks

    currentOrderFile = factory
      .make(OrderFileFake)
      .with({
        order: {
          status: OrderStatus.RESULTS_PROVIDED,
          checks: [{ actor: { type: ActorType.CORPORATE } }, { actor: { type: ActorType.INDIVIDUAL } }], // works
          // checks: [].concat(CheckFake.coperateCheck(factory).many(2), CheckFake.indivdualCheck(factory).many(2)), // breaks
        },
      })
      .one();

Models

export class OrderFileFake implements IOrderFile {
  @Fixture({ type: () => OrderFake })
  public order: IOrder;

  @Fixture({ type: () => [CheckFake] })
  public checks: ICheck[];
}

export class CheckFake implements ICheck {
  @Fixture(uuid)
  public checkId: string;
}

Thanks!

@CyriacBr
Copy link
Owner

CyriacBr commented Aug 6, 2021

export class CheckFake implements ICheck {
@fixture(uuid)
public checkId: string;
}

What is uuid here?

@CyriacBr
Copy link
Owner

CyriacBr commented Aug 6, 2021

@upMKuhn Oh I guess you're trying to generate a random uuid for CheckFake.checkId? If so you could use faker directly.
Not sure of the correct API but it is something like that:

@Fixture(faker => faker.random.uuid())
public checkId: string

@CyriacBr CyriacBr added the question Further information is requested label Aug 7, 2021
@upMKuhn
Copy link
Author

upMKuhn commented Aug 9, 2021

Hey @CyriacBr, the error message is a bit misleading. The @Fixture(uuid) is unrelated. It could be replaced by anything else

I think the root cause of this error message might a circular dependency situation. Since I haven't included the entire Fixture setup. It wasn't clear in my original post:

OrderFileFake -> ICheck[] +(IOrder -> IActor).
ICheck -> IActor.
IActor -> ICheck.

@upMKuhn
Copy link
Author

upMKuhn commented Aug 9, 2021

The best indicator for it is:

    factory.register([OrderFileFake]); // works
    // factory.register([OrderFileFake, CheckFake]); // breaks
   
   checks: [{ actor: { type: ActorType.CORPORATE } }, { actor: { type: ActorType.INDIVIDUAL } }], // works
   // checks: [].concat(CheckFake.coperateCheck(factory).many(2), CheckFake.indivdualCheck(factory).many(2)), // breaks

@CyriacBr
Copy link
Owner

Going by the error message, the factory can't, for some reason find the type of checkId. So it is odd that explicitely setting the type (or an override value) doesn't work.
Can you show me all your entities?

If this is a relationships issue, that's probably fixed in this PR #17.

@upMKuhn
Copy link
Author

upMKuhn commented Aug 16, 2021

It hopefully will be fixed in the new PR then.
Unfortunately I don't have the factories anymore. In any case, I can put my hand for it into the flames that its related to complex nested and circular dependencies. It became clear to me during trial and error.

@upMKuhn
Copy link
Author

upMKuhn commented Aug 16, 2021

We can close here I'll watch and try again when the PR is merged.
Thats what I remember
OrderFile -> ICheck[] .
OrderFile -> IOrder

IOrder -> ICheck[]

ICheck -> IActor.
IActor -> ICheck.

@CyriacBr
Copy link
Owner

Alright, I'll close this.
But, could you just provide the classes at least? I'd like to test them on my end with the PR version.

@upMKuhn
Copy link
Author

upMKuhn commented Aug 16, 2021

I'll try to find them again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants