12345678910111213141516171819202122232425262728293031323334 |
- // 测试用户认证流程
- async function testAuthFlow() {
- const testUsername = `testuser_${Math.floor(Math.random() * 10000)}`;
- const testPassword = 'testpassword123';
- console.log(`测试用户: ${testUsername}`);
- try {
- // 尝试登录(预期失败)
- console.log('尝试登录未注册用户...');
- await login(testUsername, testPassword);
- } catch (error) {
- console.log('预期中的登录失败:', error.message);
- }
- try {
- // 注册新用户
- console.log('注册新用户...');
- await signUp(testUsername, testPassword);
- // 再次尝试登录(预期成功)
- console.log('尝试登录已注册用户...');
- await login(testUsername, testPassword);
- // 尝试重复注册(预期失败)
- console.log('尝试重复注册...');
- await signUp(testUsername, testPassword);
- } catch (error) {
- console.log('捕获到预期错误:', error.message);
- }
- }
- // 运行测试
- testAuthFlow();
|