meta {
  name: objects/arrays interpolation
  type: http
  seq: 5
}

post {
  url: https://echo.usebruno.com
  body: json
  auth: none
}

body:json {
  {
   "undefined": "{{obj.undefined}}",
   "null": {{obj.null}},
   "number": {{obj.number}},
   "boolean": {{obj.boolean}},
   "array": {{arr}},
   "array[0]": {{arr[0]}},
   "object": {{obj}},
   "object.foo": {{obj.foo}},
   "object.foo.bar": {{obj.foo.bar}},
   "object.foo.bar.baz": {{obj.foo.bar.baz}}
  }
}

script:pre-request {
  bru.setVar("arr", [1,2,3,4,5]);
  
  bru.setVar("obj", {
    "null": null,
    "number": 1,
    "boolean": true,
    "foo": {
      "bar": {
        "baz": 1
      }
    }
  });
}

tests {
  test("should interpolate arrays and objects in request payload body", () => {
    const resBody = res.getBody();
    const expectedOutput = {
      "undefined": "{{obj.undefined}}",
      "null": null,
      "number": 1,
      "boolean": true,
      "array": [
        1,
        2,
        3,
        4,
        5
      ],
      "array[0]": 1,
      "object": {
        "null": null,
        "number": 1,
        "boolean": true,
        "foo": {
          "bar": {
            "baz": 1
          }
        }
      },
      "object.foo": {
        "bar": {
          "baz": 1
        }
      },
      "object.foo.bar": {
        "baz": 1
      },
      "object.foo.bar.baz": 1
    };
    expect(resBody).to.be.eql(expectedOutput);
  })
}
