@@ -6,7 +6,7 @@ import { Cli } from '../src/packages/cli-wrapper'; | |||||
vi.mock('process'); | vi.mock('process'); | ||||
describe('blah', () => { | |||||
describe('cli', () => { | |||||
let cli: Cli; | let cli: Cli; | ||||
beforeAll(() => { | beforeAll(() => { | ||||
cli = createCli({ | cli = createCli({ | ||||
@@ -16,9 +16,6 @@ | |||||
"moduleResolution": "node", | "moduleResolution": "node", | ||||
"jsx": "react", | "jsx": "react", | ||||
"esModuleInterop": true, | "esModuleInterop": true, | ||||
"target": "es2018", | |||||
"paths": { | |||||
"@/*": ["./src/*"], | |||||
} | |||||
"target": "es2018" | |||||
} | } | ||||
} | } |
@@ -1,7 +1,7 @@ | |||||
import { describe, it, expect } from 'vitest'; | import { describe, it, expect } from 'vitest'; | ||||
import { add } from '../src'; | import { add } from '../src'; | ||||
describe('blah', () => { | |||||
describe('core', () => { | |||||
it('returns result', () => { | it('returns result', () => { | ||||
expect(add({ a: 1, b: 1 })).toEqual(2); | expect(add({ a: 1, b: 1 })).toEqual(2); | ||||
}); | }); | ||||
@@ -16,9 +16,6 @@ | |||||
"moduleResolution": "node", | "moduleResolution": "node", | ||||
"jsx": "react", | "jsx": "react", | ||||
"esModuleInterop": true, | "esModuleInterop": true, | ||||
"target": "es2018", | |||||
"paths": { | |||||
"@/*": ["./src/*"], | |||||
} | |||||
"target": "es2018" | |||||
} | } | ||||
} | } |
@@ -17,7 +17,6 @@ | |||||
"tslib": "^2.6.2", | "tslib": "^2.6.2", | ||||
"typescript": "^5.4.5", | "typescript": "^5.4.5", | ||||
"vite": "^5.2.10", | "vite": "^5.2.10", | ||||
"vite-tsconfig-paths": "^4.3.2", | |||||
"vitest": "^1.5.0" | "vitest": "^1.5.0" | ||||
}, | }, | ||||
"dependencies": { | "dependencies": { | ||||
@@ -1,6 +1,6 @@ | |||||
import { createServer } from '@/server'; | |||||
import { addRoutes } from '@/routes'; | |||||
import * as config from '@/config'; | |||||
import { createServer } from './server'; | |||||
import { addRoutes } from './routes'; | |||||
import * as config from './config'; | |||||
const server = createServer({ | const server = createServer({ | ||||
logger: config.meta.env !== 'test', | logger: config.meta.env !== 'test', | ||||
@@ -4,7 +4,7 @@ import { | |||||
AdderServiceImpl, | AdderServiceImpl, | ||||
ArgumentOutOfRangeError, | ArgumentOutOfRangeError, | ||||
InvalidArgumentTypeError, | InvalidArgumentTypeError, | ||||
} from '@/modules/adder/adder.service'; | |||||
} from './adder.service'; | |||||
import { constants } from 'http2'; | import { constants } from 'http2'; | ||||
export interface AdderController { | export interface AdderController { | ||||
@@ -1,5 +1,5 @@ | |||||
import { FastifyInstance } from 'fastify'; | import { FastifyInstance } from 'fastify'; | ||||
import { AdderController, AdderControllerImpl } from '@/modules/adder'; | |||||
import { AdderController, AdderControllerImpl } from './modules/adder'; | |||||
export const addRoutes = (server: FastifyInstance) => { | export const addRoutes = (server: FastifyInstance) => { | ||||
const adderController: AdderController = new AdderControllerImpl(); | const adderController: AdderController = new AdderControllerImpl(); | ||||
@@ -16,7 +16,7 @@ import { | |||||
InvalidArgumentTypeError, | InvalidArgumentTypeError, | ||||
} from '../src/modules/adder'; | } from '../src/modules/adder'; | ||||
describe('Example', () => { | |||||
describe('add', () => { | |||||
let server: FastifyInstance; | let server: FastifyInstance; | ||||
const body = { a: 1, b: 2 }; | const body = { a: 1, b: 2 }; | ||||
@@ -32,7 +32,7 @@ describe('Example', () => { | |||||
it('returns result when successful', async () => { | it('returns result when successful', async () => { | ||||
const response = await server | const response = await server | ||||
.inject() | .inject() | ||||
.post('/') | |||||
.post('/add') | |||||
.body(body) | .body(body) | ||||
.headers({ | .headers({ | ||||
'Accept': 'application/json', | 'Accept': 'application/json', | ||||
@@ -47,7 +47,7 @@ describe('Example', () => { | |||||
const response = await server | const response = await server | ||||
.inject() | .inject() | ||||
.post('/') | |||||
.post('/add') | |||||
.body(body) | .body(body) | ||||
.headers({ | .headers({ | ||||
'Accept': 'application/json', | 'Accept': 'application/json', | ||||
@@ -62,7 +62,7 @@ describe('Example', () => { | |||||
const response = await server | const response = await server | ||||
.inject() | .inject() | ||||
.post('/') | |||||
.post('/add') | |||||
.body(body) | .body(body) | ||||
.headers({ | .headers({ | ||||
'Accept': 'application/json', | 'Accept': 'application/json', | ||||
@@ -77,7 +77,77 @@ describe('Example', () => { | |||||
const response = await server | const response = await server | ||||
.inject() | .inject() | ||||
.post('/') | |||||
.post('/add') | |||||
.body({ a: 1, b: 2 }) | |||||
.headers({ | |||||
'Accept': 'application/json', | |||||
}); | |||||
expect(response.statusCode).toBe(constants.HTTP_STATUS_INTERNAL_SERVER_ERROR); | |||||
}); | |||||
}); | |||||
describe('subtract', () => { | |||||
let server: FastifyInstance; | |||||
const body = { a: 1, b: 2 }; | |||||
beforeAll(() => { | |||||
server = createServer(); | |||||
addRoutes(server); | |||||
}); | |||||
afterAll(async () => { | |||||
await server.close(); | |||||
}); | |||||
it('returns result when successful', async () => { | |||||
const response = await server | |||||
.inject() | |||||
.post('/subtract') | |||||
.body(body) | |||||
.headers({ | |||||
'Accept': 'application/json', | |||||
}); | |||||
expect(response.statusCode).toBe(constants.HTTP_STATUS_OK); | |||||
}); | |||||
it('returns error when given invalid inputs', async () => { | |||||
vi.spyOn(AdderServiceImpl.prototype, 'addNumbers').mockImplementationOnce(() => { | |||||
throw new InvalidArgumentTypeError('Invalid input'); | |||||
}); | |||||
const response = await server | |||||
.inject() | |||||
.post('/subtract') | |||||
.body(body) | |||||
.headers({ | |||||
'Accept': 'application/json', | |||||
}); | |||||
expect(response.statusCode).toBe(constants.HTTP_STATUS_BAD_REQUEST); | |||||
}); | |||||
it('returns error when given out-of-range inputs', async () => { | |||||
vi.spyOn(AdderServiceImpl.prototype, 'addNumbers').mockImplementationOnce(() => { | |||||
throw new ArgumentOutOfRangeError('Out of range'); | |||||
}); | |||||
const response = await server | |||||
.inject() | |||||
.post('/subtract') | |||||
.body(body) | |||||
.headers({ | |||||
'Accept': 'application/json', | |||||
}); | |||||
expect(response.statusCode).toBe(constants.HTTP_STATUS_BAD_REQUEST); | |||||
}); | |||||
it('returns error when an unexpected error occurs', async () => { | |||||
vi.spyOn(AdderServiceImpl.prototype, 'addNumbers').mockImplementationOnce(() => { | |||||
throw new Error('Unexpected error'); | |||||
}); | |||||
const response = await server | |||||
.inject() | |||||
.post('/subtract') | |||||
.body({ a: 1, b: 2 }) | .body({ a: 1, b: 2 }) | ||||
.headers({ | .headers({ | ||||
'Accept': 'application/json', | 'Accept': 'application/json', | ||||
@@ -16,9 +16,6 @@ | |||||
"moduleResolution": "node", | "moduleResolution": "node", | ||||
"jsx": "react", | "jsx": "react", | ||||
"esModuleInterop": true, | "esModuleInterop": true, | ||||
"target": "es2018", | |||||
"paths": { | |||||
"@/*": ["./src/*"], | |||||
} | |||||
"target": "es2018" | |||||
} | } | ||||
} | } |
@@ -1,6 +0,0 @@ | |||||
import { defineConfig } from 'vite'; | |||||
import tsconfigPaths from 'vite-tsconfig-paths'; | |||||
export default defineConfig({ | |||||
plugins: [tsconfigPaths()], | |||||
}); |
@@ -82,9 +82,6 @@ importers: | |||||
vite: | vite: | ||||
specifier: ^5.2.10 | specifier: ^5.2.10 | ||||
version: 5.2.10(@types/node@20.12.7) | version: 5.2.10(@types/node@20.12.7) | ||||
vite-tsconfig-paths: | |||||
specifier: ^4.3.2 | |||||
version: 4.3.2(typescript@5.4.5)(vite@5.2.10) | |||||
vitest: | vitest: | ||||
specifier: ^1.5.0 | specifier: ^1.5.0 | ||||
version: 1.5.0(@types/node@20.12.7) | version: 1.5.0(@types/node@20.12.7) | ||||
@@ -1252,10 +1249,6 @@ packages: | |||||
engines: {node: '>=4'} | engines: {node: '>=4'} | ||||
dev: true | dev: true | ||||
/globrex@0.1.2: | |||||
resolution: {integrity: sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg==} | |||||
dev: true | |||||
/graceful-fs@4.2.11: | /graceful-fs@4.2.11: | ||||
resolution: {integrity: sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==} | resolution: {integrity: sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==} | ||||
dev: true | dev: true | ||||
@@ -1921,19 +1914,6 @@ packages: | |||||
engines: {node: '>=12'} | engines: {node: '>=12'} | ||||
dev: false | dev: false | ||||
/tsconfck@3.0.3(typescript@5.4.5): | |||||
resolution: {integrity: sha512-4t0noZX9t6GcPTfBAbIbbIU4pfpCwh0ueq3S4O/5qXI1VwK1outmxhe9dOiEWqMz3MW2LKgDTpqWV+37IWuVbA==} | |||||
engines: {node: ^18 || >=20} | |||||
hasBin: true | |||||
peerDependencies: | |||||
typescript: ^5.0.0 | |||||
peerDependenciesMeta: | |||||
typescript: | |||||
optional: true | |||||
dependencies: | |||||
typescript: 5.4.5 | |||||
dev: true | |||||
/tslib@2.6.2: | /tslib@2.6.2: | ||||
resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==} | resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==} | ||||
dev: true | dev: true | ||||
@@ -2001,23 +1981,6 @@ packages: | |||||
- terser | - terser | ||||
dev: true | dev: true | ||||
/vite-tsconfig-paths@4.3.2(typescript@5.4.5)(vite@5.2.10): | |||||
resolution: {integrity: sha512-0Vd/a6po6Q+86rPlntHye7F31zA2URZMbH8M3saAZ/xR9QoGN/L21bxEGfXdWmFdNkqPpRdxFT7nmNe12e9/uA==} | |||||
peerDependencies: | |||||
vite: '*' | |||||
peerDependenciesMeta: | |||||
vite: | |||||
optional: true | |||||
dependencies: | |||||
debug: 4.3.4 | |||||
globrex: 0.1.2 | |||||
tsconfck: 3.0.3(typescript@5.4.5) | |||||
vite: 5.2.10(@types/node@20.12.7) | |||||
transitivePeerDependencies: | |||||
- supports-color | |||||
- typescript | |||||
dev: true | |||||
/vite@5.2.10(@types/node@20.12.7): | /vite@5.2.10(@types/node@20.12.7): | ||||
resolution: {integrity: sha512-PAzgUZbP7msvQvqdSD+ErD5qGnSFiGOoWmV5yAKUEI0kdhjbH6nMWVyZQC/hSc4aXwc0oJ9aEdIiF9Oje0JFCw==} | resolution: {integrity: sha512-PAzgUZbP7msvQvqdSD+ErD5qGnSFiGOoWmV5yAKUEI0kdhjbH6nMWVyZQC/hSc4aXwc0oJ9aEdIiF9Oje0JFCw==} | ||||
engines: {node: ^18.0.0 || >=20.0.0} | engines: {node: ^18.0.0 || >=20.0.0} | ||||