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.
93 lines
3.4 KiB
JavaScript
93 lines
3.4 KiB
JavaScript
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.DefaultFetcher = exports.BaseFetcher = void 0;
|
|
const debug_1 = __importDefault(require("debug"));
|
|
const fs_1 = __importDefault(require("fs"));
|
|
const make_fetch_happen_1 = __importDefault(require("make-fetch-happen"));
|
|
const util_1 = __importDefault(require("util"));
|
|
const error_1 = require("./error");
|
|
const tmpfile_1 = require("./utils/tmpfile");
|
|
const log = (0, debug_1.default)('tuf:fetch');
|
|
const USER_AGENT_HEADER = 'User-Agent';
|
|
class BaseFetcher {
|
|
// Download file from given URL. The file is downloaded to a temporary
|
|
// location and then passed to the given handler. The handler is responsible
|
|
// for moving the file to its final location. The temporary file is deleted
|
|
// after the handler returns.
|
|
async downloadFile(url, maxLength, handler) {
|
|
return (0, tmpfile_1.withTempFile)(async (tmpFile) => {
|
|
const reader = await this.fetch(url);
|
|
let numberOfBytesReceived = 0;
|
|
const fileStream = fs_1.default.createWriteStream(tmpFile);
|
|
// Read the stream a chunk at a time so that we can check
|
|
// the length of the file as we go
|
|
try {
|
|
for await (const chunk of reader) {
|
|
numberOfBytesReceived += chunk.length;
|
|
if (numberOfBytesReceived > maxLength) {
|
|
throw new error_1.DownloadLengthMismatchError('Max length reached');
|
|
}
|
|
await writeBufferToStream(fileStream, chunk);
|
|
}
|
|
}
|
|
finally {
|
|
// Make sure we always close the stream
|
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
await util_1.default.promisify(fileStream.close).bind(fileStream)();
|
|
}
|
|
return handler(tmpFile);
|
|
});
|
|
}
|
|
// Download bytes from given URL.
|
|
async downloadBytes(url, maxLength) {
|
|
return this.downloadFile(url, maxLength, async (file) => {
|
|
const stream = fs_1.default.createReadStream(file);
|
|
const chunks = [];
|
|
for await (const chunk of stream) {
|
|
chunks.push(chunk);
|
|
}
|
|
return Buffer.concat(chunks);
|
|
});
|
|
}
|
|
}
|
|
exports.BaseFetcher = BaseFetcher;
|
|
class DefaultFetcher extends BaseFetcher {
|
|
userAgent;
|
|
timeout;
|
|
retry;
|
|
constructor(options = {}) {
|
|
super();
|
|
this.userAgent = options.userAgent;
|
|
this.timeout = options.timeout;
|
|
this.retry = options.retry;
|
|
}
|
|
async fetch(url) {
|
|
log('GET %s', url);
|
|
const response = await (0, make_fetch_happen_1.default)(url, {
|
|
headers: {
|
|
[USER_AGENT_HEADER]: this.userAgent || '',
|
|
},
|
|
timeout: this.timeout,
|
|
retry: this.retry,
|
|
});
|
|
if (!response.ok || !response?.body) {
|
|
throw new error_1.DownloadHTTPError('Failed to download', response.status);
|
|
}
|
|
return response.body;
|
|
}
|
|
}
|
|
exports.DefaultFetcher = DefaultFetcher;
|
|
const writeBufferToStream = async (stream, buffer) => {
|
|
return new Promise((resolve, reject) => {
|
|
stream.write(buffer, (err) => {
|
|
if (err) {
|
|
reject(err);
|
|
}
|
|
resolve(true);
|
|
});
|
|
});
|
|
};
|