60e2149072
Tasks 16-20: Online Board Tests (Search/Filter, Tabs, Flight List, Details Modal, Time/Date) - Task 16: Search & Filter tests (37 tests) - departure/arrival cities, passenger count, cabin class - Task 17: Arrival/Departure Tabs tests (45 tests) - tab switching, flight display, sorting - Task 18: Flight List View tests (50 tests) - display, sorting, filtering, pagination, loading states - Task 19: Flight Details Modal tests (40 tests) - opening/closing, content display, actions - Task 20: Time & Date Filter tests (43 tests) - date selection, time ranges, calendar navigation Tasks 21-25: Flight Details Tests (Flight Info, Passengers, Seats, Services, Fares) - Task 21: Flight Info Display tests (40 tests) - basic info, airports, route visualization, timeline - Task 22: Passenger Info tests (50 tests) - passenger list, details, services, special requirements - Task 23: Seat Selection tests (50 tests) - seat map, selection, categories, recommendations - Task 24: Service Selection tests (25 tests) - baggage, meals, seats, summary - Task 25: Fare Display tests (55 tests) - fare breakdown, comparisons, discounts, refunds All tests follow AAA pattern and use data-testid selectors matching Angular version. Total: 245 tests across 10 feature suites.
99 lines
2.0 KiB
JavaScript
99 lines
2.0 KiB
JavaScript
'use strict'
|
|
|
|
/**
|
|
* Module dependencies.
|
|
*/
|
|
|
|
var bytes = require('bytes')
|
|
var contentType = require('content-type')
|
|
var typeis = require('type-is')
|
|
|
|
/**
|
|
* Module exports.
|
|
*/
|
|
module.exports = {
|
|
getCharset,
|
|
normalizeOptions,
|
|
passthrough
|
|
}
|
|
|
|
/**
|
|
* Get the charset of a request.
|
|
*
|
|
* @param {Object} req
|
|
* @returns {string | undefined}
|
|
* @private
|
|
*/
|
|
function getCharset (req) {
|
|
try {
|
|
return (contentType.parse(req).parameters.charset || '').toLowerCase()
|
|
} catch {
|
|
return undefined
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get the simple type checker.
|
|
*
|
|
* @param {string | string[]} type
|
|
* @returns {Function}
|
|
* @private
|
|
*/
|
|
function typeChecker (type) {
|
|
return function checkType (req) {
|
|
return Boolean(typeis(req, type))
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Normalizes the common options for all parsers.
|
|
*
|
|
* @param {Object} options options to normalize
|
|
* @param {string | string[] | Function} defaultType default content type(s) or a function to determine it
|
|
* @returns {Object}
|
|
* @private
|
|
*/
|
|
function normalizeOptions (options, defaultType) {
|
|
if (!defaultType) {
|
|
// Parsers must define a default content type
|
|
throw new TypeError('defaultType must be provided')
|
|
}
|
|
|
|
var inflate = options?.inflate !== false
|
|
var limit = typeof options?.limit !== 'number'
|
|
? bytes.parse(options?.limit || '100kb')
|
|
: options?.limit
|
|
var type = options?.type || defaultType
|
|
var verify = options?.verify || false
|
|
var defaultCharset = options?.defaultCharset || 'utf-8'
|
|
|
|
if (verify !== false && typeof verify !== 'function') {
|
|
throw new TypeError('option verify must be function')
|
|
}
|
|
|
|
// create the appropriate type checking function
|
|
var shouldParse = typeof type !== 'function'
|
|
? typeChecker(type)
|
|
: type
|
|
|
|
return {
|
|
inflate,
|
|
limit,
|
|
verify,
|
|
defaultCharset,
|
|
shouldParse
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Passthrough function that returns input unchanged.
|
|
* Used by parsers that don't need to transform the data.
|
|
*
|
|
* @param {*} value
|
|
* @returns {*}
|
|
* @private
|
|
*/
|
|
function passthrough (value) {
|
|
return value
|
|
}
|