Skip to content

Commit 0e5f1cb

Browse files
authored
Merge pull request #4 from Jurrego1771/feature/test-player
Feature/test player
2 parents bcb34f8 + d429281 commit 0e5f1cb

File tree

15 files changed

+245
-138
lines changed

15 files changed

+245
-138
lines changed

fixtures/ad.fixture.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// fixtures/ad.fixture.js
2+
const base = require("@playwright/test");
3+
const { test } = require("./authRequest.fixture");
4+
5+
// Provee utilidades para crear Ads y un Ad temporal por defecto
6+
exports.test = test.extend({
7+
createAd: async ({ authRequest }, use) => {
8+
const createdIds = [];
9+
10+
async function createAd(overrides = {}) {
11+
const basePayload = {
12+
name: `qa_ad_${Date.now()}`,
13+
type: "vast",
14+
is_enabled: "false",
15+
preroll_skip_at: 0,
16+
min_media_time_length: 0,
17+
};
18+
19+
const form = { ...basePayload, ...overrides };
20+
const res = await authRequest.post("/api/ad/new", { form });
21+
const body = await res.json();
22+
if (!(res.ok() && body?.status === "OK")) {
23+
throw new Error(
24+
`createAd fallo: status=${res.status()} body=${JSON.stringify(body)}`
25+
);
26+
}
27+
const raw = body.data;
28+
const ad = Array.isArray(raw) ? raw[0] : raw;
29+
if (ad && ad._id) createdIds.push(ad._id);
30+
return { ad, res, body };
31+
}
32+
33+
await use(createAd);
34+
35+
for (const id of createdIds) {
36+
try {
37+
const delRes = await authRequest.delete(`/api/ad/${id}`);
38+
const delText = await delRes.text();
39+
console.log(
40+
`[ad.fixture] DELETE ${id} -> ${delRes.status()} ${delText}`
41+
);
42+
} catch (e) {
43+
console.log(`[ad.fixture] Error eliminando Ad ${id}:`, e);
44+
}
45+
}
46+
},
47+
48+
tempAd: async ({ createAd }, use) => {
49+
let ad = null;
50+
try {
51+
const result = await createAd();
52+
ad = result.ad;
53+
} catch (e) {
54+
console.log(`[ad.fixture] Error creando tempAd:`, e);
55+
}
56+
await use(ad);
57+
},
58+
});
59+
60+
exports.expect = base.expect;

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"description": "",
55
"main": "index.js",
66
"scripts": {
7-
"start-server": "http-server ./tests -p 3000",
87
"test": "playwright test",
98
"test:ui": "playwright test --ui",
109
"test:headed": "playwright test --headed",

playwright.config.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ module.exports = defineConfig({
66
timeout: 30_000,
77

88
use: {
9-
baseURL: process.env.BASE_URL,
9+
baseURL: process.env.BASE_URL, // solo API; sin fallback local a server
10+
headless: true,
11+
viewport: { width: 1280, height: 720 },
1012
},
1113

12-
// Configuración para reportes HTML
14+
// Sin servidor web local; solo pruebas de API/endpoint
15+
16+
// 🔹 Configuración de reportes
1317
reporter: [
1418
["list"], // salida en consola
15-
["json", { outputFile: "test-results/results.json" }], // 🧾 para Slack
16-
["html", { outputFolder: "playwright-report" }], // 🌐 para GitHub Pages
19+
["json", { outputFile: "test-results/results.json" }], // 🧾 útil para Slack o CI
20+
["html", { outputFolder: "playwright-report", open: "never" }], // 🌐 reporte para Pages
1721
],
18-
19-
reporter: [["html", { outputFolder: "playwright-report" }]],
2022
});

tests/ad/ad_create.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
const { test, expect } = require("../../fixtures/ad.fixture");
2+
3+
test.describe("💵 Ad - Creación )", () => {
4+
test("Crear Ad mínimo (name, type, flags)", async ({ tempAd }) => {
5+
expect(tempAd).toBeDefined();
6+
expect(tempAd).toHaveProperty("_id");
7+
expect(tempAd).toHaveProperty("name");
8+
expect(tempAd).toHaveProperty("type");
9+
expect([
10+
"vast",
11+
"vmap",
12+
"googleima",
13+
"local",
14+
"ad-insertion",
15+
"adswizz",
16+
]).toContain(tempAd.type);
17+
expect(tempAd).toHaveProperty("is_enabled");
18+
expect(tempAd).toHaveProperty("preroll_skip_at");
19+
expect(tempAd).toHaveProperty("min_media_time_length");
20+
21+
// Estructura opcional esperada
22+
expect(tempAd).toHaveProperty("schedule");
23+
expect(tempAd).toHaveProperty("adswizz");
24+
expect(tempAd).toHaveProperty("insertion");
25+
expect(tempAd).toHaveProperty("categories");
26+
expect(tempAd).toHaveProperty("tags");
27+
expect(tempAd).toHaveProperty("referers");
28+
});
29+
});

tests/ad/get_ad.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const { test, expect } = require("../../fixtures/ad.fixture");
2+
3+
test.describe("💵 Ad - GET )", () => {
4+
test("Obtener Ad por ID (200)", async ({ createAd, authRequest }) => {
5+
const { ad } = await createAd({
6+
name: `qa_ad_get_${Date.now()}`,
7+
type: "vast",
8+
is_enabled: "false",
9+
});
10+
11+
12+
const res = await authRequest.get(`/api/ad/${ad._id}`);
13+
const body = await res.json();
14+
15+
16+
expect(res.status()).toBe(200);
17+
expect(body.status).toBe("OK");
18+
expect(body.data).toBeDefined();
19+
expect(body.data._id).toBe(ad._id);
20+
});
21+
22+
test("ID inexistente devuelve 404", async ({ authRequest }) => {
23+
const nonExistingId = "5ee2704ea666e81cf291a085";
24+
const res = await authRequest.get(`/api/ad/${nonExistingId}`);
25+
const body = await res.json();
26+
27+
28+
expect(res.status()).toBe(404);
29+
expect(body.status).toBe("ERROR");
30+
expect(body.data).toBe("NOT_FOUND");
31+
});
32+
});

tests/ad/update_ad.test.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
const { test, expect } = require("../../fixtures/ad.fixture");
2+
3+
// Se usa createAd para crear un Ad inicial y luego se actualiza por ID
4+
5+
test.describe("💵 Ad - Update )", () => {
6+
test("Actualizar Ad existente (200)", async ({ createAd, authRequest }) => {
7+
const { ad } = await createAd({
8+
name: `qa_ad_update_${Date.now()}`,
9+
type: "vast",
10+
is_enabled: "false",
11+
preroll_skip_at: 0,
12+
min_media_time_length: 0,
13+
});
14+
15+
16+
const updatePayload = {
17+
name: `${ad.name}_updated`,
18+
is_enabled: "true",
19+
preroll_skip_at: 5,
20+
min_media_time_length: 0,
21+
};
22+
23+
const res = await authRequest.post(`/api/ad/${ad._id}`, {
24+
form: updatePayload,
25+
});
26+
const body = await res.json();
27+
28+
29+
expect(res.status()).toBe(200);
30+
expect(body.status).toBe("OK");
31+
expect(body.data._id).toBe(ad._id);
32+
expect(body.data.name).toBe(updatePayload.name);
33+
expect(body.data.is_enabled).toBeTruthy();
34+
expect(body.data.preroll_skip_at).toBe(updatePayload.preroll_skip_at);
35+
expect(body.data.min_media_time_length).toBe(
36+
updatePayload.min_media_time_length
37+
);
38+
});
39+
40+
test("min_media_time_length negativo se normaliza o devuelve 400", async ({
41+
createAd,
42+
authRequest,
43+
}) => {
44+
const { ad } = await createAd({ name: `qa_ad_update_${Date.now()}` });
45+
46+
47+
const badPayload = { min_media_time_length: -1 };
48+
const res = await authRequest.post(`/api/ad/${ad._id}`, {
49+
form: badPayload,
50+
});
51+
const body = await res.json();
52+
53+
54+
if (res.status() === 400) {
55+
expect(body.status).toBe("ERROR");
56+
expect(body.data).toMatchObject({ code: "AD_BAD_MIN_MEDIA_TIME" });
57+
} else {
58+
expect(res.status()).toBe(200);
59+
expect(body.status).toBe("OK");
60+
expect(body.data.min_media_time_length).toBeGreaterThanOrEqual(0);
61+
}
62+
});
63+
64+
test("ID inexistente devuelve 404", async ({ authRequest }) => {
65+
const nonExistingId = "5ee2704ea666e81cf291a085";
66+
const res = await authRequest.post(`/api/ad/${nonExistingId}`, {
67+
form: { name: "should_not_exist" },
68+
});
69+
const body = await res.json();
70+
71+
72+
expect(res.status()).toBe(404);
73+
expect(body.status).toBe("ERROR");
74+
expect(body.data).toBe("NOT_FOUND");
75+
});
76+
});

tests/cupones/create_coupon.test.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ let generatedCouponCodes = [];
88
let generatedCouponIds = [];
99
let allCoupons = [];
1010

11-
test.describe("🎫 Cupones API Tests - /api/coupon", () => {
11+
test.describe("🎫 Cupones ", () => {
1212
test.beforeAll(async ({ authRequest }) => {
1313
logger.info("🎫 Iniciando tests completos de API Cupones");
1414

@@ -58,7 +58,7 @@ test.describe("🎫 Cupones API Tests - /api/coupon", () => {
5858

5959
// ================== TESTS GET ==================
6060

61-
test("TC-001: GET /api/coupon - Verificar respuesta básica", async ({
61+
test("TC-001: Verificar respuesta básica", async ({
6262
authRequest,
6363
}) => {
6464
logger.info("🧪 Test: Verificar respuesta básica de cupones");
@@ -79,7 +79,7 @@ test.describe("🎫 Cupones API Tests - /api/coupon", () => {
7979
logger.info("✅ Respuesta básica verificada");
8080
});
8181

82-
test("TC-002: GET /api/coupon - Verificar filtro por custom_code", async ({
82+
test("TC-002: Verificar filtro por custom_code", async ({
8383
authRequest,
8484
coupon,
8585
}) => {
@@ -114,7 +114,7 @@ test.describe("🎫 Cupones API Tests - /api/coupon", () => {
114114
logger.info(`✅ Cupón encontrado por código: ${coupon.custom_code}`);
115115
});
116116

117-
test("TC-003: GET /api/coupon - Validar estructura de datos", async ({
117+
test("TC-003: Validar estructura de datos", async ({
118118
authRequest,
119119
}) => {
120120
logger.info("🧪 Test: Validar estructura de datos de cupones");
@@ -141,7 +141,7 @@ test.describe("🎫 Cupones API Tests - /api/coupon", () => {
141141
}
142142
});
143143

144-
test("TC-004: GET /api/coupon - Test de paginación", async ({
144+
test("TC-004: Test de paginación", async ({
145145
authRequest,
146146
}) => {
147147
logger.info("🧪 Test: Validar paginación de cupones");
@@ -160,7 +160,7 @@ test.describe("🎫 Cupones API Tests - /api/coupon", () => {
160160
logger.info("✅ Paginación validada");
161161
});
162162

163-
test("TC-005: GET /api/coupon - Test performance básico", async ({
163+
test("TC-005: Test performance básico", async ({
164164
authRequest,
165165
}) => {
166166
logger.info("🧪 Test: Performance básico");
@@ -180,7 +180,7 @@ test.describe("🎫 Cupones API Tests - /api/coupon", () => {
180180

181181
// ================== TESTS POST ==================
182182

183-
test("TC-006: POST /api/coupon - Crear cupón no reutilizable (is_reusable: false)", async ({
183+
test("TC-006: Crear cupón no reutilizable (is_reusable: false)", async ({
184184
authRequest,
185185
coupon,
186186
}) => {
@@ -246,7 +246,7 @@ test.describe("🎫 Cupones API Tests - /api/coupon", () => {
246246
}
247247
});
248248

249-
test("TC-007: POST /api/coupon - Crear cupón reutilizable con código personalizado", async ({
249+
test("TC-007: Crear cupón reutilizable con código personalizado", async ({
250250
authRequest,
251251
coupon,
252252
}) => {
@@ -307,7 +307,7 @@ test.describe("🎫 Cupones API Tests - /api/coupon", () => {
307307
}
308308
});
309309

310-
test("TC-008: POST /api/coupon - Error al crear cupón con código duplicado", async ({
310+
test("TC-008: Error al crear cupón con código duplicado", async ({
311311
authRequest,
312312
coupon,
313313
}) => {
@@ -373,7 +373,7 @@ test.describe("🎫 Cupones API Tests - /api/coupon", () => {
373373
logger.info(`✅ Error esperado al intentar duplicar código: ${body.data}`);
374374
});
375375

376-
test("TC-009: POST /api/coupon - Error con datos inválidos", async ({
376+
test("TC-009: Error con datos inválidos", async ({
377377
authRequest,
378378
}) => {
379379
logger.info("🧪 Test: Error con datos inválidos");
@@ -416,7 +416,7 @@ test.describe("🎫 Cupones API Tests - /api/coupon", () => {
416416

417417
// ================== TESTS INDIVIDUALES ==================
418418

419-
test("TC-010: GET /api/coupon/{coupon_id} - Obtener cupón por ID", async ({
419+
test("TC-010: Obtener cupón por ID", async ({
420420
authRequest,
421421
coupon,
422422
}) => {
@@ -442,7 +442,7 @@ test.describe("🎫 Cupones API Tests - /api/coupon", () => {
442442
logger.info(`✅ Cupón obtenido: ${retrievedCoupon.code}`);
443443
});
444444

445-
test("TC-011: GET /api/coupon/{coupon_code}/search - Buscar cupón por código", async ({
445+
test("TC-011: G Buscar cupón por código", async ({
446446
authRequest,
447447
coupon,
448448
}) => {
@@ -461,7 +461,7 @@ test.describe("🎫 Cupones API Tests - /api/coupon", () => {
461461
logger.info(`✅ Cupón encontrado por código: ${couponCode}`);
462462
});
463463

464-
test("TC-012: DELETE /api/coupon/{coupon_id} - Crear y eliminar cupón temporal", async ({
464+
test("TC-012: Crear y eliminar cupón temporal", async ({
465465
authRequest,
466466
coupon,
467467
}) => {
@@ -529,7 +529,7 @@ test.describe("🎫 Cupones API Tests - /api/coupon", () => {
529529
);
530530
});
531531

532-
test("TC-013: GET /api/coupon/{coupon_id} - Error para cupón inexistente", async ({
532+
test("TC-013: Error para cupón inexistente", async ({
533533
authRequest,
534534
}) => {
535535
logger.info("🧪 Test: Error para cupón inexistente");

0 commit comments

Comments
 (0)