-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsimple-test.js
More file actions
194 lines (169 loc) · 6.11 KB
/
simple-test.js
File metadata and controls
194 lines (169 loc) · 6.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
const http = require('http');
function makeRequest(options, postData = null) {
return new Promise((resolve, reject) => {
const req = http.request(options, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
try {
const parsed = JSON.parse(data);
resolve({ statusCode: res.statusCode, data: parsed });
} catch (e) {
resolve({ statusCode: res.statusCode, data: data });
}
});
});
req.on('error', (err) => {
reject(err);
});
if (postData) {
req.write(JSON.stringify(postData));
}
req.end();
});
}
async function testPermanentDeleteFix() {
console.log('🧪 Testing Permanent Delete Fix...\n');
try {
// Test basic connection
console.log('🔗 Testing basic connection...');
const inboxTest = await makeRequest({
hostname: '127.0.0.1',
port: 5050,
path: '/api/emails?userId=user-1',
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
});
console.log(`✅ Connection successful. Status: ${inboxTest.statusCode}`);
console.log(`📧 Inbox contains ${inboxTest.data.emails?.length || 0} emails`);
// Create test email
console.log('\n📧 Creating test email...');
const emailResponse = await makeRequest({
hostname: '127.0.0.1',
port: 5050,
path: '/api/emails',
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
}, {
senderId: 'user-1',
recipientIds: ['user-2'],
subject: 'Test Email for Permanent Delete Fix',
body: 'This email will be used to test the permanent delete fix.',
priority: 'normal',
cc: [],
bcc: []
});
console.log('Email response:', JSON.stringify(emailResponse, null, 2));
const emailId = emailResponse.data.id;
console.log(`✅ Email created with ID: ${emailId}`);
// Verify email appears in recipient's inbox
console.log('\n📥 Checking recipient inbox...');
const inboxBeforeDelete = await makeRequest({
hostname: '127.0.0.1',
port: 5050,
path: '/api/emails?userId=user-2',
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
});
const emailInInbox = inboxBeforeDelete.data.emails?.some(email => email.id === emailId) || false;
console.log(`✅ Email found in recipient inbox: ${emailInInbox}`);
// Delete email to trash (as recipient)
console.log('\n🗑️ Moving email to trash...');
const deleteResponse = await makeRequest({
hostname: '127.0.0.1',
port: 5050,
path: `/api/emails/${emailId}`,
method: 'DELETE',
headers: {
'Content-Type': 'application/json'
}
}, {
userId: 'user-2'
});
console.log(`✅ Email moved to trash. Status: ${deleteResponse.statusCode}`);
// Verify email appears in recipient's trash
console.log('\n🗑️ Checking recipient trash...');
const trashResponse = await makeRequest({
hostname: '127.0.0.1',
port: 5050,
path: '/api/trash?userId=user-2',
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
});
const emailInTrash = trashResponse.data.emails?.some(email => email.id === emailId) || false;
console.log(`✅ Email found in recipient trash: ${emailInTrash}`);
// Permanently delete email from trash
console.log('\n🗑️ Permanently deleting email from trash...');
const permanentDeleteResponse = await makeRequest({
hostname: '127.0.0.1',
port: 5050,
path: `/api/trash/${emailId}/permanent`,
method: 'DELETE',
headers: {
'Content-Type': 'application/json'
}
}, {
userId: 'user-2'
});
console.log(`✅ Email permanently deleted from trash. Status: ${permanentDeleteResponse.statusCode}`);
// Verify email does NOT appear in recipient's inbox after permanent delete
console.log('\n📥 Checking recipient inbox after permanent delete...');
const inboxAfterDelete = await makeRequest({
hostname: '127.0.0.1',
port: 5050,
path: '/api/emails?userId=user-2',
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
});
const emailStillInInbox = inboxAfterDelete.data.emails?.some(email => email.id === emailId) || false;
console.log(`✅ Email still in recipient inbox: ${emailStillInInbox} (should be false)`);
// Verify email does NOT appear in recipient's trash after permanent delete
console.log('\n🗑️ Checking recipient trash after permanent delete...');
const trashAfterDelete = await makeRequest({
hostname: '127.0.0.1',
port: 5050,
path: '/api/trash?userId=user-2',
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
});
const emailStillInTrash = trashAfterDelete.data.emails?.some(email => email.id === emailId) || false;
console.log(`✅ Email still in recipient trash: ${emailStillInTrash} (should be false)`);
// Verify sender can still see the email in sent items
console.log('\n📤 Checking sender sent items...');
const sentResponse = await makeRequest({
hostname: '127.0.0.1',
port: 5050,
path: '/api/emails/sent?userId=user-1',
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
});
const emailInSent = sentResponse.data.emails?.some(email => email.id === emailId) || false;
console.log(`✅ Email found in sender sent items: ${emailInSent}`);
console.log('\n🎉 All tests passed! The permanent delete fix is working correctly.');
console.log('\n📋 Summary:');
console.log('- Emails permanently deleted from trash do not reappear in inbox');
console.log('- Emails emptied from trash do not reappear in inbox');
console.log('- Sender can still see emails in sent items after recipient permanently deletes them');
} catch (error) {
console.error('❌ Test failed:', error.message);
console.error('Full error:', error);
}
}
// Run the test
testPermanentDeleteFix();