@raketa-cloud/admin 1.7.4 → 1.7.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/application.css +23 -0
- package/package.json +3 -3
- package/src/HonoAdapter.js +7 -3
- package/src/cloud/Articles.js +10 -3
- package/src/cloud/Events.js +9 -2
- package/src/cloud/Pages.js +13 -1
- package/src/cloud/documents/articlesDocuments.js +4 -2
- package/src/cloud/documents/eventsDocuments.js +4 -2
- package/src/cloud/documents/pagesDocuments.js +4 -2
- package/src/handlers/_shared/SettingsHandler.js +4 -0
- package/src/handlers/articles/ArticlesHandler.js +10 -4
- package/src/handlers/articles/ExportsHandler.js +35 -0
- package/src/handlers/events/EventsHandler.js +10 -4
- package/src/handlers/events/ExportsHandler.js +35 -0
- package/src/handlers/pages/ExportsHandler.js +35 -0
- package/src/handlers/pages/PagesHandler.js +10 -4
- package/src/helpers/CSVExportHelper.js +103 -0
- package/src/routeArticlesModule.js +13 -0
- package/src/routeEventsModule.js +13 -0
- package/src/routePagesModule.js +13 -0
- package/src/routeSettings.js +4 -0
- package/src/tests/RaketaClient.test.js +636 -0
- package/src/tests/handlers/articles/ArticlesHandler.test/index.test.js +18 -2
- package/src/tests/handlers/articles/ExportsHandler.test/index.test.js +217 -0
- package/src/tests/handlers/events/EventsHandler.test/index.test.js +17 -1
- package/src/tests/handlers/events/ExportsHandler.test/index.test.js +212 -0
- package/src/tests/handlers/pages/ExportsHandler.test/index.test.js +212 -0
- package/src/tests/handlers/pages/PagesHandler.test/index.test.js +17 -1
- package/src/tests/helpers/CSVExportHelper.test.js +364 -0
- package/src/views/articles/_shared/_export_button.ejs +9 -0
- package/src/views/articles/index.ejs +37 -1
- package/src/views/events/_shared/_export_button.ejs +9 -0
- package/src/views/events/index.ejs +37 -1
- package/src/views/layouts/application.ejs +2 -0
- package/src/views/pages/_shared/_export_button.ejs +9 -0
- package/src/views/pages/index.ejs +37 -1
- package/src/views/settings/_nav.ejs +7 -1
- package/src/views/settings/variables/edit_form.ejs +178 -0
|
@@ -6,9 +6,20 @@ import Factory from "../../../support/factory";
|
|
|
6
6
|
|
|
7
7
|
describe("Articles Handler", () => {
|
|
8
8
|
function buildCtx() {
|
|
9
|
+
const mockArticles = new Articles(() => ({}), "token");
|
|
10
|
+
mockArticles.getConfig = jest.fn().mockReturnValue({
|
|
11
|
+
i18n: {
|
|
12
|
+
locales: {
|
|
13
|
+
en: { name: "English", code: "en-gb" },
|
|
14
|
+
es: { name: "Spanish", code: "es" },
|
|
15
|
+
fr: { name: "French", code: "fr" },
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
|
|
9
20
|
return {
|
|
10
21
|
client: {
|
|
11
|
-
articles:
|
|
22
|
+
articles: mockArticles,
|
|
12
23
|
tags: new Tags(() => ({}), "token"),
|
|
13
24
|
},
|
|
14
25
|
query: { foo: "bar" },
|
|
@@ -39,7 +50,7 @@ describe("Articles Handler", () => {
|
|
|
39
50
|
expect(mockedArticleList).toHaveBeenCalledWith(
|
|
40
51
|
{ foo: "bar" },
|
|
41
52
|
"en",
|
|
42
|
-
"article"
|
|
53
|
+
"article",
|
|
43
54
|
);
|
|
44
55
|
expect(mockedTagList).toHaveBeenCalledWith("en");
|
|
45
56
|
|
|
@@ -49,6 +60,11 @@ describe("Articles Handler", () => {
|
|
|
49
60
|
list: [article],
|
|
50
61
|
pagination: pagination,
|
|
51
62
|
},
|
|
63
|
+
translations: [
|
|
64
|
+
{ name: "English", code: "en" },
|
|
65
|
+
{ name: "Spanish", code: "es" },
|
|
66
|
+
{ name: "French", code: "fr" },
|
|
67
|
+
],
|
|
52
68
|
tags: tags,
|
|
53
69
|
visibilityOptions: ctx.client.articles.visibilityOptions(),
|
|
54
70
|
},
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import ExportsHandler from "../../../../handlers/articles/ExportsHandler";
|
|
2
|
+
import Articles from "../../../../cloud/Articles";
|
|
3
|
+
|
|
4
|
+
describe("Articles ExportsHandler", () => {
|
|
5
|
+
function buildCtx(query = {}) {
|
|
6
|
+
return {
|
|
7
|
+
params: {},
|
|
8
|
+
query: query,
|
|
9
|
+
client: {
|
|
10
|
+
articles: new Articles(() => ({}), "token"),
|
|
11
|
+
},
|
|
12
|
+
resourceConfig: {
|
|
13
|
+
articleType: "article",
|
|
14
|
+
},
|
|
15
|
+
remoteConfig: {
|
|
16
|
+
resourceUrl: (item) => item.slug,
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
describe("index (exportCSV)", () => {
|
|
22
|
+
test("exports articles to CSV with default locale", async () => {
|
|
23
|
+
const mockArticles = [
|
|
24
|
+
{
|
|
25
|
+
id: 1,
|
|
26
|
+
title: "Article 1",
|
|
27
|
+
slug: "/article-1",
|
|
28
|
+
visibility: "public",
|
|
29
|
+
insertedAt: "2024-01-01",
|
|
30
|
+
updatedAt: "2024-01-02",
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
id: 2,
|
|
34
|
+
title: "Article 2",
|
|
35
|
+
slug: "/article-2",
|
|
36
|
+
visibility: "private",
|
|
37
|
+
insertedAt: "2024-01-03",
|
|
38
|
+
updatedAt: "2024-01-04",
|
|
39
|
+
},
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
const ctx = buildCtx({});
|
|
43
|
+
|
|
44
|
+
const mockedlistAll = jest
|
|
45
|
+
.spyOn(ctx.client.articles, "listAll")
|
|
46
|
+
.mockImplementation(() => ({ list: mockArticles }));
|
|
47
|
+
|
|
48
|
+
const mockDate = new Date("2024-08-30T10:30:00");
|
|
49
|
+
jest.spyOn(global, "Date").mockImplementation(() => mockDate);
|
|
50
|
+
|
|
51
|
+
const result = await ExportsHandler.index(ctx);
|
|
52
|
+
|
|
53
|
+
expect(mockedlistAll).toHaveBeenCalledWith({}, "en", "article");
|
|
54
|
+
|
|
55
|
+
expect(result.text).toContain(
|
|
56
|
+
"id,type,locale,title,URL,visibility,created_at,updated_at",
|
|
57
|
+
);
|
|
58
|
+
expect(result.text).toContain(
|
|
59
|
+
"1,article,en,Article 1,/article-1,public,2024-01-01,2024-01-02",
|
|
60
|
+
);
|
|
61
|
+
expect(result.text).toContain(
|
|
62
|
+
"2,article,en,Article 2,/article-2,private,2024-01-03,2024-01-04",
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
expect(result.headers).toEqual({
|
|
66
|
+
"Content-Type": "text/csv",
|
|
67
|
+
"Content-Disposition":
|
|
68
|
+
'attachment; filename="300824_article_export.csv"',
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
global.Date.mockRestore();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test("exports articles to CSV with specified locale", async () => {
|
|
75
|
+
const mockArticles = [
|
|
76
|
+
{
|
|
77
|
+
id: 1,
|
|
78
|
+
title: "Artículo 1",
|
|
79
|
+
slug: "/articulo-1",
|
|
80
|
+
visibility: "public",
|
|
81
|
+
insertedAt: "2024-01-01",
|
|
82
|
+
updatedAt: "2024-01-02",
|
|
83
|
+
},
|
|
84
|
+
];
|
|
85
|
+
|
|
86
|
+
const ctx = buildCtx({ locale: "es" });
|
|
87
|
+
|
|
88
|
+
const mockedlistAll = jest
|
|
89
|
+
.spyOn(ctx.client.articles, "listAll")
|
|
90
|
+
.mockImplementation(() => ({ list: mockArticles }));
|
|
91
|
+
|
|
92
|
+
const result = await ExportsHandler.index(ctx);
|
|
93
|
+
|
|
94
|
+
expect(mockedlistAll).toHaveBeenCalledWith(
|
|
95
|
+
{ locale: "es" },
|
|
96
|
+
"es",
|
|
97
|
+
"article",
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
expect(result.text).toContain(
|
|
101
|
+
"1,article,es,Artículo 1,/articulo-1,public,2024-01-01,2024-01-02",
|
|
102
|
+
);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("exports articles with CSV special characters properly escaped", async () => {
|
|
106
|
+
const mockArticles = [
|
|
107
|
+
{
|
|
108
|
+
id: 1,
|
|
109
|
+
title: 'Article with, comma and "quotes"',
|
|
110
|
+
slug: "/article-1",
|
|
111
|
+
visibility: "public",
|
|
112
|
+
insertedAt: "2024-01-01",
|
|
113
|
+
updatedAt: "2024-01-02",
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
id: 2,
|
|
117
|
+
title: "Article with\nnewline",
|
|
118
|
+
slug: "/article-2",
|
|
119
|
+
visibility: "private",
|
|
120
|
+
insertedAt: "2024-01-03",
|
|
121
|
+
updatedAt: "2024-01-04",
|
|
122
|
+
},
|
|
123
|
+
];
|
|
124
|
+
|
|
125
|
+
const ctx = buildCtx({});
|
|
126
|
+
|
|
127
|
+
jest
|
|
128
|
+
.spyOn(ctx.client.articles, "listAll")
|
|
129
|
+
.mockImplementation(() => ({ list: mockArticles }));
|
|
130
|
+
|
|
131
|
+
const result = await ExportsHandler.index(ctx);
|
|
132
|
+
|
|
133
|
+
expect(result.text).toContain('"Article with, comma and ""quotes"""');
|
|
134
|
+
expect(result.text).toContain('"Article with\nnewline"');
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test("exports empty list when no articles found", async () => {
|
|
138
|
+
const ctx = buildCtx({});
|
|
139
|
+
|
|
140
|
+
jest
|
|
141
|
+
.spyOn(ctx.client.articles, "listAll")
|
|
142
|
+
.mockImplementation(() => ({ list: [] }));
|
|
143
|
+
|
|
144
|
+
const result = await ExportsHandler.index(ctx);
|
|
145
|
+
|
|
146
|
+
expect(result.text).toBe(
|
|
147
|
+
"id,type,locale,title,URL,visibility,created_at,updated_at",
|
|
148
|
+
);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test("passes query parameters to listAll", async () => {
|
|
152
|
+
const query = {
|
|
153
|
+
search: "test",
|
|
154
|
+
visibility: "public",
|
|
155
|
+
locale: "en",
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const ctx = buildCtx(query);
|
|
159
|
+
|
|
160
|
+
const mockedlistAll = jest
|
|
161
|
+
.spyOn(ctx.client.articles, "listAll")
|
|
162
|
+
.mockImplementation(() => ({ list: [] }));
|
|
163
|
+
|
|
164
|
+
await ExportsHandler.index(ctx);
|
|
165
|
+
|
|
166
|
+
expect(mockedlistAll).toHaveBeenCalledWith(query, "en", "article");
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test("uses articleType from resourceConfig", async () => {
|
|
170
|
+
const ctx = buildCtx({});
|
|
171
|
+
ctx.resourceConfig.articleType = "custom-article-type";
|
|
172
|
+
|
|
173
|
+
const mockedlistAll = jest
|
|
174
|
+
.spyOn(ctx.client.articles, "listAll")
|
|
175
|
+
.mockImplementation(() => ({ list: [] }));
|
|
176
|
+
|
|
177
|
+
const mockDate = new Date("2024-08-30T10:30:00");
|
|
178
|
+
jest.spyOn(global, "Date").mockImplementation(() => mockDate);
|
|
179
|
+
|
|
180
|
+
const result = await ExportsHandler.index(ctx);
|
|
181
|
+
|
|
182
|
+
expect(mockedlistAll).toHaveBeenCalledWith(
|
|
183
|
+
{},
|
|
184
|
+
"en",
|
|
185
|
+
"custom-article-type",
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
expect(result.headers["Content-Disposition"]).toContain(
|
|
189
|
+
"custom-article-type_export.csv",
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
global.Date.mockRestore();
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test("exports all results without pagination", async () => {
|
|
196
|
+
const mockArticles = Array.from({ length: 150 }, (_, i) => ({
|
|
197
|
+
id: i + 1,
|
|
198
|
+
title: `Article ${i + 1}`,
|
|
199
|
+
slug: `/article-${i + 1}`,
|
|
200
|
+
visibility: "public",
|
|
201
|
+
insertedAt: "2024-01-01",
|
|
202
|
+
updatedAt: "2024-01-02",
|
|
203
|
+
}));
|
|
204
|
+
|
|
205
|
+
const ctx = buildCtx({});
|
|
206
|
+
|
|
207
|
+
jest
|
|
208
|
+
.spyOn(ctx.client.articles, "listAll")
|
|
209
|
+
.mockImplementation(() => ({ list: mockArticles }));
|
|
210
|
+
|
|
211
|
+
const result = await ExportsHandler.index(ctx);
|
|
212
|
+
|
|
213
|
+
const lines = result.text.split("\r\n");
|
|
214
|
+
expect(lines.length).toBe(151);
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
});
|
|
@@ -6,9 +6,20 @@ import Factory from "../../../support/factory";
|
|
|
6
6
|
|
|
7
7
|
describe("Events Handler", () => {
|
|
8
8
|
function buildCtx() {
|
|
9
|
+
const mockEvents = new Events(() => ({}), "token");
|
|
10
|
+
mockEvents.getConfig = jest.fn().mockReturnValue({
|
|
11
|
+
i18n: {
|
|
12
|
+
locales: {
|
|
13
|
+
en: { name: "English", code: "en-gb" },
|
|
14
|
+
es: { name: "Spanish", code: "es" },
|
|
15
|
+
fr: { name: "French", code: "fr" },
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
|
|
9
20
|
return {
|
|
10
21
|
client: {
|
|
11
|
-
events:
|
|
22
|
+
events: mockEvents,
|
|
12
23
|
tags: new Tags(() => ({}), "token"),
|
|
13
24
|
},
|
|
14
25
|
query: { foo: "bar" },
|
|
@@ -45,6 +56,11 @@ describe("Events Handler", () => {
|
|
|
45
56
|
list: [event],
|
|
46
57
|
pagination: pagination,
|
|
47
58
|
},
|
|
59
|
+
translations: [
|
|
60
|
+
{ name: "English", code: "en" },
|
|
61
|
+
{ name: "Spanish", code: "es" },
|
|
62
|
+
{ name: "French", code: "fr" },
|
|
63
|
+
],
|
|
48
64
|
tags: tags,
|
|
49
65
|
visibilityOptions: ctx.client.events.visibilityOptions(),
|
|
50
66
|
},
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import ExportsHandler from "../../../../handlers/events/ExportsHandler";
|
|
2
|
+
import Events from "../../../../cloud/Events";
|
|
3
|
+
|
|
4
|
+
describe("Events ExportsHandler", () => {
|
|
5
|
+
function buildCtx(query = {}) {
|
|
6
|
+
return {
|
|
7
|
+
params: {},
|
|
8
|
+
query: query,
|
|
9
|
+
client: {
|
|
10
|
+
events: new Events(() => ({}), "token"),
|
|
11
|
+
},
|
|
12
|
+
resourceConfig: {
|
|
13
|
+
eventType: "event",
|
|
14
|
+
},
|
|
15
|
+
remoteConfig: {
|
|
16
|
+
resourceUrl: (item) => item.slug,
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
describe("index (exportCSV)", () => {
|
|
22
|
+
test("exports events to CSV with default locale", async () => {
|
|
23
|
+
const mockEvents = [
|
|
24
|
+
{
|
|
25
|
+
id: 1,
|
|
26
|
+
title: "Event 1",
|
|
27
|
+
slug: "/event-1",
|
|
28
|
+
visibility: "public",
|
|
29
|
+
insertedAt: "2024-01-01",
|
|
30
|
+
updatedAt: "2024-01-02",
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
id: 2,
|
|
34
|
+
title: "Event 2",
|
|
35
|
+
slug: "/event-2",
|
|
36
|
+
visibility: "private",
|
|
37
|
+
insertedAt: "2024-01-03",
|
|
38
|
+
updatedAt: "2024-01-04",
|
|
39
|
+
},
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
const ctx = buildCtx({});
|
|
43
|
+
|
|
44
|
+
const mockedlistAll = jest
|
|
45
|
+
.spyOn(ctx.client.events, "listAll")
|
|
46
|
+
.mockImplementation(() => ({ list: mockEvents }));
|
|
47
|
+
|
|
48
|
+
const mockDate = new Date("2024-08-30T10:30:00");
|
|
49
|
+
jest.spyOn(global, "Date").mockImplementation(() => mockDate);
|
|
50
|
+
|
|
51
|
+
const result = await ExportsHandler.index(ctx);
|
|
52
|
+
|
|
53
|
+
expect(mockedlistAll).toHaveBeenCalledWith({}, "en", "event");
|
|
54
|
+
|
|
55
|
+
expect(result.text).toContain(
|
|
56
|
+
"id,type,locale,title,URL,visibility,created_at,updated_at",
|
|
57
|
+
);
|
|
58
|
+
expect(result.text).toContain(
|
|
59
|
+
"1,event,en,Event 1,/event-1,public,2024-01-01,2024-01-02",
|
|
60
|
+
);
|
|
61
|
+
expect(result.text).toContain(
|
|
62
|
+
"2,event,en,Event 2,/event-2,private,2024-01-03,2024-01-04",
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
expect(result.headers).toEqual({
|
|
66
|
+
"Content-Type": "text/csv",
|
|
67
|
+
"Content-Disposition": 'attachment; filename="300824_event_export.csv"',
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
global.Date.mockRestore();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("exports events to CSV with specified locale", async () => {
|
|
74
|
+
const mockEvents = [
|
|
75
|
+
{
|
|
76
|
+
id: 1,
|
|
77
|
+
title: "Evento 1",
|
|
78
|
+
slug: "/evento-1",
|
|
79
|
+
visibility: "public",
|
|
80
|
+
insertedAt: "2024-01-01",
|
|
81
|
+
updatedAt: "2024-01-02",
|
|
82
|
+
},
|
|
83
|
+
];
|
|
84
|
+
|
|
85
|
+
const ctx = buildCtx({ locale: "es" });
|
|
86
|
+
|
|
87
|
+
const mockedlistAll = jest
|
|
88
|
+
.spyOn(ctx.client.events, "listAll")
|
|
89
|
+
.mockImplementation(() => ({ list: mockEvents }));
|
|
90
|
+
|
|
91
|
+
const result = await ExportsHandler.index(ctx);
|
|
92
|
+
|
|
93
|
+
expect(mockedlistAll).toHaveBeenCalledWith(
|
|
94
|
+
{ locale: "es" },
|
|
95
|
+
"es",
|
|
96
|
+
"event",
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
expect(result.text).toContain(
|
|
100
|
+
"1,event,es,Evento 1,/evento-1,public,2024-01-01,2024-01-02",
|
|
101
|
+
);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("exports events with CSV special characters properly escaped", async () => {
|
|
105
|
+
const mockEvents = [
|
|
106
|
+
{
|
|
107
|
+
id: 1,
|
|
108
|
+
title: 'Event with, comma and "quotes"',
|
|
109
|
+
slug: "/event-1",
|
|
110
|
+
visibility: "public",
|
|
111
|
+
insertedAt: "2024-01-01",
|
|
112
|
+
updatedAt: "2024-01-02",
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
id: 2,
|
|
116
|
+
title: "Event with\nnewline",
|
|
117
|
+
slug: "/event-2",
|
|
118
|
+
visibility: "private",
|
|
119
|
+
insertedAt: "2024-01-03",
|
|
120
|
+
updatedAt: "2024-01-04",
|
|
121
|
+
},
|
|
122
|
+
];
|
|
123
|
+
|
|
124
|
+
const ctx = buildCtx({});
|
|
125
|
+
|
|
126
|
+
jest
|
|
127
|
+
.spyOn(ctx.client.events, "listAll")
|
|
128
|
+
.mockImplementation(() => ({ list: mockEvents }));
|
|
129
|
+
|
|
130
|
+
const result = await ExportsHandler.index(ctx);
|
|
131
|
+
|
|
132
|
+
expect(result.text).toContain('"Event with, comma and ""quotes"""');
|
|
133
|
+
expect(result.text).toContain('"Event with\nnewline"');
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
test("exports empty list when no events found", async () => {
|
|
137
|
+
const ctx = buildCtx({});
|
|
138
|
+
|
|
139
|
+
jest
|
|
140
|
+
.spyOn(ctx.client.events, "listAll")
|
|
141
|
+
.mockImplementation(() => ({ list: [] }));
|
|
142
|
+
|
|
143
|
+
const result = await ExportsHandler.index(ctx);
|
|
144
|
+
|
|
145
|
+
expect(result.text).toBe(
|
|
146
|
+
"id,type,locale,title,URL,visibility,created_at,updated_at",
|
|
147
|
+
);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test("passes query parameters to listAll", async () => {
|
|
151
|
+
const query = {
|
|
152
|
+
search: "test",
|
|
153
|
+
visibility: "public",
|
|
154
|
+
locale: "en",
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const ctx = buildCtx(query);
|
|
158
|
+
|
|
159
|
+
const mockedlistAll = jest
|
|
160
|
+
.spyOn(ctx.client.events, "listAll")
|
|
161
|
+
.mockImplementation(() => ({ list: [] }));
|
|
162
|
+
|
|
163
|
+
await ExportsHandler.index(ctx);
|
|
164
|
+
|
|
165
|
+
expect(mockedlistAll).toHaveBeenCalledWith(query, "en", "event");
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test("uses eventType from resourceConfig", async () => {
|
|
169
|
+
const ctx = buildCtx({});
|
|
170
|
+
ctx.resourceConfig.eventType = "custom-event-type";
|
|
171
|
+
|
|
172
|
+
const mockedlistAll = jest
|
|
173
|
+
.spyOn(ctx.client.events, "listAll")
|
|
174
|
+
.mockImplementation(() => ({ list: [] }));
|
|
175
|
+
|
|
176
|
+
const mockDate = new Date("2024-08-30T10:30:00");
|
|
177
|
+
jest.spyOn(global, "Date").mockImplementation(() => mockDate);
|
|
178
|
+
|
|
179
|
+
const result = await ExportsHandler.index(ctx);
|
|
180
|
+
|
|
181
|
+
expect(mockedlistAll).toHaveBeenCalledWith({}, "en", "custom-event-type");
|
|
182
|
+
|
|
183
|
+
expect(result.headers["Content-Disposition"]).toContain(
|
|
184
|
+
"custom-event-type_export.csv",
|
|
185
|
+
);
|
|
186
|
+
|
|
187
|
+
global.Date.mockRestore();
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
test("exports all results without pagination", async () => {
|
|
191
|
+
const mockEvents = Array.from({ length: 150 }, (_, i) => ({
|
|
192
|
+
id: i + 1,
|
|
193
|
+
title: `Event ${i + 1}`,
|
|
194
|
+
slug: `/event-${i + 1}`,
|
|
195
|
+
visibility: "public",
|
|
196
|
+
insertedAt: "2024-01-01",
|
|
197
|
+
updatedAt: "2024-01-02",
|
|
198
|
+
}));
|
|
199
|
+
|
|
200
|
+
const ctx = buildCtx({});
|
|
201
|
+
|
|
202
|
+
jest
|
|
203
|
+
.spyOn(ctx.client.events, "listAll")
|
|
204
|
+
.mockImplementation(() => ({ list: mockEvents }));
|
|
205
|
+
|
|
206
|
+
const result = await ExportsHandler.index(ctx);
|
|
207
|
+
|
|
208
|
+
const lines = result.text.split("\r\n");
|
|
209
|
+
expect(lines.length).toBe(151);
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
});
|