In the Pre-request Script, we set the environment variable userId and the global variable authToken using pm.environment.set() and pm.globals.set(). This ensures these variables are available before the request runs.
In the Tests Script, we retrieve these variables using pm.environment.get() and pm.globals.get(). Then, we use pm.test() with clear messages to assert that the variables have the expected values. This confirms the variables were set correctly.
This approach keeps scripts simple and easy to understand, which is important for maintaining tests over time.