test improvement
This commit is contained in:
Vendored
+42
@@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
# Generate test fixtures for file-info plugin tests
|
||||
|
||||
set -e
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
echo "Generating test fixtures..."
|
||||
|
||||
# Create a simple video file (if ffmpeg is available)
|
||||
if command -v ffmpeg &> /dev/null; then
|
||||
echo "Creating test-video.mp4..."
|
||||
ffmpeg -y -f lavfi -i testsrc=duration=1:size=160x120:rate=10 \
|
||||
-f lavfi -i sine=frequency=440:duration=1 \
|
||||
-c:v libx264 -preset ultrafast -c:a aac \
|
||||
test-video.mp4 2>/dev/null
|
||||
|
||||
echo "Creating test-audio.mp3..."
|
||||
ffmpeg -y -f lavfi -i sine=frequency=440:duration=1 \
|
||||
-c:a libmp3lame \
|
||||
test-audio.mp3 2>/dev/null
|
||||
else
|
||||
echo "Warning: ffmpeg not found, creating minimal video/audio stubs"
|
||||
# Create minimal MP4 file header (not a valid video, but has magic bytes)
|
||||
printf '\x00\x00\x00\x1c\x66\x74\x79\x70\x69\x73\x6f\x6d' > test-video.mp4
|
||||
# Create minimal MP3 file header
|
||||
printf '\xff\xfb\x90\x00' > test-audio.mp3
|
||||
fi
|
||||
|
||||
# Create a simple PNG image (1x1 pixel, red)
|
||||
echo "Creating test-image.png..."
|
||||
printf '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01\x08\x02\x00\x00\x00\x90wS\xde\x00\x00\x00\x0cIDATx\x9cc\xf8\xcf\xc0\x00\x00\x00\x03\x00\x01\x00\x05\xfe\xd4\x00\x00\x00\x00IEND\xaeB`\x82' > test-image.png
|
||||
|
||||
# Create a text file
|
||||
echo "Creating test-file.txt..."
|
||||
echo "This is a test file for file-info plugin tests." > test-file.txt
|
||||
|
||||
# Create a JSON file
|
||||
echo "Creating test-file.json..."
|
||||
echo '{"test": true, "name": "test-fixture"}' > test-file.json
|
||||
|
||||
echo "Test fixtures generated:"
|
||||
ls -la *.mp4 *.mp3 *.png *.txt *.json 2>/dev/null || true
|
||||
Vendored
BIN
Binary file not shown.
Vendored
+1
@@ -0,0 +1 @@
|
||||
{"test": true, "name": "test-fixture"}
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
This is a test file for file-info plugin tests.
|
||||
Vendored
BIN
Binary file not shown.
|
After Width: | Height: | Size: 69 B |
Vendored
BIN
Binary file not shown.
@@ -0,0 +1,155 @@
|
||||
/**
|
||||
* File Info Plugin Integration Tests
|
||||
*
|
||||
* Tests basic file information extraction.
|
||||
* Uses @metazla/filename-tools library for FileType class.
|
||||
*/
|
||||
|
||||
import { describe, it, expect, beforeAll } from 'vitest';
|
||||
import { FileType } from '@metazla/filename-tools';
|
||||
import * as fs from 'fs/promises';
|
||||
import * as path from 'path';
|
||||
import * as os from 'os';
|
||||
|
||||
// Dynamic import of plugin module
|
||||
let manifest: typeof import('../src/plugin.js').manifest;
|
||||
let processFile: typeof import('../src/plugin.js').process;
|
||||
|
||||
// Mock callback collector
|
||||
interface CallbackResult {
|
||||
taskId: string;
|
||||
status: 'completed' | 'failed' | 'skipped';
|
||||
duration: number;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
let lastCallback: CallbackResult | null = null;
|
||||
|
||||
const mockSendCallback = async (payload: CallbackResult): Promise<void> => {
|
||||
lastCallback = payload;
|
||||
};
|
||||
|
||||
// Create FileType instance for direct testing
|
||||
const fileType = new FileType();
|
||||
|
||||
describe('File Info Plugin Integration Tests', () => {
|
||||
let testDir: string;
|
||||
let testVideoFile: string;
|
||||
let testTextFile: string;
|
||||
|
||||
beforeAll(async () => {
|
||||
const plugin = await import('../src/plugin.js');
|
||||
manifest = plugin.manifest;
|
||||
processFile = plugin.process;
|
||||
|
||||
// Create temporary test files
|
||||
testDir = await fs.mkdtemp(path.join(os.tmpdir(), 'file-info-test-'));
|
||||
testVideoFile = path.join(testDir, 'test-movie.mkv');
|
||||
testTextFile = path.join(testDir, 'readme.txt');
|
||||
|
||||
// Create dummy files
|
||||
await fs.writeFile(testVideoFile, 'fake video content');
|
||||
await fs.writeFile(testTextFile, 'This is a text file');
|
||||
});
|
||||
|
||||
describe('Manifest', () => {
|
||||
it('has required fields', () => {
|
||||
expect(manifest.id).toBe('file-info');
|
||||
expect(manifest.name).toBeDefined();
|
||||
expect(manifest.version).toBeDefined();
|
||||
expect(manifest.dependencies).toEqual([]);
|
||||
expect(manifest.priority).toBe(10);
|
||||
});
|
||||
|
||||
it('declares correct schema', () => {
|
||||
expect(manifest.schema).toHaveProperty('fileType');
|
||||
expect(manifest.schema).toHaveProperty('mimeType');
|
||||
expect(manifest.schema).toHaveProperty('sizeByte');
|
||||
expect(manifest.schema).toHaveProperty('fileName');
|
||||
expect(manifest.schema).toHaveProperty('extension');
|
||||
});
|
||||
});
|
||||
|
||||
describe('FileType Class', () => {
|
||||
it('detects video extension', () => {
|
||||
const result = fileType.getFileTypeFromExtension('/movies/test.mkv');
|
||||
expect(result).toBe('video');
|
||||
});
|
||||
|
||||
it('detects audio extension', () => {
|
||||
const result = fileType.getFileTypeFromExtension('/music/song.mp3');
|
||||
expect(result).toBe('audio');
|
||||
});
|
||||
|
||||
it('detects image or document extension', () => {
|
||||
const result = fileType.getFileTypeFromExtension('/photos/image.jpg');
|
||||
// FileType may classify jpg as 'image' or 'document' depending on implementation
|
||||
expect(['image', 'document']).toContain(result);
|
||||
});
|
||||
|
||||
it('detects subtitle extension', () => {
|
||||
const result = fileType.getFileTypeFromExtension('/subs/movie.srt');
|
||||
expect(result).toBe('subtitle');
|
||||
});
|
||||
|
||||
it('detects document extension', () => {
|
||||
const result = fileType.getFileTypeFromExtension('/docs/readme.txt');
|
||||
expect(result).toBe('document');
|
||||
});
|
||||
|
||||
it('handles unknown extension', () => {
|
||||
const result = fileType.getFileTypeFromExtension('/files/unknown.xyz');
|
||||
expect(result).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Extension Parsing', () => {
|
||||
it('extracts extension from filename', () => {
|
||||
const ext = path.extname('/movies/Inception.2010.mkv').slice(1).toLowerCase();
|
||||
expect(ext).toBe('mkv');
|
||||
});
|
||||
|
||||
it('extracts filename from path', () => {
|
||||
const fileName = path.basename('/movies/Inception.2010.mkv');
|
||||
expect(fileName).toBe('Inception.2010.mkv');
|
||||
});
|
||||
|
||||
it('handles multiple dots in filename', () => {
|
||||
const fileName = path.basename('/movies/Movie.Name.2010.1080p.mkv');
|
||||
const ext = path.extname(fileName).slice(1).toLowerCase();
|
||||
expect(fileName).toBe('Movie.Name.2010.1080p.mkv');
|
||||
expect(ext).toBe('mkv');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Process Function', () => {
|
||||
it('processes file successfully', async () => {
|
||||
await processFile({
|
||||
taskId: 'test-file-1',
|
||||
cid: 'test-cid-file',
|
||||
filePath: testVideoFile,
|
||||
callbackUrl: 'http://localhost/callback',
|
||||
metaCoreUrl: 'http://localhost:9000',
|
||||
existingMeta: {},
|
||||
}, mockSendCallback);
|
||||
|
||||
expect(lastCallback).toBeDefined();
|
||||
expect(lastCallback?.status).toBe('completed');
|
||||
expect(lastCallback?.taskId).toBe('test-file-1');
|
||||
});
|
||||
|
||||
it('processes text file successfully', async () => {
|
||||
await processFile({
|
||||
taskId: 'test-file-2',
|
||||
cid: 'test-cid-text',
|
||||
filePath: testTextFile,
|
||||
callbackUrl: 'http://localhost/callback',
|
||||
metaCoreUrl: 'http://localhost:9000',
|
||||
existingMeta: {},
|
||||
}, mockSendCallback);
|
||||
|
||||
expect(lastCallback).toBeDefined();
|
||||
expect(lastCallback?.status).toBe('completed');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user