I am calling an endpoint using before and after timestamp parameters like this:
{{baseUrl}}/activity?before=2024-09-04T13:55:02.325Z&after=2024-09-03T12:34:47.830Z
Response body would be served as an array like this:
[
{
"eventType": "account-created",
"invokedAt": "2024-09-04T13:54:52.153Z"
},
{
"eventType": "account-preference-updated",
"invokedAt": "2024-09-04T13:54:56.231Z",
"changes": [
{
"property": "values",
"prior": "",
"new": "newValue"
}
]
},
{
"eventType": "account-preference-updated",
"invokedAt": "2024-09-04T13:58:34.342Z",
"changes": [
{
"property": "values",
"prior": "newValue",
"new": "newerValue"
}
]
}
]
How can I write a test that will evaluate whether the invokedAt
timestamps are between the specified params? I will be using variables for the params to make it easy to comapre within the test.
The closest solution I have found was never fully answered, so I am not sure whether there could be an easily utilized Postman feature for it.
This is what I tried to build from that and some other various answers:
//Validate that each invokedAt timestamp is between the endpoint param timestamps
jsonData.forEach((obj, i) => {
let invokedTime = obj.invokedAt;
console.log(invokedTime);
pm.test(`Object ${i} invoked time [${invokedTime}] within range `, () => {
pm.expect((invokedTime).isBetween("2024-09-03T12:34:47.830Z", "2024-09-04T13:55:02.325Z")).to.be.true;
})
});
It fails with error:
Object 1 invokedTime[2024-09-04T13:54:56.231Z] between | TypeError: invokedTime.isBetween is not a function