test: disabled logger when in test mode; refactor: type names

This commit is contained in:
Roberto Tonino 2021-04-09 21:06:02 +02:00
parent 418fc5647f
commit c0148e8301
4 changed files with 13 additions and 8 deletions

View File

@ -5,7 +5,10 @@ import cookieParser from 'cookie-parser'
import { WEBUI_DIR } from './helpers/paths'
export function registerMiddlewares(app: Application) {
app.use(logger('dev'))
if (process.env.NODE_ENV !== 'test') {
app.use(logger('dev'))
}
app.use(express.json())
app.use(express.urlencoded({ extended: false }))
app.use(cookieParser())

View File

@ -16,6 +16,7 @@ describe('albumSearch requests', () => {
responseStatusCollector.push((await request(app).get(uri).send()).status)
}
expect(responseStatusCollector).toMatchObject(new Array(batchCalls.length).fill(200))
expect(responseStatusCollector).toMatchObject(new Array(responseStatusCollector.length).fill(200))
})

View File

@ -1,14 +1,14 @@
import { RequestHandler } from 'express'
import { ApiHandler } from '../../../types'
export interface RawAlbumQueryParams {
export interface RawAlbumQuery {
term: string
start?: string
nb?: string
ack: number
}
export interface AlbumSearchParams extends Omit<RawAlbumQueryParams, 'start' | 'nb'> {
export interface AlbumSearchParams extends Omit<RawAlbumQuery, 'start' | 'nb'> {
start: number
nb: number
}
@ -16,12 +16,12 @@ export interface AlbumSearchParams extends Omit<RawAlbumQueryParams, 'start' | '
export interface AlbumResponse {
data: any[]
total: number
ack: RawAlbumQueryParams['ack']
ack: RawAlbumQuery['ack']
}
const path: ApiHandler['path'] = '/album-search/'
const handler: RequestHandler<{}, {}, {}, RawAlbumQueryParams> = (req, res, next) => {
const handler: RequestHandler<{}, {}, {}, RawAlbumQuery> = (req, res, next) => {
if (!req.query) {
res.status(400).send()
next()
@ -51,7 +51,7 @@ const apiHandler = { path, handler }
export default apiHandler
function parseQuery(query: RawAlbumQueryParams): AlbumSearchParams {
function parseQuery(query: RawAlbumQuery): AlbumSearchParams {
let startingPoint = 0
if (typeof query.start !== 'undefined') {

View File

@ -1,11 +1,12 @@
import { RequestHandler } from 'express'
/* === Utilities === */
export type WithOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>
// https://github.com/Microsoft/TypeScript/issues/25760#issuecomment-614417742
export type Optional<T, K extends keyof T> = Omit<T, K> & Partial<T>
export type Port = number | string | boolean
export interface ApiHandler {
path: string
handler: RequestHandler
handler: RequestHandler<any, any, any, any>
}