asdlkif
This commit is contained in:
118
test_messaging.php
Normal file
118
test_messaging.php
Normal file
@@ -0,0 +1,118 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test Messaging Endpoints</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Test Messaging Endpoints</h1>
|
||||
|
||||
<h2>Test 1: Get Global Messages</h2>
|
||||
<button onclick="testGetGlobalMessages()">Test Get Global Messages</button>
|
||||
<div id="result1"></div>
|
||||
|
||||
<h2>Test 2: Get Conversation Messages</h2>
|
||||
<button onclick="testGetConversationMessages()">Test Get Conversation Messages</button>
|
||||
<div id="result2"></div>
|
||||
|
||||
<h2>Test 3: Send Global Message</h2>
|
||||
<button onclick="testSendGlobalMessage()">Test Send Global Message</button>
|
||||
<div id="result3"></div>
|
||||
|
||||
<h2>Test 4: Send Conversation Message</h2>
|
||||
<button onclick="testSendConversationMessage()">Test Send Conversation Message</button>
|
||||
<div id="result4"></div>
|
||||
|
||||
<script>
|
||||
async function testGetGlobalMessages() {
|
||||
const resultDiv = document.getElementById('result1');
|
||||
resultDiv.innerHTML = '<p>Testing...</p>';
|
||||
|
||||
try {
|
||||
const response = await fetch('<?= Config::get('URL') ?>message/getGlobalMessages');
|
||||
const text = await response.text();
|
||||
|
||||
resultDiv.innerHTML = `
|
||||
<p><strong>Status:</strong> ${response.status}</p>
|
||||
<p><strong>Headers:</strong> ${response.headers.get('content-type')}</p>
|
||||
<p><strong>Response:</strong></p>
|
||||
<pre style="background: #f0f0f0; padding: 10px; overflow-x: auto;">${text}</pre>
|
||||
`;
|
||||
} catch (error) {
|
||||
resultDiv.innerHTML = `<p style="color: red;">Error: ${error.message}</p>`;
|
||||
}
|
||||
}
|
||||
|
||||
async function testGetConversationMessages() {
|
||||
const resultDiv = document.getElementById('result2');
|
||||
resultDiv.innerHTML = '<p>Testing...</p>';
|
||||
|
||||
try {
|
||||
// Try to get user ID from conversation (first user)
|
||||
const response = await fetch('<?= Config::get('URL') ?>message/getConversationMessages/1');
|
||||
const text = await response.text();
|
||||
|
||||
resultDiv.innerHTML = `
|
||||
<p><strong>Status:</strong> ${response.status}</p>
|
||||
<p><strong>Headers:</strong> ${response.headers.get('content-type')}</p>
|
||||
<p><strong>Response:</strong></p>
|
||||
<pre style="background: #f0f0f0; padding: 10px; overflow-x: auto;">${text}</pre>
|
||||
`;
|
||||
} catch (error) {
|
||||
resultDiv.innerHTML = `<p style="color: red;">Error: ${error.message}</p>`;
|
||||
}
|
||||
}
|
||||
|
||||
async function testSendGlobalMessage() {
|
||||
const resultDiv = document.getElementById('result3');
|
||||
resultDiv.innerHTML = '<p>Testing...</p>';
|
||||
|
||||
try {
|
||||
const response = await fetch('<?= Config::get('URL') ?>message/sendToGlobal', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
},
|
||||
body: 'message=Test message from test script'
|
||||
});
|
||||
const text = await response.text();
|
||||
|
||||
resultDiv.innerHTML = `
|
||||
<p><strong>Status:</strong> ${response.status}</p>
|
||||
<p><strong>Headers:</strong> ${response.headers.get('content-type')}</p>
|
||||
<p><strong>Response:</strong></p>
|
||||
<pre style="background: #f0f0f0; padding: 10px; overflow-x: auto;">${text}</pre>
|
||||
`;
|
||||
} catch (error) {
|
||||
resultDiv.innerHTML = `<p style="color: red;">Error: ${error.message}</p>`;
|
||||
}
|
||||
}
|
||||
|
||||
async function testSendConversationMessage() {
|
||||
const resultDiv = document.getElementById('result4');
|
||||
resultDiv.innerHTML = '<p>Testing...</p>';
|
||||
|
||||
try {
|
||||
const response = await fetch('<?= Config::get('URL') ?>message/reply', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
},
|
||||
body: 'receiver_id=1&message=Test message from test script'
|
||||
});
|
||||
const text = await response.text();
|
||||
|
||||
resultDiv.innerHTML = `
|
||||
<p><strong>Status:</strong> ${response.status}</p>
|
||||
<p><strong>Headers:</strong> ${response.headers.get('content-type')}</p>
|
||||
<p><strong>Response:</strong></p>
|
||||
<pre style="background: #f0f0f0; padding: 10px; overflow-x: auto;">${text}</pre>
|
||||
`;
|
||||
} catch (error) {
|
||||
resultDiv.innerHTML = `<p style="color: red;">Error: ${error.message}</p>`;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user