-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-github-function.js
More file actions
56 lines (48 loc) · 1.78 KB
/
test-github-function.js
File metadata and controls
56 lines (48 loc) · 1.78 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
/**
* Test script for the fetch-github-stars function
*
* This script allows you to test the GitHub stars fetch function locally
* without deploying to Netlify.
*
* Run with: node test-github-function.js
*/
// Import required modules
const { handler } = require('./netlify_functions/fetch-github-stars');
const { getRepoMappings, updateRepoMappings } = require('./netlify_functions/storage');
const { DEFAULT_REPO_MAPPINGS } = require('./netlify_functions/config');
// Create mock event object (similar to what Netlify would provide)
const mockEvent = {
body: null,
headers: {},
httpMethod: 'GET',
isBase64Encoded: false,
path: '/',
queryStringParameters: {},
};
// Execute the function
async function runTest() {
console.log('Testing GitHub stars fetch function...');
try {
// First, ensure we have repository mappings
const mappings = await getRepoMappings();
if (Object.keys(mappings).length === 0) {
console.log('No repository mappings found. Initializing with default mappings...');
await updateRepoMappings(DEFAULT_REPO_MAPPINGS);
console.log('Repository mappings initialized with:', Object.keys(DEFAULT_REPO_MAPPINGS).length, 'entries');
} else {
console.log('Found', Object.keys(mappings).length, 'repository mappings');
}
// Now execute the GitHub stars fetch function
console.log('\nFetching GitHub repository data...');
const response = await handler(mockEvent);
console.log('Function executed successfully!');
console.log('Status code:', response.statusCode);
// Parse the response body
const body = JSON.parse(response.body);
console.log('Response:', JSON.stringify(body, null, 2));
} catch (error) {
console.error('Error executing function:', error);
}
}
// Run the test
runTest();