test.js 804 B

123456789101112131415161718192021222324252627282930313233343536
  1. // 测试注册接口
  2. console.log("测试函数:邀请人不存在的情况")
  3. testRegister({
  4. mobile: '1234567890',
  5. code: '123456',
  6. inviteId: '123'
  7. });
  8. console.log("测试函数:邀请人存在的情况")
  9. testRegister({
  10. mobile: '1234567890',
  11. code: '123456',
  12. inviteId: '1'
  13. });
  14. async function testRegister(jsonBody) {
  15. const requestBody = jsonBody;
  16. try {
  17. const response = await fetch('http://localhost:3000/register', {
  18. method: 'POST',
  19. headers: {
  20. 'Content-Type': 'application/json',
  21. },
  22. body: JSON.stringify(requestBody),
  23. });
  24. const data = await response.json();
  25. console.log(data);
  26. } catch (error) {
  27. console.error('测试注册接口失败:', error);
  28. }
  29. }