From 0294bb93b223c3851c28c2a7d4aa0cb05321a0c6 Mon Sep 17 00:00:00 2001 From: sunlei Date: Mon, 6 Jul 2026 16:48:50 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E8=A1=A5=E5=85=85Pio=20Live2D=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/asset/blog-live2d-asset.service.spec.ts | 52 ++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/test/asset/blog-live2d-asset.service.spec.ts b/test/asset/blog-live2d-asset.service.spec.ts index ffb1c6c..cdef14e 100644 --- a/test/asset/blog-live2d-asset.service.spec.ts +++ b/test/asset/blog-live2d-asset.service.spec.ts @@ -153,6 +153,21 @@ describe('BlogLive2DAssetService', () => { ); }); + it('maps the fixed MOC texture manifest below the configured MinIO prefix', async () => { + const minio = createMinio(); + const service = new BlogLive2DAssetService( + minio as never, + createConfig() as never, + ); + + await service.getRuntimeObject('moc', ['textures', 'manifest.json']); + + expect(minio.getObject).toHaveBeenCalledWith( + 'blog/live2d/pio/moc/textures/manifest.json', + 'kt-template-online', + ); + }); + it('maps missing MinIO runtime objects to HTTP 404', async () => { const minio = createMinio(); minio.getObject.mockRejectedValueOnce( @@ -326,6 +341,43 @@ describe('BlogLive2DAssetController', () => { } }); + it('streams fixed Pio MOC texture manifests with a short cache policy', async () => { + const minio = createMinio(); + const moduleRef = await Test.createTestingModule({ + controllers: [BlogLive2DAssetController], + providers: [ + BlogLive2DAssetService, + { + provide: MinioClientService, + useValue: minio, + }, + { + provide: ConfigService, + useValue: createConfig(), + }, + ], + }).compile(); + const app = moduleRef.createNestApplication(); + await app.init(); + + try { + const response = await request(app.getHttpServer()) + .get('/blog/live2d/pio/moc/textures/manifest.json') + .set('Referer', 'https://blog.kwitsukasa.top/post/1') + .expect(HttpStatus.OK); + + expect(response.body).toEqual({ ok: true }); + expect(response.headers['content-type']).toContain('application/json'); + expect(response.headers['cache-control']).toBe('public, max-age=60'); + expect(minio.getObject).toHaveBeenCalledWith( + 'blog/live2d/pio/moc/textures/manifest.json', + 'kt-template-online', + ); + } finally { + await app.close(); + } + }); + it('rejects external hotlink requests before streaming assets', async () => { const minio = createMinio(); const moduleRef = await Test.createTestingModule({