Guest User

Untitled

a guest
Sep 18th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. function UTILS() {
  2.  
  3. // Returns a random number
  4. this.rand = length => Math.floor(Math.random() * length);
  5.  
  6. // Returns a random string
  7. this.text = (maxWords=1, maxLength=8) => {
  8. const chars = [
  9. 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
  10. 'abcdefghijklmnopqrstuvwxyz',
  11. '0123456789',
  12. ].join('');
  13. const word = () => [...Array(this.rand(maxLength))]
  14. .map(() => chars.charAt(this.rand(chars.length)))
  15. .join('');
  16. return [...Array(this.rand(maxWords))]
  17. .map(word)
  18. .join(' ');
  19. };
  20.  
  21. // Accordint to a (normal) server response, set an environment variable
  22. this.setEnvironmentData = (body, name, prop='id') => {
  23. const { data } = JSON.parse(body);
  24. const title = `setEnvironmentData: [${name}]`;
  25. if (!data || !data.length) return console.log(`${title} NO DATA`);
  26. const item = data[this.rand(data.length)];
  27. console.log(`${title} ${item[prop]}`);
  28. pm.environment.set(name, item[prop]);
  29. return item;
  30. }
  31. }
Add Comment
Please, Sign In to add comment