og
All checks were successful
Build & Deploy KLZ Cables / build-and-deploy (push) Successful in 4m48s
All checks were successful
Build & Deploy KLZ Cables / build-and-deploy (push) Successful in 4m48s
This commit is contained in:
52
tests/og-image.test.ts
Normal file
52
tests/og-image.test.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
|
||||
const BASE_URL = process.env.TEST_URL || 'http://localhost:3000';
|
||||
|
||||
describe('OG Image Generation', () => {
|
||||
const locales = ['de', 'en'];
|
||||
const productSlugs = ['nay2y']; // Based on data/products/de/nay2y.mdx
|
||||
|
||||
async function verifyImageResponse(response: Response) {
|
||||
expect(response.status).toBe(200);
|
||||
expect(response.headers.get('content-type')).toContain('image/png');
|
||||
|
||||
const buffer = await response.arrayBuffer();
|
||||
const bytes = new Uint8Array(buffer);
|
||||
|
||||
// Check for PNG signature: 89 50 4E 47 0D 0A 1A 0A
|
||||
expect(bytes[0]).toBe(0x89);
|
||||
expect(bytes[1]).toBe(0x50);
|
||||
expect(bytes[2]).toBe(0x4E);
|
||||
expect(bytes[3]).toBe(0x47);
|
||||
|
||||
// Check that the image is not empty and has a reasonable size
|
||||
// A 1200x630 OG image should be at least 4KB
|
||||
expect(bytes.length).toBeGreaterThan(4000);
|
||||
}
|
||||
|
||||
locales.forEach((locale) => {
|
||||
it(`should generate main OG image for ${locale}`, async () => {
|
||||
const url = `${BASE_URL}/${locale}/opengraph-image`;
|
||||
const response = await fetch(url);
|
||||
await verifyImageResponse(response);
|
||||
}, 30000);
|
||||
|
||||
it(`should generate product OG image for ${locale} with slug ${productSlugs[0]}`, async () => {
|
||||
const url = `${BASE_URL}/${locale}/api/og/product?slug=${productSlugs[0]}`;
|
||||
const response = await fetch(url);
|
||||
await verifyImageResponse(response);
|
||||
}, 30000);
|
||||
|
||||
it(`should return 400 for product OG image without slug in ${locale}`, async () => {
|
||||
const url = `${BASE_URL}/${locale}/api/og/product`;
|
||||
const response = await fetch(url);
|
||||
expect(response.status).toBe(400);
|
||||
}, 30000);
|
||||
});
|
||||
|
||||
it('should generate blog OG image', async () => {
|
||||
const url = `${BASE_URL}/de/blog/opengraph-image`;
|
||||
const response = await fetch(url);
|
||||
await verifyImageResponse(response);
|
||||
}, 30000);
|
||||
});
|
||||
Reference in New Issue
Block a user