@raketa-cloud/admin 0.0.7 → 0.0.8
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/package.json +3 -2
- package/src/Adapter.js +1 -4
- package/src/cloud/ChangePageURL.js +24 -0
- package/src/cloud/ClonesPage.js +14 -0
- package/src/cloud/DeletePage.js +35 -0
- package/src/cloud/PageChanges.js +15 -0
- package/src/cloud/PageRevisions.js +135 -0
- package/src/cloud/PageTranslations.js +22 -0
- package/src/cloud/Pages.js +63 -0
- package/src/cloud/RaketaClient.js +118 -0
- package/src/cloud/Redirects.js +81 -0
- package/src/cloud/RevertPageRevision.js +18 -0
- package/src/cloud/Settings.js +30 -0
- package/src/cloud/Tags.js +80 -0
- package/src/cloud/documents/articlesDocuments.js +608 -0
- package/src/cloud/documents/categoryDocuments.js +64 -0
- package/src/cloud/documents/common.js +84 -0
- package/src/cloud/documents/pagesDocuments.js +245 -0
- package/src/cloud/documents/redirectsDocuments.js +82 -0
- package/src/cloud/documents/settingsDocuments.js +23 -0
- package/src/cloud/documents/tagsDocuments.js +63 -0
- package/src/handlers/PageCloneHandler.js +17 -0
- package/src/handlers/PageCloneHandler.test/create.test.js +55 -0
- package/src/handlers/PageDeleteHandler.js +68 -0
- package/src/handlers/PageDeleteHandler.test/create.test.js +112 -0
- package/src/handlers/PageDeleteHandler.test/create_form.test.js +54 -0
- package/src/handlers/PageRevisionsCodesHandler.js +83 -0
- package/src/handlers/PageRevisionsCodesHandler.test/edit_form.test.js +56 -0
- package/src/handlers/PageRevisionsCodesHandler.test/update.test.js +137 -0
- package/src/handlers/PageRevisionsGeneralHandler.js +86 -0
- package/src/handlers/PageRevisionsGeneralHandler.test/edit_form.test.js +62 -0
- package/src/handlers/PageRevisionsGeneralHandler.test/update.test.js +147 -0
- package/src/handlers/PageRevisionsHandler.js +47 -0
- package/src/handlers/PageRevisionsHandler.test/create.test.js +67 -0
- package/src/handlers/PageRevisionsHandler.test/destroy.test.js +54 -0
- package/src/handlers/PageRevisionsLockHandler.js +54 -0
- package/src/handlers/PageRevisionsMetaHandler.js +83 -0
- package/src/handlers/PageRevisionsMetaHandler.test/edit_form.test.js +57 -0
- package/src/handlers/PageRevisionsMetaHandler.test/update.test.js +141 -0
- package/src/handlers/PageRevisionsTagsHandler.js +80 -0
- package/src/handlers/PageRevisionsTagsHandler.test/edit_form.test.js +69 -0
- package/src/handlers/PageRevisionsTagsHandler.test/update.test.js +141 -0
- package/src/handlers/PageRevisionsUnlockHandler.js +22 -0
- package/src/handlers/PageRevisionsVisualsHandler.js +77 -0
- package/src/handlers/PageRevisionsVisualsHandler.test/edit_form.test.js +55 -0
- package/src/handlers/PageRevisionsVisualsHandler.test/update.test.js +129 -0
- package/src/handlers/PageRevisionsWidgetsHandler.js +41 -0
- package/src/handlers/PageRevisionsWidgetsHandler.test/show.test.js +47 -0
- package/src/handlers/PageRevisionsWidgetsHandler.test/update.test.js +104 -0
- package/src/handlers/PageTranslationsHandler.js +91 -0
- package/src/handlers/PageURLsHandler.js +69 -0
- package/src/handlers/PageURLsHandler.test/create.test.js +157 -0
- package/src/handlers/PageURLsHandler.test/create_form.test.js +51 -0
- package/src/handlers/PagesHandler.js +114 -0
- package/src/handlers/PagesHandler.test/create.test.js +140 -0
- package/src/handlers/PagesHandler.test/create_form.test.js +41 -0
- package/src/handlers/PagesHandler.test/index.test.js +49 -0
- package/src/handlers/PagesHandler.test/show.test.js +103 -0
- package/src/handlers/PublishPageRevisionHandler.js +84 -0
- package/src/handlers/PublishPageRevisionHandler.test/create.test.js +136 -0
- package/src/handlers/PublishPageRevisionHandler.test/create_form.test.js +47 -0
- package/src/handlers/RedirectsHandler.js +124 -0
- package/src/handlers/RedirectsHandler.test/create.test.js +84 -0
- package/src/handlers/RedirectsHandler.test/create_form.test.js +29 -0
- package/src/handlers/RedirectsHandler.test/destroy.test.js +54 -0
- package/src/handlers/RedirectsHandler.test/edit_form.test.js +38 -0
- package/src/handlers/RedirectsHandler.test/index.test.js +42 -0
- package/src/handlers/RedirectsHandler.test/show.test.js +41 -0
- package/src/handlers/RedirectsHandler.test/update.test.js +89 -0
- package/src/handlers/RevertPageRevisionHandler.js +26 -0
- package/src/handlers/RevertPageRevisionHandler.test/create.test.js +80 -0
- package/src/handlers/SettingsGeneralHandler.js +13 -0
- package/src/handlers/SettingsLayoutHandler.js +51 -0
- package/src/handlers/SettingsMetaHandler.js +52 -0
- package/src/handlers/TagsHandler.js +113 -0
- package/src/helpers/FormBuilder.js +12 -4
- package/src/index.js +33 -0
- package/src/setupAuthentication.js +1 -1
- package/src/styles/application.css +55 -19
- package/src/views/layouts/application.ejs +30 -31
- package/src/views/layouts/header.ejs +5 -6
- package/src/views/page_deletes/create_form.ejs +55 -0
- package/src/views/page_lock/create_form.ejs +35 -0
- package/src/views/page_publish/_form.ejs +57 -0
- package/src/views/page_publish/create_form.ejs +11 -0
- package/src/views/page_revisions/_nav.ejs +40 -0
- package/src/views/page_revisions/codes/edit_form.ejs +39 -0
- package/src/views/page_revisions/general/edit_form.ejs +69 -0
- package/src/views/page_revisions/meta/edit_form.ejs +41 -0
- package/src/views/page_revisions/tags/edit_form.ejs +64 -0
- package/src/views/page_revisions/visuals/edit_form.ejs +42 -0
- package/src/views/page_translations/_form.ejs +76 -0
- package/src/views/page_translations/create_form.ejs +11 -0
- package/src/views/page_urls/create_form.ejs +31 -0
- package/src/views/pages/_form.ejs +84 -0
- package/src/views/pages/create_form.ejs +9 -0
- package/src/views/pages/edit_form.ejs +3 -0
- package/src/views/pages/index.ejs +161 -0
- package/src/views/pages/show.ejs +281 -0
- package/src/views/redirects/_form.ejs +40 -0
- package/src/views/redirects/create_form.ejs +9 -0
- package/src/views/redirects/edit_form.ejs +9 -0
- package/src/views/redirects/index.ejs +75 -1
- package/src/views/redirects/show.ejs +60 -0
- package/src/views/settings/_nav.ejs +28 -0
- package/src/views/settings/general/edit_form.ejs +26 -0
- package/src/views/settings/layout/edit_form.ejs +22 -0
- package/src/views/settings/meta/edit_form.ejs +38 -0
- package/src/views/tags/_form.ejs +39 -0
- package/src/views/tags/create_form.ejs +9 -0
- package/src/views/tags/edit_form.ejs +9 -0
- package/src/views/tags/index.ejs +43 -0
- package/test/factory.js +91 -0
- package/test/handlersHelper.js +9 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
const index = async (ctx) => {
|
|
2
|
+
const items = await ctx.client.redirects.list(ctx.query);
|
|
3
|
+
|
|
4
|
+
return {
|
|
5
|
+
assigns: {
|
|
6
|
+
items,
|
|
7
|
+
},
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const show = async (ctx) => {
|
|
12
|
+
const { id } = ctx.params;
|
|
13
|
+
const item = await ctx.client.redirects.find(id);
|
|
14
|
+
const history = await ctx.client.redirects.history(id);
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
assigns: {
|
|
18
|
+
item,
|
|
19
|
+
history,
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const create_form = (_ctx) => {
|
|
25
|
+
return {
|
|
26
|
+
assigns: {
|
|
27
|
+
redirect: {},
|
|
28
|
+
errors: {},
|
|
29
|
+
_translations: [],
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const edit_form = async (ctx) => {
|
|
35
|
+
const { id } = ctx.params;
|
|
36
|
+
const redirect = await ctx.client.redirects.find(id);
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
assigns: {
|
|
40
|
+
id,
|
|
41
|
+
redirect,
|
|
42
|
+
errors: {},
|
|
43
|
+
_translations: [],
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const create = async (ctx) => {
|
|
49
|
+
const params = ctx.resourceParams.redirect;
|
|
50
|
+
|
|
51
|
+
const { errors } = await ctx.client.redirects.create({
|
|
52
|
+
url: params.url,
|
|
53
|
+
destination: params.destination,
|
|
54
|
+
httpResponseCode: Number.parseInt(params.httpResponseCode, 10),
|
|
55
|
+
note: params.note || "",
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
if (errors) {
|
|
59
|
+
return {
|
|
60
|
+
assigns: {
|
|
61
|
+
redirect: params,
|
|
62
|
+
errors: { redirect: ctx.client.redirects.formatErrors(errors) },
|
|
63
|
+
_translations: [],
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
redirect: `/${ctx.locale}/redirects`,
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const update = async (ctx) => {
|
|
74
|
+
const { id } = ctx.params;
|
|
75
|
+
const params = ctx.resourceParams.redirect;
|
|
76
|
+
|
|
77
|
+
const { errors } = await ctx.client.redirects.update(id, {
|
|
78
|
+
url: params.url,
|
|
79
|
+
destination: params.destination,
|
|
80
|
+
httpResponseCode: Number.parseInt(params.httpResponseCode, 10),
|
|
81
|
+
note: params.note || "",
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
if (errors) {
|
|
85
|
+
return {
|
|
86
|
+
assigns: {
|
|
87
|
+
redirect: { ...params, id },
|
|
88
|
+
errors: { redirect: ctx.client.redirects.formatErrors(errors) },
|
|
89
|
+
_translations: [],
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
redirect: `/${ctx.locale}/redirects`,
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const destroy = async (ctx) => {
|
|
100
|
+
const { id } = ctx.params;
|
|
101
|
+
|
|
102
|
+
const { errors } = await ctx.client.redirects.delete(id);
|
|
103
|
+
|
|
104
|
+
if (errors) {
|
|
105
|
+
throw `Failed to delete redirect #${id}. WTF?`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
headers: {
|
|
110
|
+
"HX-Redirect": `/${ctx.locale}/redirects`,
|
|
111
|
+
},
|
|
112
|
+
json: {},
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export default {
|
|
117
|
+
index,
|
|
118
|
+
show,
|
|
119
|
+
create_form,
|
|
120
|
+
edit_form,
|
|
121
|
+
create,
|
|
122
|
+
update,
|
|
123
|
+
destroy,
|
|
124
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import RedirectsHandler from "../RedirectsHandler";
|
|
2
|
+
import Redirects from "../../cloud/Redirects";
|
|
3
|
+
|
|
4
|
+
import { testConfig } from "../../../test/handlersHelper";
|
|
5
|
+
import Factory from "../../../test/factory";
|
|
6
|
+
|
|
7
|
+
function buildCtx(redirect) {
|
|
8
|
+
return {
|
|
9
|
+
client: {
|
|
10
|
+
redirects: new Redirects(testConfig, "token"),
|
|
11
|
+
},
|
|
12
|
+
resourceParams: {
|
|
13
|
+
redirect: {
|
|
14
|
+
url: redirect.url,
|
|
15
|
+
destination: redirect.destination,
|
|
16
|
+
httpResponseCode: redirect.httpResponseCode.toString(),
|
|
17
|
+
note: redirect.note,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
locale: "en",
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
describe("Redirects", () => {
|
|
25
|
+
test("create successful", async () => {
|
|
26
|
+
const redirect = Factory.build("redirect");
|
|
27
|
+
const ctx = buildCtx(redirect);
|
|
28
|
+
|
|
29
|
+
const mockCreate = jest
|
|
30
|
+
.spyOn(ctx.client.redirects, "create")
|
|
31
|
+
.mockImplementation(() => ({ redirect: redirect, errors: null }));
|
|
32
|
+
|
|
33
|
+
const result = await RedirectsHandler.create(ctx);
|
|
34
|
+
|
|
35
|
+
expect(mockCreate).toHaveBeenCalledWith({
|
|
36
|
+
url: redirect.url,
|
|
37
|
+
destination: redirect.destination,
|
|
38
|
+
httpResponseCode: redirect.httpResponseCode,
|
|
39
|
+
note: redirect.note,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
expect(result).toEqual({
|
|
43
|
+
redirect: "/en/redirects",
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("create failed", async () => {
|
|
48
|
+
const redirect = Factory.build("redirect");
|
|
49
|
+
const ctx = buildCtx(redirect);
|
|
50
|
+
|
|
51
|
+
const mockCreate = jest
|
|
52
|
+
.spyOn(ctx.client.redirects, "create")
|
|
53
|
+
.mockImplementation(() => ({
|
|
54
|
+
redirect: null,
|
|
55
|
+
errors: [{ key: "url", message: "already used" }],
|
|
56
|
+
}));
|
|
57
|
+
|
|
58
|
+
const result = await RedirectsHandler.create(ctx);
|
|
59
|
+
|
|
60
|
+
expect(mockCreate).toHaveBeenCalledWith({
|
|
61
|
+
url: redirect.url,
|
|
62
|
+
destination: redirect.destination,
|
|
63
|
+
httpResponseCode: redirect.httpResponseCode,
|
|
64
|
+
note: redirect.note,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
expect(result).toEqual({
|
|
68
|
+
assigns: {
|
|
69
|
+
redirect: {
|
|
70
|
+
url: redirect.url,
|
|
71
|
+
destination: redirect.destination,
|
|
72
|
+
httpResponseCode: redirect.httpResponseCode.toString(),
|
|
73
|
+
note: redirect.note,
|
|
74
|
+
},
|
|
75
|
+
errors: {
|
|
76
|
+
redirect: {
|
|
77
|
+
url: "already used",
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
_translations: [],
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import RedirectsHandler from "../RedirectsHandler";
|
|
2
|
+
import Redirects from "../../cloud/Redirects";
|
|
3
|
+
|
|
4
|
+
import { testConfig } from "../../../test/handlersHelper";
|
|
5
|
+
|
|
6
|
+
function buildCtx() {
|
|
7
|
+
return {
|
|
8
|
+
client: {
|
|
9
|
+
redirects: new Redirects(testConfig, "token"),
|
|
10
|
+
},
|
|
11
|
+
params: { id: 1 },
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
describe("Redirects", () => {
|
|
16
|
+
test("create_form", async () => {
|
|
17
|
+
const ctx = buildCtx();
|
|
18
|
+
|
|
19
|
+
const result = RedirectsHandler.create_form(ctx);
|
|
20
|
+
|
|
21
|
+
expect(result).toEqual({
|
|
22
|
+
assigns: {
|
|
23
|
+
redirect: {},
|
|
24
|
+
errors: {},
|
|
25
|
+
_translations: [],
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import RedirectsHandler from "../RedirectsHandler";
|
|
2
|
+
import Redirects from "../../cloud/Redirects";
|
|
3
|
+
|
|
4
|
+
import { testConfig } from "../../../test/handlersHelper";
|
|
5
|
+
import Factory from "../../../test/factory";
|
|
6
|
+
|
|
7
|
+
function buildCtx() {
|
|
8
|
+
return {
|
|
9
|
+
client: {
|
|
10
|
+
redirects: new Redirects(testConfig, "token"),
|
|
11
|
+
},
|
|
12
|
+
params: { id: 1 },
|
|
13
|
+
locale: "en",
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
describe("Redirects", () => {
|
|
18
|
+
test("destroy successful", async () => {
|
|
19
|
+
const redirect = Factory.build("redirect");
|
|
20
|
+
const ctx = buildCtx();
|
|
21
|
+
|
|
22
|
+
const mockDelete = jest
|
|
23
|
+
.spyOn(ctx.client.redirects, "delete")
|
|
24
|
+
.mockImplementation(() => ({ redirect: redirect, errors: null }));
|
|
25
|
+
|
|
26
|
+
const result = await RedirectsHandler.destroy(ctx);
|
|
27
|
+
|
|
28
|
+
expect(mockDelete).toHaveBeenCalledWith(1);
|
|
29
|
+
|
|
30
|
+
expect(result).toEqual({
|
|
31
|
+
headers: {
|
|
32
|
+
"HX-Redirect": "/en/redirects",
|
|
33
|
+
},
|
|
34
|
+
json: {},
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("destroy failed", async () => {
|
|
39
|
+
const ctx = buildCtx();
|
|
40
|
+
|
|
41
|
+
const mockDelete = jest
|
|
42
|
+
.spyOn(ctx.client.redirects, "delete")
|
|
43
|
+
.mockImplementation(() => ({
|
|
44
|
+
redirect: null,
|
|
45
|
+
errors: [{ key: "generalError", message: "Not found" }],
|
|
46
|
+
}));
|
|
47
|
+
|
|
48
|
+
await expect(() => RedirectsHandler.destroy(ctx)).rejects.toMatch(
|
|
49
|
+
"Failed to delete redirect #1. WTF?"
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
expect(mockDelete).toHaveBeenCalledWith(1);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import RedirectsHandler from "../RedirectsHandler";
|
|
2
|
+
import Redirects from "../../cloud/Redirects";
|
|
3
|
+
|
|
4
|
+
import { testConfig } from "../../../test/handlersHelper";
|
|
5
|
+
import Factory from "../../../test/factory";
|
|
6
|
+
|
|
7
|
+
function buildCtx() {
|
|
8
|
+
return {
|
|
9
|
+
client: {
|
|
10
|
+
redirects: new Redirects(testConfig, "token"),
|
|
11
|
+
},
|
|
12
|
+
params: { id: 1 },
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe("Redirects", () => {
|
|
17
|
+
test("edit_form", async () => {
|
|
18
|
+
const redirect = Factory.build("redirect");
|
|
19
|
+
const ctx = buildCtx();
|
|
20
|
+
|
|
21
|
+
const mockShow = jest
|
|
22
|
+
.spyOn(ctx.client.redirects, "find")
|
|
23
|
+
.mockImplementation(() => redirect);
|
|
24
|
+
|
|
25
|
+
const result = await RedirectsHandler.edit_form(ctx);
|
|
26
|
+
|
|
27
|
+
expect(mockShow).toHaveBeenCalledWith(1);
|
|
28
|
+
|
|
29
|
+
expect(result).toEqual({
|
|
30
|
+
assigns: {
|
|
31
|
+
id: 1,
|
|
32
|
+
redirect: redirect,
|
|
33
|
+
errors: {},
|
|
34
|
+
_translations: [],
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import RedirectsHandler from "./../RedirectsHandler";
|
|
2
|
+
import Redirects from "../../cloud/Redirects";
|
|
3
|
+
|
|
4
|
+
import { testConfig } from "../../../test/handlersHelper";
|
|
5
|
+
import Factory from "../../../test/factory";
|
|
6
|
+
|
|
7
|
+
describe("Redirects", () => {
|
|
8
|
+
function buildCtx() {
|
|
9
|
+
return {
|
|
10
|
+
client: {
|
|
11
|
+
redirects: new Redirects(testConfig, "token"),
|
|
12
|
+
},
|
|
13
|
+
query: { foo: "bar" },
|
|
14
|
+
req: {
|
|
15
|
+
path: "/redirects",
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
test("index", async () => {
|
|
21
|
+
const redirect = Factory.build("redirect");
|
|
22
|
+
const pagination = Factory.build("pagination");
|
|
23
|
+
const ctx = buildCtx();
|
|
24
|
+
|
|
25
|
+
const mockedList = jest
|
|
26
|
+
.spyOn(ctx.client.redirects, "list")
|
|
27
|
+
.mockImplementation(() => ({ list: [redirect], pagination }));
|
|
28
|
+
|
|
29
|
+
const result = await RedirectsHandler.index(ctx);
|
|
30
|
+
|
|
31
|
+
expect(mockedList).toHaveBeenCalledWith({ foo: "bar" });
|
|
32
|
+
|
|
33
|
+
expect(result).toEqual({
|
|
34
|
+
assigns: {
|
|
35
|
+
items: {
|
|
36
|
+
list: [redirect],
|
|
37
|
+
pagination: pagination,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import RedirectsHandler from "../RedirectsHandler";
|
|
2
|
+
import Redirects from "../../cloud/Redirects";
|
|
3
|
+
import { testConfig } from "../../../test/handlersHelper";
|
|
4
|
+
import Factory from "../../../test/factory";
|
|
5
|
+
|
|
6
|
+
function buildCtx() {
|
|
7
|
+
return {
|
|
8
|
+
client: {
|
|
9
|
+
redirects: new Redirects(testConfig, "token"),
|
|
10
|
+
},
|
|
11
|
+
params: { id: 1 },
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
describe("Redirects", () => {
|
|
16
|
+
test("show", async () => {
|
|
17
|
+
const redirect = Factory.build("redirect");
|
|
18
|
+
|
|
19
|
+
const ctx = buildCtx();
|
|
20
|
+
|
|
21
|
+
const mockShow = jest
|
|
22
|
+
.spyOn(ctx.client.redirects, "find")
|
|
23
|
+
.mockImplementation(() => redirect);
|
|
24
|
+
|
|
25
|
+
const mockHistory = jest
|
|
26
|
+
.spyOn(ctx.client.redirects, "history")
|
|
27
|
+
.mockImplementation(() => []);
|
|
28
|
+
|
|
29
|
+
const result = await RedirectsHandler.show(ctx);
|
|
30
|
+
|
|
31
|
+
expect(mockShow).toHaveBeenCalledWith(1);
|
|
32
|
+
expect(mockHistory).toHaveBeenCalledWith(1);
|
|
33
|
+
|
|
34
|
+
expect(result).toEqual({
|
|
35
|
+
assigns: {
|
|
36
|
+
item: redirect,
|
|
37
|
+
history: [],
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import RedirectsHandler from "../RedirectsHandler";
|
|
2
|
+
import Redirects from "../../cloud/Redirects";
|
|
3
|
+
|
|
4
|
+
import { testConfig } from "../../../test/handlersHelper";
|
|
5
|
+
import Factory from "../../../test/factory";
|
|
6
|
+
|
|
7
|
+
function buildCtx(redirect) {
|
|
8
|
+
return {
|
|
9
|
+
client: {
|
|
10
|
+
redirects: new Redirects(testConfig, "token"),
|
|
11
|
+
},
|
|
12
|
+
params: { id: redirect.id },
|
|
13
|
+
resourceParams: {
|
|
14
|
+
redirect: {
|
|
15
|
+
url: "/updated",
|
|
16
|
+
destination: redirect.destination,
|
|
17
|
+
httpResponseCode: redirect.httpResponseCode.toString(),
|
|
18
|
+
note: redirect.note,
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
locale: "en",
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe("Redirects", () => {
|
|
26
|
+
test("update successful", async () => {
|
|
27
|
+
const redirect = Factory.build("redirect");
|
|
28
|
+
const ctx = buildCtx(redirect);
|
|
29
|
+
|
|
30
|
+
const mockUpdate = jest
|
|
31
|
+
.spyOn(ctx.client.redirects, "update")
|
|
32
|
+
.mockImplementation(() => ({
|
|
33
|
+
redirect: { ...redirect, url: "/updated" },
|
|
34
|
+
errors: null,
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
const result = await RedirectsHandler.update(ctx);
|
|
38
|
+
|
|
39
|
+
expect(mockUpdate).toHaveBeenCalledWith(redirect.id, {
|
|
40
|
+
url: "/updated",
|
|
41
|
+
destination: redirect.destination,
|
|
42
|
+
httpResponseCode: redirect.httpResponseCode,
|
|
43
|
+
note: redirect.note,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
expect(result).toEqual({
|
|
47
|
+
redirect: "/en/redirects",
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("update failed", async () => {
|
|
52
|
+
const redirect = Factory.build("redirect");
|
|
53
|
+
const ctx = buildCtx(redirect);
|
|
54
|
+
|
|
55
|
+
const mockUpdate = jest
|
|
56
|
+
.spyOn(ctx.client.redirects, "update")
|
|
57
|
+
.mockImplementation(() => ({
|
|
58
|
+
redirect: null,
|
|
59
|
+
errors: [{ key: "url", message: "already used" }],
|
|
60
|
+
}));
|
|
61
|
+
|
|
62
|
+
const result = await RedirectsHandler.update(ctx);
|
|
63
|
+
|
|
64
|
+
expect(mockUpdate).toHaveBeenCalledWith(redirect.id, {
|
|
65
|
+
url: "/updated",
|
|
66
|
+
destination: redirect.destination,
|
|
67
|
+
httpResponseCode: redirect.httpResponseCode,
|
|
68
|
+
note: redirect.note,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
expect(result).toEqual({
|
|
72
|
+
assigns: {
|
|
73
|
+
redirect: {
|
|
74
|
+
id: redirect.id,
|
|
75
|
+
url: "/updated",
|
|
76
|
+
destination: redirect.destination,
|
|
77
|
+
httpResponseCode: redirect.httpResponseCode.toString(),
|
|
78
|
+
note: redirect.note,
|
|
79
|
+
},
|
|
80
|
+
errors: {
|
|
81
|
+
redirect: {
|
|
82
|
+
url: "already used",
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
_translations: [],
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const create = async (ctx) => {
|
|
2
|
+
const { parent_id } = ctx.params;
|
|
3
|
+
const { version } = ctx.resourceParams;
|
|
4
|
+
|
|
5
|
+
const { errors, pageErrors } = await ctx.client.revertPageRevision.create(
|
|
6
|
+
parent_id,
|
|
7
|
+
Number.parseInt(version, 10),
|
|
8
|
+
ctx.locale
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
if (errors) {
|
|
12
|
+
throw new Error(`Failed to start revision: ${JSON.stringify(errors)}`);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (pageErrors) {
|
|
16
|
+
throw new Error(`Failed to start revision: ${JSON.stringify(pageErrors)}`);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
redirect: `/${ctx.locale}/pages/${parent_id}`,
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default {
|
|
25
|
+
create,
|
|
26
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import RevertPageRevisionHandler from "../RevertPageRevisionHandler";
|
|
2
|
+
import RevertPageRevision from "../../cloud/RevertPageRevision";
|
|
3
|
+
import { testConfig } from "../../../../../apps/admin/test/handlersHelper";
|
|
4
|
+
|
|
5
|
+
function buildCtx(pageID, version) {
|
|
6
|
+
return {
|
|
7
|
+
client: {
|
|
8
|
+
revertPageRevision: new RevertPageRevision(testConfig, "token"),
|
|
9
|
+
},
|
|
10
|
+
params: { parent_id: pageID },
|
|
11
|
+
resourceParams: { version },
|
|
12
|
+
locale: "en",
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe("Page revision revert", () => {
|
|
17
|
+
test("create successful", async () => {
|
|
18
|
+
const pageId = 42;
|
|
19
|
+
const version = 2;
|
|
20
|
+
const ctx = buildCtx(pageId, version);
|
|
21
|
+
|
|
22
|
+
const mockRevert = jest
|
|
23
|
+
.spyOn(ctx.client.revertPageRevision, "create")
|
|
24
|
+
.mockImplementation(() => ({
|
|
25
|
+
revision: {},
|
|
26
|
+
errors: null,
|
|
27
|
+
pageErrors: null,
|
|
28
|
+
}));
|
|
29
|
+
|
|
30
|
+
const result = await RevertPageRevisionHandler.create(ctx);
|
|
31
|
+
|
|
32
|
+
expect(mockRevert).toHaveBeenCalledWith(pageId, version, "en");
|
|
33
|
+
|
|
34
|
+
expect(result).toEqual({
|
|
35
|
+
redirect: `/en/pages/${pageId}`,
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("create failed with errors", async () => {
|
|
40
|
+
const pageId = 42;
|
|
41
|
+
const version = 2;
|
|
42
|
+
const ctx = buildCtx(pageId, version);
|
|
43
|
+
const errors = [{ key: "generalError", message: "Some error" }];
|
|
44
|
+
|
|
45
|
+
const mockRevert = jest
|
|
46
|
+
.spyOn(ctx.client.revertPageRevision, "create")
|
|
47
|
+
.mockImplementation(() => ({
|
|
48
|
+
revision: null,
|
|
49
|
+
errors: errors,
|
|
50
|
+
pageErrors: null,
|
|
51
|
+
}));
|
|
52
|
+
|
|
53
|
+
expect(async () => {
|
|
54
|
+
await RevertPageRevisionHandler.create(ctx);
|
|
55
|
+
}).rejects.toThrow(`Failed to start revision: ${JSON.stringify(errors)}`);
|
|
56
|
+
|
|
57
|
+
expect(mockRevert).toHaveBeenCalledWith(pageId, version, "en");
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("create failed with page errors", async () => {
|
|
61
|
+
const pageId = 42;
|
|
62
|
+
const version = 2;
|
|
63
|
+
const ctx = buildCtx(pageId, version);
|
|
64
|
+
const errors = [{ key: "generalError", message: "Some error" }];
|
|
65
|
+
|
|
66
|
+
const mockRevert = jest
|
|
67
|
+
.spyOn(ctx.client.revertPageRevision, "create")
|
|
68
|
+
.mockImplementation(() => ({
|
|
69
|
+
revision: null,
|
|
70
|
+
errors: null,
|
|
71
|
+
pageErrors: errors,
|
|
72
|
+
}));
|
|
73
|
+
|
|
74
|
+
expect(async () => {
|
|
75
|
+
await RevertPageRevisionHandler.create(ctx);
|
|
76
|
+
}).rejects.toThrow(`Failed to start revision: ${JSON.stringify(errors)}`);
|
|
77
|
+
|
|
78
|
+
expect(mockRevert).toHaveBeenCalledWith(pageId, version, "en");
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const edit_form = async (ctx) => {
|
|
2
|
+
const data = await ctx.client.settings.find(ctx.locale);
|
|
3
|
+
|
|
4
|
+
const layout_settings = {
|
|
5
|
+
header: JSON.stringify(data.menus?.header),
|
|
6
|
+
footer: JSON.stringify(data.menus?.footer),
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
return {
|
|
10
|
+
assigns: {
|
|
11
|
+
errors: {},
|
|
12
|
+
layout_settings,
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const update = async (ctx) => {
|
|
18
|
+
const params = ctx.resourceParams.layout_settings;
|
|
19
|
+
|
|
20
|
+
const currentSettings = await ctx.client.settings.find(ctx.locale);
|
|
21
|
+
|
|
22
|
+
if (!currentSettings.menus) {
|
|
23
|
+
currentSettings.menus = {};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
currentSettings.menus.header = JSON.parse(params.header);
|
|
27
|
+
currentSettings.menus.footer = JSON.parse(params.footer);
|
|
28
|
+
|
|
29
|
+
const { errors } = await ctx.client.settings.update(
|
|
30
|
+
ctx.locale,
|
|
31
|
+
currentSettings
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
if (errors) {
|
|
35
|
+
return {
|
|
36
|
+
assigns: {
|
|
37
|
+
setting: { ...params },
|
|
38
|
+
errors: { setting: ctx.client.settings.formatErrors(errors) },
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
redirect: `/${ctx.locale}/settings/layout/edit`,
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export default {
|
|
49
|
+
edit_form,
|
|
50
|
+
update,
|
|
51
|
+
};
|