Pārlūkot izejas kodu

Update tests

Ensure tests pass before being used as template.
master
TheoryOfNekomata pirms 8 mēnešiem
vecāks
revīzija
66ec7bbabc
12 mainītis faili ar 85 papildinājumiem un 68 dzēšanām
  1. +1
    -1
      packages/cli/test/index.test.ts
  2. +1
    -4
      packages/cli/tsconfig.json
  3. +1
    -1
      packages/core/test/index.test.ts
  4. +1
    -4
      packages/core/tsconfig.json
  5. +0
    -1
      packages/web-api/package.json
  6. +3
    -3
      packages/web-api/src/index.ts
  7. +1
    -1
      packages/web-api/src/modules/adder/adder.controller.ts
  8. +1
    -1
      packages/web-api/src/routes.ts
  9. +75
    -5
      packages/web-api/test/index.test.ts
  10. +1
    -4
      packages/web-api/tsconfig.json
  11. +0
    -6
      packages/web-api/vite.config.ts
  12. +0
    -37
      pnpm-lock.yaml

+ 1
- 1
packages/cli/test/index.test.ts Parādīt failu

@@ -6,7 +6,7 @@ import { Cli } from '../src/packages/cli-wrapper';

vi.mock('process');

describe('blah', () => {
describe('cli', () => {
let cli: Cli;
beforeAll(() => {
cli = createCli({


+ 1
- 4
packages/cli/tsconfig.json Parādīt failu

@@ -16,9 +16,6 @@
"moduleResolution": "node",
"jsx": "react",
"esModuleInterop": true,
"target": "es2018",
"paths": {
"@/*": ["./src/*"],
}
"target": "es2018"
}
}

+ 1
- 1
packages/core/test/index.test.ts Parādīt failu

@@ -1,7 +1,7 @@
import { describe, it, expect } from 'vitest';
import { add } from '../src';

describe('blah', () => {
describe('core', () => {
it('returns result', () => {
expect(add({ a: 1, b: 1 })).toEqual(2);
});


+ 1
- 4
packages/core/tsconfig.json Parādīt failu

@@ -16,9 +16,6 @@
"moduleResolution": "node",
"jsx": "react",
"esModuleInterop": true,
"target": "es2018",
"paths": {
"@/*": ["./src/*"],
}
"target": "es2018"
}
}

+ 0
- 1
packages/web-api/package.json Parādīt failu

@@ -17,7 +17,6 @@
"tslib": "^2.6.2",
"typescript": "^5.4.5",
"vite": "^5.2.10",
"vite-tsconfig-paths": "^4.3.2",
"vitest": "^1.5.0"
},
"dependencies": {


+ 3
- 3
packages/web-api/src/index.ts Parādīt failu

@@ -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({
logger: config.meta.env !== 'test',


+ 1
- 1
packages/web-api/src/modules/adder/adder.controller.ts Parādīt failu

@@ -4,7 +4,7 @@ import {
AdderServiceImpl,
ArgumentOutOfRangeError,
InvalidArgumentTypeError,
} from '@/modules/adder/adder.service';
} from './adder.service';
import { constants } from 'http2';

export interface AdderController {


+ 1
- 1
packages/web-api/src/routes.ts Parādīt failu

@@ -1,5 +1,5 @@
import { FastifyInstance } from 'fastify';
import { AdderController, AdderControllerImpl } from '@/modules/adder';
import { AdderController, AdderControllerImpl } from './modules/adder';

export const addRoutes = (server: FastifyInstance) => {
const adderController: AdderController = new AdderControllerImpl();


+ 75
- 5
packages/web-api/test/index.test.ts Parādīt failu

@@ -16,7 +16,7 @@ import {
InvalidArgumentTypeError,
} from '../src/modules/adder';

describe('Example', () => {
describe('add', () => {
let server: FastifyInstance;
const body = { a: 1, b: 2 };

@@ -32,7 +32,7 @@ describe('Example', () => {
it('returns result when successful', async () => {
const response = await server
.inject()
.post('/')
.post('/add')
.body(body)
.headers({
'Accept': 'application/json',
@@ -47,7 +47,7 @@ describe('Example', () => {

const response = await server
.inject()
.post('/')
.post('/add')
.body(body)
.headers({
'Accept': 'application/json',
@@ -62,7 +62,7 @@ describe('Example', () => {

const response = await server
.inject()
.post('/')
.post('/add')
.body(body)
.headers({
'Accept': 'application/json',
@@ -77,7 +77,77 @@ describe('Example', () => {

const response = await server
.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 })
.headers({
'Accept': 'application/json',


+ 1
- 4
packages/web-api/tsconfig.json Parādīt failu

@@ -16,9 +16,6 @@
"moduleResolution": "node",
"jsx": "react",
"esModuleInterop": true,
"target": "es2018",
"paths": {
"@/*": ["./src/*"],
}
"target": "es2018"
}
}

+ 0
- 6
packages/web-api/vite.config.ts Parādīt failu

@@ -1,6 +0,0 @@
import { defineConfig } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths';

export default defineConfig({
plugins: [tsconfigPaths()],
});

+ 0
- 37
pnpm-lock.yaml Parādīt failu

@@ -82,9 +82,6 @@ importers:
vite:
specifier: ^5.2.10
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:
specifier: ^1.5.0
version: 1.5.0(@types/node@20.12.7)
@@ -1252,10 +1249,6 @@ packages:
engines: {node: '>=4'}
dev: true

/globrex@0.1.2:
resolution: {integrity: sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg==}
dev: true

/graceful-fs@4.2.11:
resolution: {integrity: sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==}
dev: true
@@ -1921,19 +1914,6 @@ packages:
engines: {node: '>=12'}
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:
resolution: {integrity: sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==}
dev: true
@@ -2001,23 +1981,6 @@ packages:
- terser
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):
resolution: {integrity: sha512-PAzgUZbP7msvQvqdSD+ErD5qGnSFiGOoWmV5yAKUEI0kdhjbH6nMWVyZQC/hSc4aXwc0oJ9aEdIiF9Oje0JFCw==}
engines: {node: ^18.0.0 || >=20.0.0}


Notiek ielāde…
Atcelt
Saglabāt