-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.js
More file actions
208 lines (185 loc) · 6.72 KB
/
test.js
File metadata and controls
208 lines (185 loc) · 6.72 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
const {
getAyah, getSurah, searchText, getRandomAyah, getSajdahAyat, getQuranData,
// Phase 1 Enhanced functions (v1.1.0)
getAyahRange, getJuz, getHizb, searchBySurahName, getSurahStatistics
} = require('./dist/index.js');
console.log('🧪 Testing @muslims-community/quran package\n');
// Test getAyah
console.log('📖 Testing getAyah(1, 1):');
try {
const ayah = getAyah(1, 1);
console.log(`✅ Ayah text: ${ayah.text}`);
console.log(`✅ Surah: ${ayah.surah.name} (${ayah.surah.englishName})`);
console.log(`✅ Source: ${ayah.source}\n`);
} catch (error) {
console.log(`❌ Error: ${error.message}\n`);
}
// Test getSurah
console.log('📚 Testing getSurah(18):');
try {
const surah = getSurah(18);
console.log(`✅ Surah: ${surah.name} (${surah.englishName})`);
console.log(`✅ Number of Ayat: ${surah.numberOfAyahs}`);
console.log(`✅ Revelation Type: ${surah.revelationType}`);
console.log(`✅ First Ayah: ${surah.ayat[0].text}\n`);
} catch (error) {
console.log(`❌ Error: ${error.message}\n`);
}
// Test searchText
console.log('🔍 Testing searchText("بِسمِ"):');
try {
const results = searchText('بِسمِ');
console.log(`✅ Found ${results.totalResults} results`);
if (results.results.length > 0) {
console.log(`✅ First result: ${results.results[0].text}`);
console.log(`✅ From: ${results.results[0].surah.englishName}`);
} else {
console.log(`✅ No results found for the search term`);
}
console.log('');
} catch (error) {
console.log(`❌ Error: ${error.message}\n`);
}
// Test getRandomAyah
console.log('🎲 Testing getRandomAyah():');
try {
const randomAyah = getRandomAyah();
console.log(`✅ Random Ayah: ${randomAyah.text}`);
console.log(`✅ From: ${randomAyah.surah.englishName} (${randomAyah.surah.name}), Ayah ${randomAyah.id}\n`);
} catch (error) {
console.log(`❌ Error: ${error.message}\n`);
}
// Test getSajdahAyat
console.log('🕌 Testing getSajdahAyat():');
try {
const sajdahResult = getSajdahAyat();
console.log(`✅ Total Sajdah Ayat: ${sajdahResult.totalSajdahAyat}`);
if (sajdahResult.sajdahAyat.length > 0) {
const firstSajdah = sajdahResult.sajdahAyat[0];
console.log(`✅ First Sajdah: ${firstSajdah.surah.englishName} ${firstSajdah.id}`);
console.log(`✅ Text: ${firstSajdah.text}\n`);
}
} catch (error) {
console.log(`❌ Error: ${error.message}\n`);
}
// Test getQuranData
console.log('📊 Testing getQuranData():');
try {
const quranData = getQuranData();
console.log(`✅ Total Surahs: ${quranData.surahs.length}`);
console.log(`✅ Version: ${quranData.version}`);
console.log(`✅ License: ${quranData.license}`);
// Calculate total ayat
const totalAyat = quranData.surahs.reduce((total, surah) => total + surah.numberOfAyahs, 0);
console.log(`✅ Total Ayat: ${totalAyat}\n`);
} catch (error) {
console.log(`❌ Error: ${error.message}\n`);
}
// Test error handling
console.log('⚠️ Testing error handling:');
try {
getAyah(999, 1); // Invalid surah
} catch (error) {
console.log(`✅ Correctly caught error: ${error.message}`);
}
try {
getAyah(1, 999); // Invalid ayah
} catch (error) {
console.log(`✅ Correctly caught error: ${error.message}`);
}
try {
searchText(''); // Empty search
} catch (error) {
console.log(`✅ Correctly caught error: ${error.message}`);
}
// Test Phase 1 Enhanced Functions (v1.1.0)
console.log('\n🚀 Testing Phase 1 Enhanced Functions (v1.1.0):');
// Test getAyahRange
console.log('\n📖 Testing getAyahRange(2, 1, 3):');
try {
const ayahRange = getAyahRange(2, 1, 3);
console.log(`✅ Range: ${ayahRange.range.start}-${ayahRange.range.end} (${ayahRange.range.count} ayat)`);
console.log(`✅ First ayah: ${ayahRange.ayat[0].text.substring(0, 30)}...`);
console.log(`✅ Surah: ${ayahRange.surah.englishName}`);
} catch (error) {
console.log(`❌ Error: ${error.message}`);
}
// Test getJuz
console.log('\n📚 Testing getJuz(1):');
try {
const juz = getJuz(1);
console.log(`✅ Juz ${juz.juz}: ${juz.totalAyat} ayat`);
console.log(`✅ First ayah: ${juz.ayat[0].text}`);
console.log(`✅ From: ${juz.ayat[0].surah.englishName}`);
} catch (error) {
console.log(`❌ Error: ${error.message}`);
}
// Test getHizb
console.log('\n📑 Testing getHizb(1):');
try {
const hizb = getHizb(1);
console.log(`✅ Hizb ${hizb.hizb} (Juz ${hizb.juz}): ${hizb.totalAyat} ayat`);
if (hizb.ayat.length > 0) {
console.log(`✅ First ayah: ${hizb.ayat[0].text.substring(0, 30)}...`);
}
} catch (error) {
console.log(`❌ Error: ${error.message}`);
}
// Test searchBySurahName
console.log('\n🔍 Testing searchBySurahName("Fatiha"):');
try {
const surahSearch = searchBySurahName('Fatiha');
console.log(`✅ Found ${surahSearch.totalResults} results`);
if (surahSearch.results.length > 0) {
console.log(`✅ Result: ${surahSearch.results[0].englishName} (${surahSearch.results[0].name})`);
}
} catch (error) {
console.log(`❌ Error: ${error.message}`);
}
// Test searchBySurahName with Arabic
console.log('\n🔍 Testing searchBySurahName("البقرة"):');
try {
const arabicSearch = searchBySurahName('البقرة');
console.log(`✅ Found ${arabicSearch.totalResults} results`);
if (arabicSearch.results.length > 0) {
console.log(`✅ Result: ${arabicSearch.results[0].englishName} (${arabicSearch.results[0].name})`);
}
} catch (error) {
console.log(`❌ Error: ${error.message}`);
}
// Test getSurahStatistics
console.log('\n📊 Testing getSurahStatistics():');
try {
const stats = getSurahStatistics();
console.log(`✅ Total Surahs: ${stats.totalSurahs}`);
console.log(`✅ Total Ayat: ${stats.totalAyat}`);
console.log(`✅ Meccan: ${stats.meccanSurahs}, Medinan: ${stats.medinanSurahs}`);
console.log(`✅ Average Ayat per Surah: ${stats.averageAyatPerSurah}`);
console.log(`✅ Longest: ${stats.longestSurah.englishName} (${stats.longestSurah.numberOfAyahs} ayat)`);
console.log(`✅ Shortest: ${stats.shortestSurah.englishName} (${stats.shortestSurah.numberOfAyahs} ayat)`);
} catch (error) {
console.log(`❌ Error: ${error.message}`);
}
// Test error handling for new functions
console.log('\n⚠️ Testing error handling for enhanced functions:');
try {
getAyahRange(999, 1, 1); // Invalid surah
} catch (error) {
console.log(`✅ Correctly caught error: ${error.message}`);
}
try {
getJuz(31); // Invalid juz
} catch (error) {
console.log(`✅ Correctly caught error: ${error.message}`);
}
try {
getHizb(61); // Invalid hizb
} catch (error) {
console.log(`✅ Correctly caught error: ${error.message}`);
}
try {
searchBySurahName(''); // Empty search
} catch (error) {
console.log(`✅ Correctly caught error: ${error.message}`);
}
console.log('\n🎉 All tests completed successfully! Phase 1 Enhanced Functions (v1.1.0) working perfectly!');