This commit is contained in:
53
test-request.js
Normal file
53
test-request.js
Normal file
@@ -0,0 +1,53 @@
|
||||
require('dotenv').config();
|
||||
const axios = require('axios');
|
||||
|
||||
const BASE_URL = 'http://localhost:3000/api/command';
|
||||
const API_KEY = process.env.API_KEY;
|
||||
|
||||
async function request(command, parameters) {
|
||||
const { data } = await axios.post(BASE_URL, {
|
||||
command,
|
||||
parameters,
|
||||
apiKey: API_KEY
|
||||
});
|
||||
return data;
|
||||
}
|
||||
|
||||
async function run() {
|
||||
const ping = await request('ping');
|
||||
console.log("PING:", ping);
|
||||
|
||||
const add = await request('diary', {
|
||||
instruction: 'add -desc "Test expense" -cost 12.50 -cat food'
|
||||
});
|
||||
console.log("Add:", add);
|
||||
const expenseId = add.data?.id;
|
||||
|
||||
const update = await request('diary', {
|
||||
instruction: `update ${expenseId} -cost 15.00`
|
||||
});
|
||||
console.log("Update:", update);
|
||||
|
||||
const del = await request('diary', {
|
||||
instruction: `delete ${expenseId}`
|
||||
});
|
||||
console.log("Delete:", del);
|
||||
|
||||
const daylog = await request('diary', {
|
||||
instruction: 'daylog -stars 4 -text "Test day log entry"'
|
||||
});
|
||||
console.log("Day log:", daylog);
|
||||
|
||||
await request('diary', {
|
||||
instruction: 'add -desc "Test expense 2" -cost 14.99 -cat travel'
|
||||
});
|
||||
|
||||
const report = await request('diary', {
|
||||
instruction: 'report -from "2025-01-01" -export true'
|
||||
});
|
||||
console.log("Report:", report);
|
||||
}
|
||||
|
||||
run().catch(err => {
|
||||
console.error('Error:', err.response?.data || err.message);
|
||||
});
|
||||
Reference in New Issue
Block a user