@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.
Files changed (114) hide show
  1. package/package.json +3 -2
  2. package/src/Adapter.js +1 -4
  3. package/src/cloud/ChangePageURL.js +24 -0
  4. package/src/cloud/ClonesPage.js +14 -0
  5. package/src/cloud/DeletePage.js +35 -0
  6. package/src/cloud/PageChanges.js +15 -0
  7. package/src/cloud/PageRevisions.js +135 -0
  8. package/src/cloud/PageTranslations.js +22 -0
  9. package/src/cloud/Pages.js +63 -0
  10. package/src/cloud/RaketaClient.js +118 -0
  11. package/src/cloud/Redirects.js +81 -0
  12. package/src/cloud/RevertPageRevision.js +18 -0
  13. package/src/cloud/Settings.js +30 -0
  14. package/src/cloud/Tags.js +80 -0
  15. package/src/cloud/documents/articlesDocuments.js +608 -0
  16. package/src/cloud/documents/categoryDocuments.js +64 -0
  17. package/src/cloud/documents/common.js +84 -0
  18. package/src/cloud/documents/pagesDocuments.js +245 -0
  19. package/src/cloud/documents/redirectsDocuments.js +82 -0
  20. package/src/cloud/documents/settingsDocuments.js +23 -0
  21. package/src/cloud/documents/tagsDocuments.js +63 -0
  22. package/src/handlers/PageCloneHandler.js +17 -0
  23. package/src/handlers/PageCloneHandler.test/create.test.js +55 -0
  24. package/src/handlers/PageDeleteHandler.js +68 -0
  25. package/src/handlers/PageDeleteHandler.test/create.test.js +112 -0
  26. package/src/handlers/PageDeleteHandler.test/create_form.test.js +54 -0
  27. package/src/handlers/PageRevisionsCodesHandler.js +83 -0
  28. package/src/handlers/PageRevisionsCodesHandler.test/edit_form.test.js +56 -0
  29. package/src/handlers/PageRevisionsCodesHandler.test/update.test.js +137 -0
  30. package/src/handlers/PageRevisionsGeneralHandler.js +86 -0
  31. package/src/handlers/PageRevisionsGeneralHandler.test/edit_form.test.js +62 -0
  32. package/src/handlers/PageRevisionsGeneralHandler.test/update.test.js +147 -0
  33. package/src/handlers/PageRevisionsHandler.js +47 -0
  34. package/src/handlers/PageRevisionsHandler.test/create.test.js +67 -0
  35. package/src/handlers/PageRevisionsHandler.test/destroy.test.js +54 -0
  36. package/src/handlers/PageRevisionsLockHandler.js +54 -0
  37. package/src/handlers/PageRevisionsMetaHandler.js +83 -0
  38. package/src/handlers/PageRevisionsMetaHandler.test/edit_form.test.js +57 -0
  39. package/src/handlers/PageRevisionsMetaHandler.test/update.test.js +141 -0
  40. package/src/handlers/PageRevisionsTagsHandler.js +80 -0
  41. package/src/handlers/PageRevisionsTagsHandler.test/edit_form.test.js +69 -0
  42. package/src/handlers/PageRevisionsTagsHandler.test/update.test.js +141 -0
  43. package/src/handlers/PageRevisionsUnlockHandler.js +22 -0
  44. package/src/handlers/PageRevisionsVisualsHandler.js +77 -0
  45. package/src/handlers/PageRevisionsVisualsHandler.test/edit_form.test.js +55 -0
  46. package/src/handlers/PageRevisionsVisualsHandler.test/update.test.js +129 -0
  47. package/src/handlers/PageRevisionsWidgetsHandler.js +41 -0
  48. package/src/handlers/PageRevisionsWidgetsHandler.test/show.test.js +47 -0
  49. package/src/handlers/PageRevisionsWidgetsHandler.test/update.test.js +104 -0
  50. package/src/handlers/PageTranslationsHandler.js +91 -0
  51. package/src/handlers/PageURLsHandler.js +69 -0
  52. package/src/handlers/PageURLsHandler.test/create.test.js +157 -0
  53. package/src/handlers/PageURLsHandler.test/create_form.test.js +51 -0
  54. package/src/handlers/PagesHandler.js +114 -0
  55. package/src/handlers/PagesHandler.test/create.test.js +140 -0
  56. package/src/handlers/PagesHandler.test/create_form.test.js +41 -0
  57. package/src/handlers/PagesHandler.test/index.test.js +49 -0
  58. package/src/handlers/PagesHandler.test/show.test.js +103 -0
  59. package/src/handlers/PublishPageRevisionHandler.js +84 -0
  60. package/src/handlers/PublishPageRevisionHandler.test/create.test.js +136 -0
  61. package/src/handlers/PublishPageRevisionHandler.test/create_form.test.js +47 -0
  62. package/src/handlers/RedirectsHandler.js +124 -0
  63. package/src/handlers/RedirectsHandler.test/create.test.js +84 -0
  64. package/src/handlers/RedirectsHandler.test/create_form.test.js +29 -0
  65. package/src/handlers/RedirectsHandler.test/destroy.test.js +54 -0
  66. package/src/handlers/RedirectsHandler.test/edit_form.test.js +38 -0
  67. package/src/handlers/RedirectsHandler.test/index.test.js +42 -0
  68. package/src/handlers/RedirectsHandler.test/show.test.js +41 -0
  69. package/src/handlers/RedirectsHandler.test/update.test.js +89 -0
  70. package/src/handlers/RevertPageRevisionHandler.js +26 -0
  71. package/src/handlers/RevertPageRevisionHandler.test/create.test.js +80 -0
  72. package/src/handlers/SettingsGeneralHandler.js +13 -0
  73. package/src/handlers/SettingsLayoutHandler.js +51 -0
  74. package/src/handlers/SettingsMetaHandler.js +52 -0
  75. package/src/handlers/TagsHandler.js +113 -0
  76. package/src/helpers/FormBuilder.js +12 -4
  77. package/src/index.js +33 -0
  78. package/src/setupAuthentication.js +1 -1
  79. package/src/styles/application.css +55 -19
  80. package/src/views/layouts/application.ejs +30 -31
  81. package/src/views/layouts/header.ejs +5 -6
  82. package/src/views/page_deletes/create_form.ejs +55 -0
  83. package/src/views/page_lock/create_form.ejs +35 -0
  84. package/src/views/page_publish/_form.ejs +57 -0
  85. package/src/views/page_publish/create_form.ejs +11 -0
  86. package/src/views/page_revisions/_nav.ejs +40 -0
  87. package/src/views/page_revisions/codes/edit_form.ejs +39 -0
  88. package/src/views/page_revisions/general/edit_form.ejs +69 -0
  89. package/src/views/page_revisions/meta/edit_form.ejs +41 -0
  90. package/src/views/page_revisions/tags/edit_form.ejs +64 -0
  91. package/src/views/page_revisions/visuals/edit_form.ejs +42 -0
  92. package/src/views/page_translations/_form.ejs +76 -0
  93. package/src/views/page_translations/create_form.ejs +11 -0
  94. package/src/views/page_urls/create_form.ejs +31 -0
  95. package/src/views/pages/_form.ejs +84 -0
  96. package/src/views/pages/create_form.ejs +9 -0
  97. package/src/views/pages/edit_form.ejs +3 -0
  98. package/src/views/pages/index.ejs +161 -0
  99. package/src/views/pages/show.ejs +281 -0
  100. package/src/views/redirects/_form.ejs +40 -0
  101. package/src/views/redirects/create_form.ejs +9 -0
  102. package/src/views/redirects/edit_form.ejs +9 -0
  103. package/src/views/redirects/index.ejs +75 -1
  104. package/src/views/redirects/show.ejs +60 -0
  105. package/src/views/settings/_nav.ejs +28 -0
  106. package/src/views/settings/general/edit_form.ejs +26 -0
  107. package/src/views/settings/layout/edit_form.ejs +22 -0
  108. package/src/views/settings/meta/edit_form.ejs +38 -0
  109. package/src/views/tags/_form.ejs +39 -0
  110. package/src/views/tags/create_form.ejs +9 -0
  111. package/src/views/tags/edit_form.ejs +9 -0
  112. package/src/views/tags/index.ejs +43 -0
  113. package/test/factory.js +91 -0
  114. package/test/handlersHelper.js +9 -0
@@ -0,0 +1,140 @@
1
+ import PagesHandler from "./../PagesHandler";
2
+ import Pages from "../../cloud/Pages";
3
+ import Tags from "../../cloud/Tags";
4
+ import { testConfig } from "../../../../../apps/admin/test/handlersHelper";
5
+ import Factory from "../../../../../apps/admin/test/factory";
6
+
7
+ describe("Pages Handler", () => {
8
+ function buildCtx(params) {
9
+ return {
10
+ client: {
11
+ pages: new Pages(testConfig, "token"),
12
+ tags: new Tags(testConfig, "token"),
13
+ },
14
+ resourceParams: {
15
+ page: params,
16
+ },
17
+ locale: "en",
18
+ };
19
+ }
20
+
21
+ test("create successfull", async () => {
22
+ const tag = Factory.build("tag");
23
+ const params = {
24
+ title: "Page title",
25
+ slug: "url",
26
+ visibility: "public",
27
+ layout: "default",
28
+ meta_title: "Meta title",
29
+ meta_description: "Meta description",
30
+ meta_image: JSON.stringify({ id: 42 }),
31
+ username: "admin",
32
+ password: "admin123!@#",
33
+ tags: [tag.id],
34
+ };
35
+
36
+ const ctx = buildCtx(params);
37
+
38
+ const mockedCreate = jest
39
+ .spyOn(ctx.client.pages, "create")
40
+ .mockImplementation(() => ({ page: {}, errors: null }));
41
+
42
+ const result = await PagesHandler.create(ctx);
43
+
44
+ expect(mockedCreate).toHaveBeenCalledWith(
45
+ {
46
+ title: params.title,
47
+ slug: params.slug,
48
+ visibility: params.visibility,
49
+ settings: {
50
+ layout: params.layout,
51
+ meta: {
52
+ title: params.meta_title,
53
+ description: params.meta_description,
54
+ image: JSON.parse(params.meta_image || "{}"),
55
+ },
56
+ credentials: {
57
+ user: params.username,
58
+ password: params.password,
59
+ },
60
+ },
61
+ widgets: [],
62
+ tags: params.tags,
63
+ categories: [],
64
+ },
65
+ "en",
66
+ "page"
67
+ );
68
+
69
+ expect(result).toEqual({
70
+ redirect: "/en/pages",
71
+ });
72
+ });
73
+
74
+ test("create failed", async () => {
75
+ const tag = Factory.build("tag");
76
+ const params = {
77
+ title: "Page title",
78
+ slug: "",
79
+ visibility: "public",
80
+ layout: "default",
81
+ meta_title: "Meta title",
82
+ meta_description: "Meta description",
83
+ meta_image: JSON.stringify({ id: 42 }),
84
+ username: "admin",
85
+ password: "admin123!@#",
86
+ tags: [tag.id],
87
+ };
88
+
89
+ const ctx = buildCtx(params);
90
+
91
+ const mockedTagsList = jest
92
+ .spyOn(ctx.client.tags, "all")
93
+ .mockImplementation(() => ({ list: [tag] }));
94
+
95
+ const mockedCreate = jest
96
+ .spyOn(ctx.client.pages, "create")
97
+ .mockImplementation(() => ({
98
+ page: {},
99
+ errors: [{ key: "slug", message: "cannot be blank" }],
100
+ }));
101
+
102
+ const result = await PagesHandler.create(ctx);
103
+
104
+ expect(mockedTagsList).toHaveBeenCalledWith("en");
105
+ expect(mockedCreate).toHaveBeenCalledWith(
106
+ {
107
+ title: params.title,
108
+ slug: "",
109
+ visibility: params.visibility,
110
+ settings: {
111
+ layout: params.layout,
112
+ meta: {
113
+ title: params.meta_title,
114
+ description: params.meta_description,
115
+ image: JSON.parse(params.meta_image || "{}"),
116
+ },
117
+ credentials: {
118
+ user: params.username,
119
+ password: params.password,
120
+ },
121
+ },
122
+ widgets: [],
123
+ tags: params.tags,
124
+ categories: [],
125
+ },
126
+ "en",
127
+ "page"
128
+ );
129
+
130
+ expect(result).toEqual({
131
+ assigns: {
132
+ page: { ...params },
133
+ tags: [tag],
134
+ errors: { page: { slug: "cannot be blank" } },
135
+ visibilityOptions: ctx.client.pages.visibilityOptions(),
136
+ _translations: [],
137
+ },
138
+ });
139
+ });
140
+ });
@@ -0,0 +1,41 @@
1
+ import PagesHandler from "./../PagesHandler";
2
+ import Pages from "../../cloud/Pages";
3
+ import Tags from "../../cloud/Tags";
4
+ import { testConfig } from "../../../test/handlersHelper";
5
+ import Factory from "../../../test/factory";
6
+
7
+ describe("Pages Handler", () => {
8
+ function buildCtx() {
9
+ return {
10
+ client: {
11
+ pages: new Pages(testConfig, "token"),
12
+ tags: new Tags(testConfig, "token"),
13
+ },
14
+ query: { foo: "bar" },
15
+ locale: "en",
16
+ };
17
+ }
18
+
19
+ test("index", async () => {
20
+ const tags = [Factory.build("tag")];
21
+ const ctx = buildCtx();
22
+
23
+ const mockedTagList = jest
24
+ .spyOn(ctx.client.tags, "all")
25
+ .mockImplementation(() => ({ list: tags, pagination: null }));
26
+
27
+ const result = await PagesHandler.create_form(ctx);
28
+
29
+ expect(mockedTagList).toHaveBeenCalledWith("en");
30
+
31
+ expect(result).toEqual({
32
+ assigns: {
33
+ page: { ...ctx.client.pages.defaults(), meta_image: {} },
34
+ tags: tags,
35
+ errors: {},
36
+ visibilityOptions: ctx.client.pages.visibilityOptions(),
37
+ _translations: [],
38
+ },
39
+ });
40
+ });
41
+ });
@@ -0,0 +1,49 @@
1
+ import PagesHandler from "./../PagesHandler";
2
+ import Pages from "../../cloud/Pages";
3
+ import Tags from "../../cloud/Tags";
4
+ import { testConfig } from "../../../test/handlersHelper";
5
+ import Factory from "../../../test/factory";
6
+
7
+ describe("Pages Handler", () => {
8
+ function buildCtx() {
9
+ return {
10
+ client: {
11
+ pages: new Pages(testConfig, "token"),
12
+ tags: new Tags(testConfig, "token"),
13
+ },
14
+ query: { foo: "bar" },
15
+ locale: "en",
16
+ };
17
+ }
18
+
19
+ test("index", async () => {
20
+ const page = Factory.build("page");
21
+ const pagination = Factory.build("pagination");
22
+ const tags = [Factory.build("tag")];
23
+ const ctx = buildCtx();
24
+
25
+ const mockedPageList = jest
26
+ .spyOn(ctx.client.pages, "list")
27
+ .mockImplementation(() => ({ list: [page], pagination }));
28
+
29
+ const mockedTagList = jest
30
+ .spyOn(ctx.client.tags, "all")
31
+ .mockImplementation(() => ({ list: tags, pagination: null }));
32
+
33
+ const result = await PagesHandler.index(ctx);
34
+
35
+ expect(mockedPageList).toHaveBeenCalledWith({ foo: "bar" }, "en");
36
+ expect(mockedTagList).toHaveBeenCalledWith("en");
37
+
38
+ expect(result).toEqual({
39
+ assigns: {
40
+ items: {
41
+ list: [page],
42
+ pagination: pagination,
43
+ },
44
+ tags: tags,
45
+ visibilityOptions: ctx.client.pages.visibilityOptions(),
46
+ },
47
+ });
48
+ });
49
+ });
@@ -0,0 +1,103 @@
1
+ import PagesHandler from "./../PagesHandler";
2
+ import Pages from "../../cloud/Pages";
3
+ import PageChanges from "../../cloud/PageChanges";
4
+ import PageRevisions from "../../cloud/PageRevisions";
5
+ import { testConfig } from "../../../test/handlersHelper";
6
+ import Factory from "../../../test/factory";
7
+
8
+ describe("Pages Handler", () => {
9
+ function buildCtx(page) {
10
+ return {
11
+ client: {
12
+ pages: new Pages(testConfig, "token"),
13
+ pageChanges: new PageChanges(testConfig, "token"),
14
+ pageRevisions: new PageRevisions(testConfig, "token"),
15
+ },
16
+ params: { id: page.id },
17
+ locale: "en",
18
+ locales: {
19
+ en: {
20
+ name: "English",
21
+ code: "en-gb",
22
+ flag: "/static/_assets/flags/gb.svg",
23
+ },
24
+ bg: {
25
+ name: "Bulgarian",
26
+ code: "bg",
27
+ flag: "/static/_assets/flags/bg.svg",
28
+ },
29
+ de: {
30
+ name: "German",
31
+ code: "de",
32
+ flag: "/static/_assets/flags/de.svg",
33
+ },
34
+ },
35
+ };
36
+ }
37
+
38
+ test("show for existing page", async () => {
39
+ const page = Factory.build("page", {
40
+ translations: {
41
+ de: {
42
+ id: 42,
43
+ },
44
+ bg: {
45
+ id: 69,
46
+ },
47
+ },
48
+ });
49
+ const revision = Factory.build("page_revision", { originalId: page.id });
50
+ const change = Factory.build("page_change");
51
+ const ctx = buildCtx(page);
52
+
53
+ const mockedPageFind = jest
54
+ .spyOn(ctx.client.pages, "find")
55
+ .mockImplementation(() => page);
56
+
57
+ const mockedPageRevisions = jest
58
+ .spyOn(ctx.client.pageRevisions, "all")
59
+ .mockImplementation(() => ({ list: [revision] }));
60
+
61
+ const mockedPageChanges = jest
62
+ .spyOn(ctx.client.pageChanges, "all")
63
+ .mockImplementation(() => ({ list: [change] }));
64
+
65
+ const result = await PagesHandler.show(ctx);
66
+
67
+ expect(mockedPageFind).toHaveBeenCalledWith(page.id, "en");
68
+ expect(mockedPageRevisions).toHaveBeenCalledWith(page.id, "en");
69
+ expect(mockedPageChanges).toHaveBeenCalledWith(page.id, "en");
70
+
71
+ expect(result).toEqual({
72
+ assigns: {
73
+ page,
74
+ revisions: [revision],
75
+ changes: [change],
76
+ _translations: [
77
+ {
78
+ locale: "bg",
79
+ path: "/bg/pages/69",
80
+ },
81
+ {
82
+ locale: "de",
83
+ path: "/de/pages/42",
84
+ },
85
+ ],
86
+ },
87
+ });
88
+ });
89
+
90
+ test("show for non existing page", async () => {
91
+ const ctx = buildCtx({ id: "42" });
92
+
93
+ const mockedPageFind = jest
94
+ .spyOn(ctx.client.pages, "find")
95
+ .mockImplementation(() => null);
96
+
97
+ expect(async () => {
98
+ await PagesHandler.show(ctx);
99
+ }).rejects.toThrow("Missing page #42");
100
+
101
+ expect(mockedPageFind).toHaveBeenCalledWith("42", "en");
102
+ });
103
+ });
@@ -0,0 +1,84 @@
1
+ const create_form = async (ctx) => {
2
+ const { parent_id } = ctx.params;
3
+
4
+ const revision = await ctx.client.pageRevisions.find(parent_id, ctx.locale);
5
+
6
+ return {
7
+ assigns: {
8
+ publishing: {
9
+ id: revision.id,
10
+ originalId: revision.originalId,
11
+ title: revision.meta.title,
12
+ description: revision.meta.description,
13
+ visibility: revision.visibility,
14
+ username: revision.settings?.credentials?.user,
15
+ password: revision.settings?.credentials?.password,
16
+ },
17
+ visibilityOptions: ctx.client.pages.visibilityOptions(),
18
+ errors: {},
19
+ _translations: [],
20
+ },
21
+ };
22
+ };
23
+
24
+ function publishPageParams(
25
+ { visibility, username, password },
26
+ currentSettings
27
+ ) {
28
+ if (visibility === "protected") {
29
+ const credentials = {
30
+ user: username,
31
+ password: password,
32
+ };
33
+
34
+ return {
35
+ visibility,
36
+ settings: JSON.stringify({
37
+ ...currentSettings,
38
+ credentials,
39
+ }),
40
+ };
41
+ }
42
+
43
+ return { visibility };
44
+ }
45
+
46
+ const create = async (ctx) => {
47
+ const { parent_id } = ctx.params;
48
+ const publishing = ctx.resourceParams.publishing;
49
+
50
+ const revision = await ctx.client.pageRevisions.find(parent_id, ctx.locale);
51
+ const { errors } = await ctx.client.pageRevisions.publish(
52
+ revision.id,
53
+ ctx.locale,
54
+ {
55
+ title: publishing.title || "",
56
+ description: publishing.description || "",
57
+ },
58
+ publishPageParams(publishing, revision.settings)
59
+ );
60
+
61
+ if (errors) {
62
+ return {
63
+ assigns: {
64
+ publishing: {
65
+ ...publishing,
66
+ id: revision.id,
67
+ originalId: revision.originalId,
68
+ },
69
+ visibilityOptions: ctx.client.pages.visibilityOptions(),
70
+ errors: ctx.client.pageRevisions.formatErrors(errors),
71
+ _translations: [],
72
+ },
73
+ };
74
+ }
75
+
76
+ return {
77
+ redirect: `/${ctx.locale}/pages/${revision.originalId}`,
78
+ };
79
+ };
80
+
81
+ export default {
82
+ create,
83
+ create_form,
84
+ };
@@ -0,0 +1,136 @@
1
+ import PublishPageRevisionHandler from "../PublishPageRevisionHandler";
2
+ import PageRevisions from "../../cloud/PageRevisions";
3
+ import Pages from "../../cloud/Pages";
4
+ import Factory from "../../../../../apps/admin/test/factory";
5
+ import { testConfig } from "../../../../../apps/admin/test/handlersHelper";
6
+
7
+ function buildCtx(revision, resourceParams) {
8
+ return {
9
+ client: {
10
+ pageRevisions: new PageRevisions(testConfig, "token"),
11
+ pages: new Pages(testConfig, "token"),
12
+ },
13
+ params: { parent_id: revision.id },
14
+ resourceParams,
15
+ locale: "en",
16
+ };
17
+ }
18
+
19
+ describe("Publish page revision", () => {
20
+ test("create successful", async () => {
21
+ const revision = Factory.build("page_revision");
22
+ const publishing = {
23
+ title: "A new revision!",
24
+ description: "Nice!",
25
+ visibility: "protected",
26
+ username: "admin",
27
+ password: "admin123!@#",
28
+ };
29
+
30
+ const ctx = buildCtx(revision, {
31
+ publishing,
32
+ });
33
+
34
+ const updatedPage = Factory.build("page", {
35
+ id: revision.originalId,
36
+ settings: {
37
+ credentials: {
38
+ user: "admin",
39
+ password: "admin123!@#",
40
+ },
41
+ },
42
+ });
43
+
44
+ const mockFind = jest
45
+ .spyOn(ctx.client.pageRevisions, "find")
46
+ .mockImplementation(() => revision);
47
+
48
+ const mockPublish = jest
49
+ .spyOn(ctx.client.pageRevisions, "publish")
50
+ .mockImplementation(() => ({ page: updatedPage, errors: null }));
51
+
52
+ const result = await PublishPageRevisionHandler.create(ctx);
53
+
54
+ expect(mockFind).toHaveBeenCalledWith(revision.id, "en");
55
+ expect(mockPublish).toHaveBeenCalledWith(
56
+ revision.id,
57
+ "en",
58
+ {
59
+ title: publishing.title,
60
+ description: publishing.description,
61
+ },
62
+ {
63
+ visibility: publishing.visibility,
64
+ settings: JSON.stringify({
65
+ ...revision.settings,
66
+ credentials: {
67
+ user: publishing.username,
68
+ password: publishing.password,
69
+ },
70
+ }),
71
+ }
72
+ );
73
+
74
+ expect(result).toEqual({
75
+ redirect: `/en/pages/${updatedPage.id}`,
76
+ });
77
+ });
78
+
79
+ test("create failed", async () => {
80
+ const revision = Factory.build("page_revision");
81
+ const publishing = {
82
+ title: "A new revision!",
83
+ description: "Nice!",
84
+ visibility: "public",
85
+ };
86
+
87
+ const ctx = buildCtx(revision, {
88
+ publishing,
89
+ });
90
+
91
+ const mockFind = jest
92
+ .spyOn(ctx.client.pageRevisions, "find")
93
+ .mockImplementation(() => revision);
94
+
95
+ const mockPublish = jest
96
+ .spyOn(ctx.client.pageRevisions, "publish")
97
+ .mockImplementation(() => ({
98
+ page: null,
99
+ errors: [{ key: "url", message: "Oops" }],
100
+ }));
101
+
102
+ const result = await PublishPageRevisionHandler.create(ctx);
103
+
104
+ expect(mockFind).toHaveBeenCalledWith(revision.id, "en");
105
+ expect(mockPublish).toHaveBeenCalledWith(
106
+ revision.id,
107
+ "en",
108
+ {
109
+ title: publishing.title,
110
+ description: publishing.description,
111
+ },
112
+ {
113
+ visibility: publishing.visibility,
114
+ }
115
+ );
116
+
117
+ expect(result).toEqual({
118
+ assigns: {
119
+ publishing: {
120
+ id: revision.id,
121
+ originalId: revision.originalId,
122
+ title: publishing.title,
123
+ description: publishing.description,
124
+ visibility: publishing.visibility,
125
+ username: publishing.username,
126
+ password: publishing.password,
127
+ },
128
+ visibilityOptions: ctx.client.pages.visibilityOptions(),
129
+ errors: {
130
+ url: "Oops",
131
+ },
132
+ _translations: [],
133
+ },
134
+ });
135
+ });
136
+ });
@@ -0,0 +1,47 @@
1
+ import PublishPageRevisionHandler from "../PublishPageRevisionHandler";
2
+ import PageRevisions from "../../cloud/PageRevisions";
3
+ import Pages from "../../cloud/Pages";
4
+ import Factory from "../../../test/factory";
5
+ import { testConfig } from "../../../test/handlersHelper";
6
+
7
+ function buildCtx(revision) {
8
+ return {
9
+ client: {
10
+ pageRevisions: new PageRevisions(testConfig, "token"),
11
+ pages: new Pages(testConfig, "token"),
12
+ },
13
+ params: { parent_id: revision.id },
14
+ locale: "en",
15
+ };
16
+ }
17
+
18
+ describe("Publish page revision", () => {
19
+ test("create_form", async () => {
20
+ const revision = Factory.build("page_revision");
21
+ const ctx = buildCtx(revision);
22
+ const mockFind = jest
23
+ .spyOn(ctx.client.pageRevisions, "find")
24
+ .mockImplementation(() => revision);
25
+
26
+ const result = await PublishPageRevisionHandler.create_form(ctx);
27
+
28
+ expect(mockFind).toHaveBeenCalledWith(revision.id, "en");
29
+
30
+ expect(result).toEqual({
31
+ assigns: {
32
+ publishing: {
33
+ id: revision.id,
34
+ originalId: revision.originalId,
35
+ title: revision.meta.title,
36
+ description: revision.meta.description,
37
+ visibility: revision.visibility,
38
+ username: revision.settings?.credentials?.user,
39
+ password: revision.settings?.credentials?.password,
40
+ },
41
+ visibilityOptions: ctx.client.pages.visibilityOptions(),
42
+ errors: {},
43
+ _translations: [],
44
+ },
45
+ });
46
+ });
47
+ });