-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-function.js
More file actions
74 lines (62 loc) · 1.88 KB
/
test-function.js
File metadata and controls
74 lines (62 loc) · 1.88 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
#!/usr/bin/env node
/**
* Test script to call the testDegradeCreatureStats function with Firebase Auth
*
* Usage:
* 1. Log in to your web app to get a token
* 2. Copy the token from browser dev tools (Application -> Local Storage -> firebase:authUser)
* 3. Run: node test-function.js YOUR_TOKEN_HERE
*
* Alternative: Use this script which will get the token automatically
*/
const https = require('https');
const FUNCTION_URL =
'https://us-central1-habii-235d1.cloudfunctions.net/testDegradeCreatureStats';
async function callTestFunction(token) {
return new Promise((resolve, reject) => {
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${token}`,
},
};
const req = https.request(FUNCTION_URL, options, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
console.log(`Status: ${res.statusCode}`);
console.log(`Response:`, JSON.parse(data));
resolve(data);
});
});
req.on('error', (error) => {
console.error('Error:', error);
reject(error);
});
req.end();
});
}
// Get token from command line argument
const token = process.argv[2];
if (!token) {
console.log('Usage: node test-function.js YOUR_FIREBASE_TOKEN');
console.log('');
console.log('To get your token:');
console.log('1. Log in to your web app');
console.log('2. Open browser dev tools');
console.log('3. Go to Application -> Local Storage');
console.log('4. Find the firebase:authUser entry');
console.log('5. Copy the "stsTokenManager.accessToken" value');
process.exit(1);
}
callTestFunction(token)
.then(() => {
console.log('Function call completed successfully!');
})
.catch((error) => {
console.error('Function call failed:', error);
process.exit(1);
});