File size: 2,148 Bytes
3eedfc9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { fetchFromAppwrite, getMemberData, getCandidateData, postData, getStats } from './services/appwriteDataFetcher.js';

async function testFetchFromAppwrite() {
  console.log('\n=== Testing fetchFromAppwrite ===');
  try {
    const payload = {
      action: 'testAction',
      key: 'value'
    };
    const result = await fetchFromAppwrite(payload, 'test-request');
    console.log('Result:', JSON.stringify(result, null, 2));
  } catch (error) {
    console.error('Error:', error.message);
  }
}

async function testGetMemberData() {
  console.log('\n=== Testing getMemberData ===');
  try {
    const result = await getMemberData('Narendra Modi', 'MP', 'Varanasi', 'Uttar Pradesh');
    console.log('Result:', JSON.stringify(result, null, 2));
  } catch (error) {
    console.error('Error:', error.message);
  }
}

async function testGetCandidateData() {
  console.log('\n=== Testing getCandidateData ===');
  try {
    const result = await getCandidateData('Candidate Name', 'Constituency', 'Party');
    console.log('Result:', JSON.stringify(result, null, 2));
  } catch (error) {
    console.error('Error:', error.message);
  }
}

async function testPostData() {
  console.log('\n=== Testing postData ===');
  try {
    const data = { action: 'customAction', data: 'test' };
    const result = await postData(data, 'post-test');
    console.log('Result:', JSON.stringify(result, null, 2));
  } catch (error) {
    console.error('Error:', error.message);
  }
}

async function testGetStats() {
  console.log('\n=== Testing getStats ===');
  try {
    const stats = getStats();
    console.log('Stats:', JSON.stringify(stats, null, 2));
  } catch (error) {
    console.error('Error:', error.message);
  }
}

async function runTests() {
  console.log('Starting AppwriteDataFetcher Tests...\n');

  await testGetStats();
  await testFetchFromAppwrite();
  await testGetMemberData();
  await testGetCandidateData();
  await testPostData();

  console.log('\nTests completed.');
}

// Run tests
runTests().catch(console.error);

export { runTests, testFetchFromAppwrite, testGetMemberData, testGetCandidateData, testPostData, testGetStats };