meta {
  name: fakerjs
  type: http
  seq: 1
}

post {
  url: {{host}}/api/echo/json
  body: json
  auth: none
}

body:json {
  {
    "hello": "bruno"
  }
}

assert {
  res.status: eq 200
}

script:pre-request {
  const { faker } = require('@faker-js/faker');
  const uuid = faker.string.uuid();
  
  const data = req.getBody();
  data.uuid = uuid;
  
  req.setBody(data);
}

tests {
  test("should return json", function() {
    const data = res.getBody();
    const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
    const isUUID = (inputString) => {
      return uuidRegex.test(inputString);
    };
    
    expect(data.hello).to.equal("bruno");
    expect(isUUID(data.uuid)).to.be.true;
  });
  
}
