From f40a834c8c692872a48d4c4aa952113fa1c5385d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mih=C3=A1ly=20Andr=C3=A1s=20T=C3=B3th?= Date: Thu, 17 Jul 2025 10:42:40 +0200 Subject: [PATCH] rename api.test and add tag test --- test/{api.test.js => badge.api.test.js} | 0 test/tag.api.test.js | 72 +++++++++++++++++++++++++ 2 files changed, 72 insertions(+) rename test/{api.test.js => badge.api.test.js} (100%) create mode 100644 test/tag.api.test.js diff --git a/test/api.test.js b/test/badge.api.test.js similarity index 100% rename from test/api.test.js rename to test/badge.api.test.js diff --git a/test/tag.api.test.js b/test/tag.api.test.js new file mode 100644 index 0000000..30e6958 --- /dev/null +++ b/test/tag.api.test.js @@ -0,0 +1,72 @@ +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(' { + 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(' { + 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"'); + }); +}); \ No newline at end of file