diff --git a/.gitignore b/.gitignore index 14885812..67bbd144 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,8 @@ -node_modules +node_modules/ +dist/ .env -.env.funder -*.pem +__pycache__/ +*.log +.DS_Store +coverage/ +.nyc_output/ \ No newline at end of file diff --git a/package.json b/package.json index 88840d66..fd45f4e4 100644 --- a/package.json +++ b/package.json @@ -1,19 +1,17 @@ { - "name": "auto-funder-express", + "name": "hero-api", "version": "1.0.0", - "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "vitest run", + "test:watch": "vitest" + }, + "devDependencies": { + "vitest": "^0.34.0", + "supertest": "^6.3.3", + "@types/express": "^4.17.17", + "@types/supertest": "^2.0.12" }, - "keywords": [], - "author": "", - "license": "ISC", - "description": "", "dependencies": { - "@_koii/create-task-cli": "^1.1.3-beta.1", - "axios": "^1.7.7", - "crypto": "^1.0.1", - "dotenv": "^16.4.5", - "express": "^4.21.0" + "express": "^4.18.2" } -} +} \ No newline at end of file diff --git a/src/app.ts b/src/app.ts new file mode 100644 index 00000000..6462cea2 --- /dev/null +++ b/src/app.ts @@ -0,0 +1,9 @@ +import express from 'express'; +import heroRoutes from './routes/heroRoutes'; + +const app = express(); + +// Use hero routes +app.use(heroRoutes); + +export default app; \ No newline at end of file diff --git a/src/routes/heroRoutes.ts b/src/routes/heroRoutes.ts new file mode 100644 index 00000000..8df6d025 --- /dev/null +++ b/src/routes/heroRoutes.ts @@ -0,0 +1,18 @@ +import express from 'express'; + +const router = express.Router(); + +const heroData = { + 'spiderman': { + name: 'Spider-Man', + realName: 'Peter Parker', + powers: ['Wall-crawling', 'Spider-sense', 'Superhuman strength'], + firstAppearance: 'Amazing Fantasy #15' + } +}; + +router.get(['/spiderMan', '/spiderman', '/spider-man', '/SpiderMan'], (req, res) => { + res.json(heroData['spiderman']); +}); + +export default router; \ No newline at end of file diff --git a/tests/spiderMan.test.ts b/tests/spiderMan.test.ts new file mode 100644 index 00000000..cb7d16f6 --- /dev/null +++ b/tests/spiderMan.test.ts @@ -0,0 +1,37 @@ +import { describe, it, expect } from 'vitest'; +import request from 'supertest'; +import app from '../src/app'; // Adjust the path to your Express app + +describe('Spider-Man Endpoint', () => { + it('should return correct Spider-Man information', async () => { + const response = await request(app) + .get('/spiderMan') + .expect('Content-Type', /json/) + .expect(200); + + expect(response.body).toEqual({ + name: 'Spider-Man', + realName: 'Peter Parker', + powers: ['Wall-crawling', 'Spider-sense', 'Superhuman strength'], + firstAppearance: 'Amazing Fantasy #15' + }); + }); + + it('should handle case variations', async () => { + const variations = ['/spiderman', '/spider-man', '/SpiderMan']; + + for (const path of variations) { + const response = await request(app) + .get(path) + .expect('Content-Type', /json/) + .expect(200); + + expect(response.body).toEqual({ + name: 'Spider-Man', + realName: 'Peter Parker', + powers: ['Wall-crawling', 'Spider-sense', 'Superhuman strength'], + firstAppearance: 'Amazing Fantasy #15' + }); + } + }); +}); \ No newline at end of file