Skip to content

Commit 423362d

Browse files
committed
feat(dataFactory): add show generation methods and update test scripts
- Introduced new methods in DataFactory for generating show payloads, including generateShowPayload, generateShowMinimalPayload, and generateShowFullPayload. - Added a new test script command for shows in package.json.
1 parent 6f08782 commit 423362d

File tree

5 files changed

+754
-53
lines changed

5 files changed

+754
-53
lines changed

fixtures/show.fixture.js

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/**
2+
* Fixture personalizada para tests del módulo Show
3+
* Configura X-API-TOKEN (mayúsculas) solo para endpoints de Show
4+
*/
5+
6+
const baseTest = require("@playwright/test");
7+
require("dotenv").config();
8+
const { faker } = require("@faker-js/faker");
9+
10+
const createShow = async (authRequest, attrs = {}) => {
11+
const payload = {
12+
title: `[QA-AUTO] Show ${faker.string.alphanumeric(6)} ${Date.now()}`,
13+
type: "tvshow",
14+
account: process.env.ACCOUNT_ID || "test-account",
15+
...attrs,
16+
};
17+
18+
const res = await authRequest.post("/api/show", { form: payload });
19+
if (!res.ok()) {
20+
const txt = await res.text().catch(() => "");
21+
throw new Error(`createShow failed: ${res.status()} ${txt}`);
22+
}
23+
24+
const body = await res.json();
25+
// API returns: { data: show } | { status, data } | show at root | array
26+
const raw = body?.data ?? body;
27+
return Array.isArray(raw) ? raw[0] : raw;
28+
};
29+
30+
const deleteShow = async (authRequest, showId) => {
31+
try {
32+
const res = await authRequest.delete(`/api/show/${showId}`);
33+
return res.ok();
34+
} catch (err) {
35+
console.error(`Error deleting show ${showId}:`, err.message);
36+
return false;
37+
}
38+
};
39+
40+
exports.test = baseTest.test.extend({
41+
// -- authRequest con X-API-TOKEN (solo para Show) --
42+
authRequest: async ({ playwright }, use) => {
43+
const context = await playwright.request.newContext({
44+
baseURL: process.env.BASE_URL,
45+
extraHTTPHeaders: {
46+
"X-API-Token": process.env.API_TOKEN,
47+
},
48+
});
49+
50+
await use(context);
51+
await context.dispose();
52+
},
53+
54+
// -- Información de contexto --
55+
accountId: async ({}, use) => {
56+
const accountId = process.env.ACCOUNT_ID || "test-account-id";
57+
await use(accountId);
58+
},
59+
60+
tempShow: async ({ authRequest }, use) => {
61+
const show = await createShow(authRequest, {
62+
type: "tvshow",
63+
is_published: "true",
64+
});
65+
66+
await use(show);
67+
68+
// Cleanup
69+
await deleteShow(authRequest, show._id);
70+
},
71+
72+
// -- Show para ser eliminado en el test --
73+
tempShowForDelete: async ({ authRequest }, use) => {
74+
const show = await createShow(authRequest, {
75+
type: "radioshow",
76+
});
77+
78+
await use(show);
79+
80+
// Intenta limpiar en caso de que el test no lo elimine completamente
81+
try {
82+
await deleteShow(authRequest, show._id);
83+
} catch (err) {
84+
// Ignore
85+
}
86+
},
87+
88+
// -- Usuario restringido para pruebas de control de acceso --
89+
restrictedUser: async ({}, use) => {
90+
const restrictedUserId =
91+
process.env.RESTRICTED_USER_ID || "restricted-user-123";
92+
await use(restrictedUserId);
93+
},
94+
95+
// -- Múltiples shows para pruebas de Search --
96+
tempShowsBatch: async ({ authRequest }, use) => {
97+
const shows = [];
98+
const types = ["tvshow", "radioshow", "podcast"];
99+
for (let i = 0; i < 3; i++) {
100+
const show = await createShow(authRequest, {
101+
title: `[QA-AUTO] Batch Show ${i} ${Date.now()}`,
102+
type: types[i % types.length],
103+
is_published: i === 0 ? "true" : "false",
104+
});
105+
shows.push(show);
106+
}
107+
108+
await use(shows);
109+
110+
// Cleanup
111+
for (const show of shows) {
112+
await deleteShow(authRequest, show._id);
113+
}
114+
},
115+
});
116+
117+
exports.expect = baseTest.expect;
118+
119+
module.exports = exports;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"test:report": "playwright show-report",
1111
"test:media": "playwright test tests/media/",
1212
"test:live": "playwright test tests/live/",
13+
"test:show": "playwright test tests/show/",
1314
"test:debug": "playwright test --debug",
1415
"install:browsers": "playwright install",
1516
"notify:slack": "node notify-slack.js"

schemas/show.schema.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Esquemas Zod para validación de respuestas del módulo Show
3+
* Nota: La API retorna el objeto Show directamente, no envuelto en {status, data}
4+
*/
5+
6+
const { z } = require("zod");
7+
8+
// -- Schema base para un Show --
9+
const showSchema = z
10+
.object({
11+
_id: z.string(),
12+
account: z.string().optional(),
13+
title: z.string(),
14+
version: z.string().optional(),
15+
description: z.string().optional(),
16+
type: z.enum(["tvshow", "radioshow", "podcast", "movie", "mixed"]),
17+
genres: z.array(z.string()).optional(),
18+
iab_genres: z.array(z.string()).optional(),
19+
is_published: z.union([z.boolean(), z.string()]).optional(),
20+
first_emision: z.string().optional(),
21+
next_episode: z.union([z.number(), z.string()]).optional(),
22+
status: z.string().optional(),
23+
date_created: z.string().optional(),
24+
date_updated: z.string().optional(),
25+
distributors: z.array(z.unknown()).optional(),
26+
producers: z.array(z.unknown()).optional(),
27+
featuring: z.array(z.unknown()).optional(),
28+
hosts: z.array(z.unknown()).optional(),
29+
ads: z.array(z.unknown()).optional(),
30+
ad_map_url: z.string().optional(),
31+
rss: z.object({}).passthrough().optional(),
32+
gracenote: z.object({}).passthrough().optional(),
33+
})
34+
.passthrough();
35+
36+
module.exports = {
37+
showSchema,
38+
};

0 commit comments

Comments
 (0)