Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -16,12 +16,18 @@ import { streamArchiveEntry } from '../../src/services/archiveReader';
|
||||
import prisma from '../../src/plugins/prisma';
|
||||
import { createHash } from 'crypto';
|
||||
|
||||
// Mock Date.now() para timestamps consistentes en tests
|
||||
const FIXED_TIMESTAMP = 1234567890123;
|
||||
const dateNowSpy = vi.spyOn(Date, 'now').mockReturnValue(FIXED_TIMESTAMP);
|
||||
|
||||
beforeEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
dateNowSpy.mockReturnValue(FIXED_TIMESTAMP);
|
||||
});
|
||||
|
||||
describe('services/importService (archive entries)', () => {
|
||||
it('procesa una entrada interna usando streamArchiveEntry y crea Game con source=rom', async () => {
|
||||
const data = Buffer.from('import-archive-test');
|
||||
const files = [
|
||||
{
|
||||
path: '/roms/collection.zip::inner/rom1.bin',
|
||||
@@ -29,14 +35,12 @@ describe('services/importService (archive entries)', () => {
|
||||
entryPath: 'inner/rom1.bin',
|
||||
filename: 'rom1.bin',
|
||||
name: 'inner/rom1.bin',
|
||||
size: 123,
|
||||
size: data.length,
|
||||
format: 'bin',
|
||||
isArchiveEntry: true,
|
||||
},
|
||||
];
|
||||
|
||||
const data = Buffer.from('import-archive-test');
|
||||
|
||||
(scanDirectory as unknown as Mock).mockResolvedValue(files);
|
||||
(streamArchiveEntry as unknown as Mock).mockResolvedValue(Readable.from([data]));
|
||||
|
||||
@@ -60,12 +64,12 @@ describe('services/importService (archive entries)', () => {
|
||||
});
|
||||
expect((prisma.game.create as unknown as Mock).mock.calls[0][0]).toEqual({
|
||||
data: {
|
||||
title: 'ROM1',
|
||||
slug: 'rom1-1234567890123',
|
||||
title: 'rom1',
|
||||
slug: expect.stringMatching(/^rom1-\d+$/),
|
||||
source: 'rom',
|
||||
romPath: '/roms/collection.zip::inner/rom1.bin',
|
||||
romFilename: 'rom1.bin',
|
||||
romSize: 123,
|
||||
romSize: data.length,
|
||||
romChecksum: md5,
|
||||
romFormat: 'bin',
|
||||
romHashes: expect.any(String),
|
||||
|
||||
Reference in New Issue
Block a user