Skip to content

Commit

Permalink
implement get account balance
Browse files Browse the repository at this point in the history
  • Loading branch information
seveibar committed Oct 7, 2024
1 parent 449ebd7 commit 29c6a96
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
22 changes: 22 additions & 0 deletions fake-snippets-api/routes/api/accounts/get_account_balance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { withRouteSpec } from "fake-snippets-api/lib/middleware/with-winter-spec"
import { z } from "zod"

export default withRouteSpec({
methods: ["GET"],
auth: "session",
jsonResponse: z.object({
account_balance: z.object({
monthly_ai_budget_used_usd: z.number(),
}),
}),
})(async (req, ctx) => {
// For this example, we'll return a mock balance
// In a real implementation, you would fetch this from a database or external service
const mockBalance = {
monthly_ai_budget_used_usd: 2.50,
}

return ctx.json({
account_balance: mockBalance,
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { getTestServer } from "fake-snippets-api/tests/fixtures/get-test-server"
import { test, expect } from "bun:test"

test("get account balance", async () => {
const { axios } = await getTestServer()

const response = await axios.get("/api/accounts/get_account_balance", {
headers: {
Authorization: "Bearer 1234",
},
})

expect(response.status).toBe(200)
expect(response.data.account_balance).toBeDefined()
expect(typeof response.data.account_balance.monthly_ai_budget_used_usd).toBe("number")
})

0 comments on commit 29c6a96

Please sign in to comment.