45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
import type { BangDreamDataProvider } from '@/modules/qqbot/plugins/bangdream/src/infrastructure/integration/bangdream-data-provider';
|
|
import { CardArtResourceRepository } from '@/modules/qqbot/plugins/bangdream/src/domain/card/card-art.repository';
|
|
|
|
/**
|
|
* 创建 BangDream 插件对象或配置。
|
|
* @returns 创建后的 BangDream 插件对象或配置。
|
|
*/
|
|
function createProviderMock(): jest.Mocked<BangDreamDataProvider> {
|
|
return {
|
|
getAsset: jest.fn(),
|
|
getJson: jest.fn(),
|
|
getTracker: jest.fn(),
|
|
name: 'MockBestdori',
|
|
resolveUrl: jest.fn((pathOrUrl) => `https://bestdori.example${pathOrUrl}`),
|
|
};
|
|
}
|
|
|
|
describe('BangDream card art resource repository', () => {
|
|
it('downloads card icon and illustration frames through the provider', async () => {
|
|
const provider = createProviderMock();
|
|
const iconFrameBuffer = Buffer.from('icon-frame');
|
|
const illustrationFrameBuffer = Buffer.from('illustration-frame');
|
|
provider.getAsset
|
|
.mockResolvedValueOnce(iconFrameBuffer)
|
|
.mockResolvedValueOnce(illustrationFrameBuffer);
|
|
const repository = new CardArtResourceRepository(provider);
|
|
|
|
await expect(repository.getIconFrameBuffer(1, 'cool')).resolves.toBe(
|
|
iconFrameBuffer,
|
|
);
|
|
await expect(
|
|
repository.getIllustrationFrameBuffer(5, 'happy'),
|
|
).resolves.toBe(illustrationFrameBuffer);
|
|
|
|
expect(provider.getAsset).toHaveBeenNthCalledWith(
|
|
1,
|
|
'/res/image/card-1-cool.png',
|
|
);
|
|
expect(provider.getAsset).toHaveBeenNthCalledWith(
|
|
2,
|
|
'/res/image/frame-5.png',
|
|
);
|
|
});
|
|
});
|