test-auth.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. // 测试用户认证流程
  2. async function testAuthFlow() {
  3. const testUsername = `testuser_${Math.floor(Math.random() * 10000)}`;
  4. const testPassword = 'testpassword123';
  5. console.log(`测试用户: ${testUsername}`);
  6. try {
  7. // 尝试登录(预期失败)
  8. console.log('尝试登录未注册用户...');
  9. await login(testUsername, testPassword);
  10. } catch (error) {
  11. console.log('预期中的登录失败:', error.message);
  12. }
  13. try {
  14. // 注册新用户
  15. console.log('注册新用户...');
  16. await signUp(testUsername, testPassword);
  17. // 再次尝试登录(预期成功)
  18. console.log('尝试登录已注册用户...');
  19. await login(testUsername, testPassword);
  20. // 尝试重复注册(预期失败)
  21. console.log('尝试重复注册...');
  22. await signUp(testUsername, testPassword);
  23. } catch (error) {
  24. console.log('捕获到预期错误:', error.message);
  25. }
  26. }
  27. // 运行测试
  28. testAuthFlow();