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

Providing String as a argument causes crash #1

Open
keinsell opened this issue May 8, 2024 · 11 comments
Open

Providing String as a argument causes crash #1

keinsell opened this issue May 8, 2024 · 11 comments

Comments

@keinsell
Copy link

keinsell commented May 8, 2024

I've tried multiple ways to pipe options to faker but cannot succeeded, when I do things like {{ lorem.lines | fake: 1 }} where argument is privitive things ten to work - but only when argument is integer; as soon as I will add string there is a crash.

Example: ${{ phone.number | fake: "+48#########" }}

To be checked on https://stepci.com/ playground.

@mishushakov
Copy link
Member

Playground was outdated. Feel free to reopen the issue if you're experiencing this on local

@HKandulla
Copy link

Hi @mishushakov ,
how can we pass objects to faker, as in faker.color.cmyk({ format: 'css' })
Thanks, Hannes

@mishushakov
Copy link
Member

mishushakov commented May 12, 2024

Like this?

{{color.cmyk | fake: {"format": "css"}}}

Keep in mind this is probably not possible to do in YAML, because of double quotes

@keinsell
Copy link
Author

I would be interesting in knowing real example how I can pass the object to faker for example, like @HKandulla mentioned, faker.color.cmyk({ format: 'css' }) inside of the .yaml test file that is run in stepci.

@keinsell
Copy link
Author

keinsell commented May 12, 2024

Playground was outdated. Feel free to reopen the issue if you're experiencing this on local

Problem is still persistent in playground and on my local machine, it's a real issue with stepci and how faker or liquidless is handled. And I cannot reopen the issue, can we cut the shit?

@mishushakov mishushakov reopened this May 12, 2024
@mishushakov
Copy link
Member

I have since added JSON5 support, you can now use single quotes for JSON objects:

version: "1.1"
name: Fake Data
tests:
  example:
    steps:
      - name: GET request
        http:
          url: "https://en.wikipedia.org/wiki/${{color.cmyk | fake: {'format': 'css'}}}"
          method: GET
          check:
            status: /^20/

@keinsell
Copy link
Author

Okay, that seems to work - however when I try to reference phone number format it does not :/

version: "1.1"
name: Fake Data
tests:
  example:
    steps:
      - name: GET request
        http:
          url: "https://en.wikipedia.org/wiki/${{ phone.number | fake: '+48#########' }}"
          method: GET
          check:
            status: /^20/

At this point I have no clue it's issue with faker (where function works in faker library used in way it should be parsed), liquidless (it seems to pass things correctly) or liquidless-faker (where something on the road is wrong)

@keinsell
Copy link
Author

Currently I've found workaround with exposing a endpoint on server that generates a random phone number that is later used in tests, but it would be good to more advanced fake data on the fly

@HKandulla
Copy link

HKandulla commented May 13, 2024

Hi @mishushakov ,

thanks for looking into this!
Adding JSON5 supports makes it possible to pass objects but faker still ignores the value.

Passing not format

version: "1.1"
    name: Fake Data
    tests:
      example:
        steps:
          - name: POST request
            http:
              url: "https://httpbin.org/post"
              method: POST
              json:
                name: default
                color: "${{color.cmyk | fake}}"
              check:
                status: /^20/

Request

POST https://httpbin.org/post HTTP/1.1
Content-Type: application/json

{"name":"default","color":"0.5,0.56,0.52,0.96"}

Passing format: css

version: "1.1"
name: Fake Data
tests:
  example:
    steps:
      - name: POST request
        http:
          url: "https://httpbin.org/post"
          method: POST
          json:
            name: test_css
            color: "${{color.cmyk | fake: {'format': 'css'}}}"
          check:
            status: /^20/

Request

POST https://httpbin.org/post HTTP/1.1
Content-Type: application/json

{"name":"test_css","color":"0.37,0.28,0.83,0.03}"}

Passing format: css should resolve to:
faker.color.cmyk({ format: 'css' }) // cmyk(100%, 0%, 0%, 0%)

When using liquidless-faker v1.3.2 standalone passing objects as parameters work:

import { renderString } from 'liquidless'
import { fake } from '../src'

const string = renderString("{{ color.cmyk | fake: {'format': 'css'} }}", {}, {
  filters: {
    fake
  }
})

console.log(string)

Output:

➜  liquidless-faker git:(main) ✗ npm run test

> [email protected] test
> ts-node ./tests/test.ts

cmyk(99%, 100%, 28%, 18%)

@mishushakov
Copy link
Member

Have you properly re-installed stepci?

@HKandulla
Copy link

Hi @mishushakov ,
sorry for my late reply..
Yes, I have re-installed stepci and also tried the following example using the playground on https://stepci.com/

Example:

version: "1.1"
name: Fake Data with objects as parameter
tests:
  example:
    steps:
      - name: POST request
        http:
          url: "https://httpbin.org/post"
          method: POST
          json:
            name: test_css
            color: "${{color.cmyk | fake: {'format': 'css'}}}"
          check:
            status: /^20/

Request is:

POST https://httpbin.org/post HTTP/1.1
Content-Type: application/json

{"name":"test_css","color":"0.02,0.92,0.41,0.9}"}

Request should be:

POST https://httpbin.org/post HTTP/1.1
Content-Type: application/json

{"name":"test_css","color":"cmyk(100%, 0%, 0%, 0%)}"}

See https://fakerjs.dev/api/color.html#cmyk

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

3 participants