getbigger-io / prisma-fixtures

Prisma 2 Fixtures Management Tool
MIT License
25 stars 2 forks source link

[Bug] Calling faker functions with multiple parameters is broken #8

Open LinuCC opened 1 year ago

LinuCC commented 1 year ago

Trying to use functions like address.latitude (https://fakerjs.dev/api/address.html#latitude) with multiple parameters does not work.

Take this example:

entity: post
items:
    post{1..10}:
        latitude: '{{address.longitude(13, 6, 4)}}'

latitude becomes NaN and this leads to an error.

The problem arises from around here:

https://github.com/getbigger-io/prisma-fixtures/blob/bed45fdf82af1002cd51c527d71f5b0b5757884d/src/parsers/FakerParser.ts#L93-L104

13, 6, 4 is being parsed as a string and passed into address.longitude as the first parameter, which leads to some weird output by faker.

Simple & stupid workaround without rewriting the parsing logic: Maybe we can spread the params into the function if it is parsed as an array (address.longitude([13, 6, 4])) so there is some way to use the function (although then we would need to write helpers.arrayElement(["a", "b"]) as helpers.arrayElement([["a", "b"]])).