I am testing this public API using postman.
When I send a request to this endpoint:
POST: https://reqres.in/api/users
with the following request body:
{
"name": "Rose Thompson",
"job": "Senior Markets Agent"
}
I get this as a response:
{
"name": "Rose Thompson",
"job": "Senior Markets Agent",
"id": "818",
"createdAt": "2022-05-09T09:30:43.839Z"
}
Then I am writing some custom API tests to make sure that the actual and expected responses are the same.
Here is my test code in Postman:
pm.test("Successful POST request", function () {
pm.expect(pm.response.code).to.be.oneOf([201, 202]);
});
const response = pm.response.json();
pm.test("Should Have Right Name", () => {
const actual = response.name;
const expected = "Rose Thompson";
pm.expect(actual).to.eq(expected);
})
pm.test("Should Have Right Job", () => {
const actual = response.job;
const expected = "Senior Markets Agent";
pm.expect(actual).to.eq(expected);
})
Now I want to write a test for the createdAt
field from the response body. I know how to get the actual value from the response itself (I'll do it like this response.createdAt
), however, I am having difficulties getting the expected value of the createdAt
field.
Can you please tell me how can I get the expected value of the createdAt
field?