diff --git a/package.json b/package.json index 4b91dde..eae3dd6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "snapapi", - "version": "0.1.0", + "version": "0.6.0", "description": "URL to Screenshot API — PNG, JPEG, WebP via simple REST API", "main": "dist/index.js", "type": "module", diff --git a/src/docs/__tests__/openapi.test.ts b/src/docs/__tests__/openapi.test.ts new file mode 100644 index 0000000..7a93ace --- /dev/null +++ b/src/docs/__tests__/openapi.test.ts @@ -0,0 +1,19 @@ +import { describe, it, expect } from 'vitest' +import { openapiSpec } from '../openapi.js' + +describe('OpenAPI Spec', () => { + it('should include GET /v1/screenshot endpoint', () => { + expect(openapiSpec.paths['/v1/screenshot']).toBeDefined() + expect(openapiSpec.paths['/v1/screenshot'].get).toBeDefined() + }) + + it('should include GET /v1/usage endpoint', () => { + expect(openapiSpec.paths['/v1/usage']).toBeDefined() + expect(openapiSpec.paths['/v1/usage'].get).toBeDefined() + }) + + it('should NOT include /v1/signup/free endpoint', () => { + const signupPath = openapiSpec.paths['/v1/signup/free'] + expect(signupPath).toBeUndefined() + }) +}) diff --git a/src/routes/__tests__/health.test.ts b/src/routes/__tests__/health.test.ts index 5f1a1b5..e053732 100644 --- a/src/routes/__tests__/health.test.ts +++ b/src/routes/__tests__/health.test.ts @@ -1,7 +1,11 @@ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest' import { Request, Response } from 'express' +import { createRequire } from 'module' import { healthRouter } from '../health.js' +const require = createRequire(import.meta.url) +const pkg = require('../../../package.json') + // Mock dependencies vi.mock('../../services/browser.js', () => ({ getPoolStats: vi.fn() @@ -58,9 +62,10 @@ describe('Health Route', () => { await handler(req, res, vi.fn()) expect(mockGetPoolStats).toHaveBeenCalledOnce() + expect(res.json).toHaveBeenCalledWith({ status: "ok", - version: "0.1.0", + version: pkg.version, uptime: expect.any(Number), browser: mockPoolStats }) @@ -115,7 +120,7 @@ describe('Health Route', () => { expect(res.json).toHaveBeenCalledWith({ status: "ok", - version: "0.1.0", + version: pkg.version, uptime: expect.any(Number), browser: mockPoolStats }) @@ -135,7 +140,7 @@ describe('Health Route', () => { const responseCall = res.json.mock.calls[0][0] expect(responseCall).toHaveProperty('status', 'ok') - expect(responseCall).toHaveProperty('version', '0.1.0') + expect(responseCall).toHaveProperty('version', pkg.version) expect(responseCall).toHaveProperty('uptime') expect(responseCall).toHaveProperty('browser') }) @@ -178,7 +183,7 @@ describe('Health Route', () => { expect(res.json).toHaveBeenCalledWith({ status: "ok", - version: "0.1.0", + version: pkg.version, uptime: expect.any(Number), browser: mockPoolStats }) diff --git a/src/routes/health.ts b/src/routes/health.ts index 2e9e435..cd03fa1 100644 --- a/src/routes/health.ts +++ b/src/routes/health.ts @@ -1,6 +1,10 @@ import { Router } from "express"; +import { createRequire } from "module"; import { getPoolStats } from "../services/browser.js"; +const require = createRequire(import.meta.url); +const pkg = require("../../package.json"); + export const healthRouter = Router(); /** @@ -27,7 +31,7 @@ healthRouter.get("/", (_req, res) => { const pool = getPoolStats(); res.json({ status: "ok", - version: "0.1.0", + version: pkg.version, uptime: process.uptime(), browser: pool, }); diff --git a/src/routes/signup.ts b/src/routes/signup.ts index bc47ab2..1a728e1 100644 --- a/src/routes/signup.ts +++ b/src/routes/signup.ts @@ -5,57 +5,6 @@ import logger from "../services/logger.js"; export const signupRouter = Router(); // Simple signup: email → instant API key (no verification for now) -/** - * @openapi - * /v1/signup/free: - * post: - * tags: [Signup] - * summary: Create a free account - * description: Sign up with an email to get a free API key (100 screenshots/month). - * operationId: signupFree - * requestBody: - * required: true - * content: - * application/json: - * schema: - * type: object - * required: [email] - * properties: - * email: - * type: string - * format: email - * description: Your email address - * example: "user@example.com" - * responses: - * 200: - * description: API key created - * content: - * application/json: - * schema: - * type: object - * properties: - * apiKey: - * type: string - * description: Your new API key - * tier: - * type: string - * example: free - * limit: - * type: integer - * example: 100 - * message: - * type: string - * 400: - * description: Invalid email - * content: - * application/json: - * schema: { $ref: "#/components/schemas/Error" } - * 500: - * description: Signup failed - * content: - * application/json: - * schema: { $ref: "#/components/schemas/Error" } - */ signupRouter.post("/free", async (req, res) => { const { email } = req.body;