72 lines
2.6 KiB
JavaScript
72 lines
2.6 KiB
JavaScript
const request = require('supertest');
|
|
const express = require('express');
|
|
const helmet = require('helmet');
|
|
const tagRouter = require('../src/api/tag');
|
|
|
|
const app = express();
|
|
app.use(helmet({ crossOriginResourcePolicy: false }));
|
|
app.use(tagRouter);
|
|
|
|
describe('GET /tag', () => {
|
|
it('should return SVG with default params', async () => {
|
|
const res = await request(app).get('/tag');
|
|
const resBody = Buffer.from(res.body).toString();
|
|
expect(res.statusCode).toBe(200);
|
|
expect(res.headers['content-type']).toMatch(/image\/svg\+xml/);
|
|
expect(resBody).toContain('<svg');
|
|
expect(resBody).toContain('<rect');
|
|
expect(resBody).toContain('badgedex');
|
|
expect(resBody).toContain('BADGEDEX');
|
|
});
|
|
|
|
it('should use custom tag and label', async () => {
|
|
const res = await request(app).get('/tag?tag=test&label=Teszt');
|
|
const resBody = Buffer.from(res.body).toString();
|
|
expect(res.statusCode).toBe(200);
|
|
expect(resBody).toContain('test');
|
|
expect(resBody).toContain('TESZT');
|
|
});
|
|
|
|
it('should set tag background to transparent', async () => {
|
|
const res = await request(app).get('/tag?bgtag=none');
|
|
const resBody = Buffer.from(res.body).toString();
|
|
expect(res.statusCode).toBe(200);
|
|
expect(resBody).toContain('fill="none"');
|
|
});
|
|
|
|
it('should set label background to transparent', async () => {
|
|
const res = await request(app).get('/tag?bglabel=none');
|
|
const resBody = Buffer.from(res.body).toString();
|
|
expect(res.statusCode).toBe(200);
|
|
expect(resBody).toContain('fill="none"');
|
|
});
|
|
|
|
it('should use flat style', async () => {
|
|
const res = await request(app).get('/tag?style=flat');
|
|
const resBody = Buffer.from(res.body).toString();
|
|
expect(res.statusCode).toBe(200);
|
|
expect(resBody).toContain('<linearGradient');
|
|
expect(resBody).toContain('<clipPath');
|
|
});
|
|
|
|
it('should handle custom fontweight', async () => {
|
|
const res = await request(app).get('/tag?fontweight=bold');
|
|
const resBody = Buffer.from(res.body).toString();
|
|
expect(res.statusCode).toBe(200);
|
|
expect(resBody).toContain('font-weight="bold"');
|
|
});
|
|
|
|
it('should handle custom color', async () => {
|
|
const res = await request(app).get('/tag?color=%23ff0000');
|
|
const resBody = Buffer.from(res.body).toString();
|
|
expect(res.statusCode).toBe(200);
|
|
expect(resBody).toContain('fill="#ff0000"');
|
|
});
|
|
|
|
it('should handle custom size', async () => {
|
|
const res = await request(app).get('/tag?size=48');
|
|
const resBody = Buffer.from(res.body).toString();
|
|
expect(res.statusCode).toBe(200);
|
|
expect(resBody).toContain('height="48"');
|
|
});
|
|
}); |