Hi Chris,
There are various ways in which this can be achieved, some of which have been discussed in other topics (Where is the best place to set global functions for tests?, Global functions via Collection level folder?) and some others which have been crowdsourced on StackOverflow over the years (How to write Global functions in Postman).
Following the top-rated eval
example on StackOverflow, I was able to demonstrate this working with one of your functions; firstly, by utilising an arbitrary Pre-Request Script tab to submit my group of functions into a global variable:
Set functions in a Global variable
pm.globals.set('loadUtils', function loadUtils() {
let utils = {};
utils.validateResponseCode = function validateResponseCode(expectedResponseCode) {
pm.test("Response status code is " + expectedResponseCode, function () {
pm.expect(pm.response.code, 'Response Code').to.equal(expectedResponseCode);
});
}
//...repeat for the rest of your functions
return utils;
} + '; loadUtils();');
tests['Utils initialized'] = true;
…and then you can reference these in any Tests tab anywhere within your workspace:
const utils = eval(globals.loadUtils);
utils.validateResponseCode(200);
Things get a bit more complicated if you want to start setting other variables from within your common functions, but all of the examples you gave appear to be doing straightforward assertions, so hopefully this (and the linked resources) can get you what you need.