初始化
This commit is contained in:
53
test_api.js
Normal file
53
test_api.js
Normal file
@@ -0,0 +1,53 @@
|
||||
const axios = require('axios');
|
||||
|
||||
const API_BASE_URL = 'http://localhost:5003/api/v1';
|
||||
|
||||
async function testAPI() {
|
||||
try {
|
||||
// 1. 注册用户
|
||||
console.log('1. 注册用户...');
|
||||
const registerResponse = await axios.post(`${API_BASE_URL}/auth/register`, {
|
||||
username: 'testuser',
|
||||
email: 'test@example.com',
|
||||
password: 'password123'
|
||||
});
|
||||
const token = registerResponse.data.data.token;
|
||||
console.log('注册成功,获取到token:', token);
|
||||
|
||||
// 2. 创建邮件
|
||||
console.log('\n2. 创建邮件...');
|
||||
const mailData = {
|
||||
title: '测试邮件',
|
||||
content: '这是一封测试邮件内容',
|
||||
recipientType: 'SELF',
|
||||
sendTime: new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString(), // 明天这个时候
|
||||
triggerType: 'TIME',
|
||||
triggerCondition: {},
|
||||
attachments: [],
|
||||
isEncrypted: false,
|
||||
capsuleStyle: 'default'
|
||||
};
|
||||
|
||||
const createMailResponse = await axios.post(`${API_BASE_URL}/mails/create`, mailData, {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
console.log('创建邮件成功:', createMailResponse.data);
|
||||
|
||||
// 3. 获取邮件列表
|
||||
console.log('\n3. 获取邮件列表...');
|
||||
const mailsResponse = await axios.get(`${API_BASE_URL}/mails?type=SENT&page=1&size=20`, {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`
|
||||
}
|
||||
});
|
||||
console.log('获取邮件列表成功:', mailsResponse.data);
|
||||
|
||||
} catch (error) {
|
||||
console.error('测试失败:', error.response?.data || error.message);
|
||||
}
|
||||
}
|
||||
|
||||
testAPI();
|
||||
Reference in New Issue
Block a user