You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
2.2 KiB

  1. var request = require('request');
  2. var url = "http://127.0.0.1:3000/api";
  3. var users = [{
  4. username: "u1",
  5. password: "u1",
  6. email: "u1"
  7. },
  8. {
  9. username: "u2",
  10. password: "u2",
  11. email: "u2"
  12. },
  13. {
  14. username: "u3",
  15. password: "u3",
  16. email: "u3"
  17. }
  18. ];
  19. //signup
  20. function signup(user) {
  21. var data = {
  22. username: user.username,
  23. password: user.password,
  24. email: user.email
  25. };
  26. request({
  27. url: url + "/signup",
  28. method: "POST",
  29. headers: {
  30. 'content-type': 'application/json'
  31. },
  32. body: data,
  33. json: true
  34. }, function(err, httpResponse, body) {
  35. if (err) {
  36. console.log(err);
  37. } else {
  38. //console.log(body);
  39. login(user);
  40. }
  41. });
  42. }
  43. //login
  44. function login(user) {
  45. var data = {
  46. username: user.username,
  47. password: user.email
  48. };
  49. request({
  50. url: url + "/login",
  51. method: "POST",
  52. headers: {
  53. 'content-type': 'application/json'
  54. },
  55. body: data,
  56. json: true
  57. }, function(err, httpResponse, body) {
  58. if (err) {
  59. console.log(err);
  60. } else {
  61. console.log(body.token);
  62. user.token = JSON.parse(JSON.stringify(body.token));
  63. console.log(user.username);
  64. addTravel(user);
  65. }
  66. });
  67. }
  68. function addTravel(user) {
  69. var data = {
  70. title: "travel",
  71. description: "description4",
  72. from: "placeA",
  73. to: "placeB",
  74. date: "2017-10-29T22:58:59.000Z",
  75. seats: 3,
  76. package: true,
  77. collectivized: true,
  78. type: "offer"
  79. };
  80. request({
  81. url: url + "/login",
  82. method: "POST",
  83. headers: {
  84. 'content-type': 'application/json',
  85. 'x-access-token': user.token
  86. },
  87. body: data,
  88. json: true
  89. }, function(err, httpResponse, body) {
  90. if (err) {
  91. console.log(err);
  92. } else {
  93. console.log(body);
  94. }
  95. });
  96. }
  97. for (var i = 0; i < users.length; i++) {
  98. console.log(i);
  99. console.log(users[i].username);
  100. setTimeout(function() {
  101. signup(users[i]);
  102. }, 2000);
  103. }