Skip to content
This repository has been archived by the owner on Mar 26, 2021. It is now read-only.

Variables don't resolve Fake() expressions #98

Open
finestructure opened this issue Nov 9, 2018 · 1 comment
Open

Variables don't resolve Fake() expressions #98

finestructure opened this issue Nov 9, 2018 · 1 comment

Comments

@finestructure
Copy link

Describe the bug
I'm trying to set up a variable with a random number in order to test PUT updates:

variables:
  note_update: Update Fake(random.number)

requests:

  update_contract:
    url: Var(apiUrl)/v1/contract/JsonPath{{contract_list[0].id}}
    method: PUT
    headers:
      Authorization: Bearer Value(userToken.access_token)
    data:
      json:
        notes: Var(note_update)
    validate:
      code: 204

  validate_update:
    url: Var(apiUrl)/v1/contract/JsonPath{{contract_list[0].id}}
    method: GET
    headers:
      Authorization: Bearer Value(userToken.access_token)
    validate:
      code: 200
      json:
        notes: Var(note_update)

While this passes the test, it doesn't work as intended, because the value actually saved is literally

Update Fake(random.number)

and not something like

Update 32078

To Reproduce
Steps to reproduce the behavior

Expected behavior
Var(note_update) should resolve to Update \d+

Additional context

I have alternatively tried to rewrite my test as follows:

requests:

  update_contract:
    url: Var(apiUrl)/v1/contract/JsonPath{{contract_list[0].id}}
    method: PUT
    headers:
      Authorization: Bearer Value(userToken.access_token)
    data:
      json:
        notes: Update Fake(random.number)
    validate:
      code: 204

  validate_update:
    url: Var(apiUrl)/v1/contract/JsonPath{{contract_list[0].id}}
    method: GET
    headers:
      Authorization: Bearer Value(userToken.access_token)
    validate:
      code: 200
      json:
        notes: Value(update_contract.notes)

but this fails, because update_contract is a 204 - No content and therefore Value(update_contract.notes) is not available.

I can't see a way to provide a random input but also save it for later cross checking.

@jgroom33
Copy link
Collaborator

The workaround for this would be to use a service that returns the value:

Note: using stREST release 2.0 syntax

version: 1

requests:
  setValue:
    request:
      url: https://postman-echo.com/post
      method: POST
      postData:
        mimeType: application/json
        text: 
          value: <$ Faker("random.number") $>
    log: true
  useValue:
    request:
      url: https://postman-echo.com/post
      method: POST
      postData:
        mimeType: application/json
        text: 
          reused: <$ setValue.content.data.value $>
    log: true

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants