test: add vitest and openai test

This commit is contained in:
moonrailgun 2024-01-13 00:13:51 +08:00
parent 3d3f07c380
commit bf887ae8fc
4 changed files with 753 additions and 3 deletions

View File

@ -6,6 +6,7 @@
"dev": "nodemon",
"start": "cross-env NODE_ENV=production node ./dist/src/server/main.js",
"start:docker": "pnpm db:migrate:apply && pnpm db:generate && pnpm start",
"test": "vitest",
"build": "pnpm build:tracker && pnpm build:client && pnpm build:server && pnpm build:geo",
"build:client": "vite build",
"build:server": "tsc -p tsconfig.server.json",
@ -130,6 +131,7 @@
"tailwindcss": "^3.3.3",
"tar": "^6.1.15",
"typescript": "^5.2.2",
"vite": "^4.4.9"
"vite": "^4.4.9",
"vitest": "^1.1.3"
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,12 @@
import { describe, test } from 'vitest';
import { getBillingCreditGrants } from '../openai';
describe.runIf(!!process.env.OPENAI_SESS_KEY)('openai', () => {
test('getBillingCreditGrants should be ok', async () => {
const res = await getBillingCreditGrants(
String(process.env.OPENAI_SESS_KEY)
);
console.log(res);
});
});

View File

@ -53,7 +53,7 @@ export const openai: MonitorProvider<{
},
};
async function getBillingCreditGrants(sessionKey: string) {
export async function getBillingCreditGrants(sessionKey: string) {
const { data } = await axios.get(
'https://api.openai.com/dashboard/billing/credit_grants',
{