@raketa-cloud/admin 0.0.33 → 0.0.36

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 (43) hide show
  1. package/package.json +1 -1
  2. package/src/handlers/article_revisions/LocksHandler.js +22 -4
  3. package/src/handlers/article_revisions/UnlocksHandler.js +3 -1
  4. package/src/handlers/event_revisions/LocksHandler.js +17 -4
  5. package/src/handlers/event_revisions/UnlocksHandler.js +1 -1
  6. package/src/handlers/page_revisions/LocksHandler.js +13 -3
  7. package/src/handlers/page_revisions/UnlocksHandler.js +1 -1
  8. package/src/helpers/FormBuilder.js +108 -49
  9. package/src/helpers/Inflector.js +1 -1
  10. package/src/styles/application.css +11 -2
  11. package/src/tests/handlers/article_revisions/CodesHandler.test/update.test.js +5 -5
  12. package/src/tests/handlers/article_revisions/LocksHandler.test/create.test.js +142 -0
  13. package/src/tests/handlers/article_revisions/LocksHandler.test/create_form.test.js +55 -0
  14. package/src/tests/handlers/article_revisions/UnlocksHandler.test/create.test.js +84 -0
  15. package/src/tests/handlers/event_revisions/CodesHandler.test/update.test.js +5 -5
  16. package/src/tests/handlers/event_revisions/LocksHandler.test/create.test.js +142 -0
  17. package/src/tests/handlers/event_revisions/LocksHandler.test/create_form.test.js +55 -0
  18. package/src/tests/handlers/event_revisions/UnlocksHandler.test/create.test.js +84 -0
  19. package/src/tests/handlers/page_revisions/CodesHandler.test/edit_form.test.js +1 -1
  20. package/src/tests/handlers/page_revisions/CodesHandler.test/update.test.js +5 -5
  21. package/src/tests/handlers/page_revisions/LocksHandler.test/create.test.js +138 -0
  22. package/src/tests/handlers/page_revisions/LocksHandler.test/create_form.test.js +55 -0
  23. package/src/tests/handlers/page_revisions/UnlocksHandler.test/create.test.js +80 -0
  24. package/src/views/article_revisions/codes/edit_form.ejs +3 -3
  25. package/src/views/article_revisions/tags/edit_form.ejs +1 -1
  26. package/src/views/articles/_form.ejs +1 -1
  27. package/src/views/articles/create_form.ejs +1 -1
  28. package/src/views/articles/deletes/create_form.ejs +1 -1
  29. package/src/views/articles/translations/_form.ejs +1 -1
  30. package/src/views/articles/translations/create_form.ejs +1 -1
  31. package/src/views/event_revisions/codes/edit_form.ejs +3 -3
  32. package/src/views/event_revisions/tags/edit_form.ejs +1 -1
  33. package/src/views/events/_form.ejs +1 -1
  34. package/src/views/events/create_form.ejs +1 -1
  35. package/src/views/events/deletes/create_form.ejs +1 -1
  36. package/src/views/events/translations/_form.ejs +1 -1
  37. package/src/views/events/translations/create_form.ejs +1 -1
  38. package/src/views/page_revisions/codes/edit_form.ejs +3 -3
  39. package/src/views/pages/_form.ejs +1 -1
  40. package/src/views/pages/create_form.ejs +1 -1
  41. package/src/views/pages/deletes/create_form.ejs +1 -1
  42. package/src/views/pages/translations/_form.ejs +1 -1
  43. package/src/views/pages/translations/create_form.ejs +1 -1
@@ -0,0 +1,55 @@
1
+ import Factory from "../../../support/factory";
2
+ import ArticleRevisions from "../../../../cloud/ArticleRevisions";
3
+ import LocksHandler from "../../../../handlers/article_revisions/LocksHandler";
4
+
5
+ function buildCtx(revision) {
6
+ return {
7
+ client: {
8
+ articleRevisions: new ArticleRevisions(() => ({}), "token"),
9
+ },
10
+ params: { parent_id: revision.id },
11
+ locale: "en",
12
+ };
13
+ }
14
+
15
+ describe("New article revision lock", () => {
16
+ test("create_form for locking article revision", async () => {
17
+ const revision = Factory.build("article_revision");
18
+ const ctx = buildCtx(revision);
19
+
20
+ const mockFind = jest
21
+ .spyOn(ctx.client.articleRevisions, "find")
22
+ .mockImplementation(() => revision);
23
+
24
+ const result = await LocksHandler.create_form(ctx);
25
+
26
+ expect(mockFind).toHaveBeenCalledWith(revision.id, "en");
27
+
28
+ expect(result).toEqual({
29
+ assigns: {
30
+ resource: {
31
+ id: revision.id,
32
+ originalId: revision.originalId,
33
+ message: "",
34
+ },
35
+ errors: {},
36
+ _translations: [],
37
+ },
38
+ });
39
+ });
40
+
41
+ test("create_form for non existing article revision", async () => {
42
+ const nonExistentRevision = Factory.build("article_revision");
43
+ const ctx = buildCtx(nonExistentRevision);
44
+
45
+ const mockFind = jest
46
+ .spyOn(ctx.client.articleRevisions, "find")
47
+ .mockImplementation(() => null);
48
+
49
+ await expect(LocksHandler.create_form(ctx)).rejects.toThrow(
50
+ `Missing revision #${nonExistentRevision.id}`
51
+ );
52
+
53
+ expect(mockFind).toHaveBeenCalledWith(nonExistentRevision.id, "en");
54
+ });
55
+ });
@@ -0,0 +1,84 @@
1
+ import Factory from "../../../support/factory";
2
+ import ArticleRevisions from "../../../../cloud/ArticleRevisions";
3
+ import UnlocksHandler from "../../../../handlers/article_revisions/UnlocksHandler";
4
+
5
+ function buildCtx(revision) {
6
+ return {
7
+ client: {
8
+ articleRevisions: new ArticleRevisions(() => ({}), "token"),
9
+ },
10
+ params: { parent_id: revision.id },
11
+ locale: "en",
12
+ resourceConfig: {
13
+ articleType: "article",
14
+ articleTypePlural: "articles",
15
+ },
16
+ };
17
+ }
18
+
19
+ describe("Article revision unlock", () => {
20
+ test("unlock successful", async () => {
21
+ const revision = Factory.build("article_revision");
22
+ const ctx = buildCtx(revision);
23
+
24
+ const mockUnlock = jest
25
+ .spyOn(ctx.client.articleRevisions, "unlock")
26
+ .mockImplementation(() => ({
27
+ revision: revision,
28
+ errors: null,
29
+ articleErrors: null,
30
+ }));
31
+
32
+ const result = await UnlocksHandler.create(ctx);
33
+
34
+ expect(mockUnlock).toHaveBeenCalledWith(revision.id, "en");
35
+
36
+ expect(result).toEqual({
37
+ redirect: `/en/articles/${revision.originalId}`,
38
+ });
39
+ });
40
+
41
+ test("unlock failed with errors", async () => {
42
+ const revision = Factory.build("article_revision");
43
+ const ctx = buildCtx(revision);
44
+ const errors = [
45
+ { key: "generalError", message: "Failed to unlock revision" },
46
+ ];
47
+
48
+ const mockUnlock = jest
49
+ .spyOn(ctx.client.articleRevisions, "unlock")
50
+ .mockImplementation(() => ({
51
+ revision: null,
52
+ errors,
53
+ articleErrors: null,
54
+ }));
55
+
56
+ await expect(UnlocksHandler.create(ctx)).rejects.toThrow(
57
+ `Failed to unlock revision: ${JSON.stringify(errors)}`
58
+ );
59
+
60
+ expect(mockUnlock).toHaveBeenCalledWith(revision.id, "en");
61
+ });
62
+
63
+ test("unlock failed with article errors", async () => {
64
+ const revision = Factory.build("article_revision");
65
+ const ctx = buildCtx(revision);
66
+ const articleErrors = [
67
+ { key: "generalError", message: "Failed to start revision" },
68
+ ];
69
+
70
+ const mockUnlock = jest
71
+ .spyOn(ctx.client.articleRevisions, "unlock")
72
+ .mockImplementation(() => ({
73
+ revision: null,
74
+ errors: null,
75
+ articleErrors,
76
+ }));
77
+
78
+ await expect(UnlocksHandler.create(ctx)).rejects.toThrow(
79
+ `Failed to start revision: ${JSON.stringify(articleErrors)}`
80
+ );
81
+
82
+ expect(mockUnlock).toHaveBeenCalledWith(revision.id, "en");
83
+ });
84
+ });
@@ -32,7 +32,7 @@ describe("Event revision code settings", () => {
32
32
  settings: {
33
33
  codes: {
34
34
  scripts: JSON.stringify([{ type: "bla" }]),
35
- structured_data: JSON.stringify({ type: "event" }),
35
+ structured_json: JSON.stringify({ type: "event" }),
36
36
  },
37
37
  },
38
38
  };
@@ -67,7 +67,7 @@ describe("Event revision code settings", () => {
67
67
  ...revision.settings,
68
68
  codes: {
69
69
  scripts: [{ type: "bla" }],
70
- structured_data: { type: "event" },
70
+ structured_json: { type: "event" },
71
71
  },
72
72
  },
73
73
  });
@@ -88,7 +88,7 @@ describe("Event revision code settings", () => {
88
88
  settings: {
89
89
  codes: {
90
90
  scripts: JSON.stringify([{ type: "bla" }]),
91
- structured_data: JSON.stringify({ type: "event" }),
91
+ structured_json: JSON.stringify({ type: "event" }),
92
92
  },
93
93
  },
94
94
  };
@@ -123,7 +123,7 @@ describe("Event revision code settings", () => {
123
123
  ...revision.settings,
124
124
  codes: {
125
125
  scripts: [{ type: "bla" }],
126
- structured_data: { type: "event" },
126
+ structured_json: { type: "event" },
127
127
  },
128
128
  },
129
129
  });
@@ -139,7 +139,7 @@ describe("Event revision code settings", () => {
139
139
  ...revision.settings,
140
140
  codes: {
141
141
  scripts: [{ type: "bla" }],
142
- structured_data: { type: "event" },
142
+ structured_json: { type: "event" },
143
143
  },
144
144
  },
145
145
  },
@@ -0,0 +1,142 @@
1
+ import Factory from "../../../support/factory";
2
+ import EventRevisions from "../../../../cloud/EventRevisions";
3
+ import LocksHandler from "../../../../handlers/event_revisions/LocksHandler";
4
+
5
+ function buildCtx(revision, lockSettings) {
6
+ return {
7
+ client: {
8
+ eventRevisions: new EventRevisions(() => ({}), "token"),
9
+ },
10
+ params: { parent_id: revision.id },
11
+ resourceParams: {
12
+ resource: lockSettings,
13
+ },
14
+ locale: "en",
15
+ resourceConfig: {
16
+ eventType: "event",
17
+ eventTypePlural: "events",
18
+ },
19
+ };
20
+ }
21
+
22
+ describe("Event revision lock ", () => {
23
+ test("lock successful", async () => {
24
+ const revision = Factory.build("event_revision");
25
+ const lockSettings = { message: "Some lock message" };
26
+ const ctx = buildCtx(revision, lockSettings);
27
+
28
+ const mockFind = jest
29
+ .spyOn(ctx.client.eventRevisions, "find")
30
+ .mockImplementation(() => revision);
31
+
32
+ const mockLock = jest
33
+ .spyOn(ctx.client.eventRevisions, "lock")
34
+ .mockImplementation(() => ({
35
+ revision,
36
+ errors: null,
37
+ eventErrors: null,
38
+ }));
39
+
40
+ const result = await LocksHandler.create(ctx);
41
+
42
+ expect(mockFind).toHaveBeenCalledWith(revision.id, "en");
43
+ expect(mockLock).toHaveBeenCalledWith(
44
+ revision.id,
45
+ "en",
46
+ lockSettings.message
47
+ );
48
+
49
+ expect(result).toEqual({
50
+ redirect: `/en/events/${revision.originalId}`,
51
+ });
52
+ });
53
+
54
+ test("lock failed with errors", async () => {
55
+ const revision = Factory.build("event_revision");
56
+ const lockSettings = { message: "" };
57
+ const ctx = buildCtx(revision, lockSettings);
58
+ const errors = [{ key: "message", message: "Cannot be blank" }];
59
+
60
+ const mockFind = jest
61
+ .spyOn(ctx.client.eventRevisions, "find")
62
+ .mockImplementation(() => revision);
63
+
64
+ const mockLock = jest
65
+ .spyOn(ctx.client.eventRevisions, "lock")
66
+ .mockImplementation(() => ({
67
+ revision: null,
68
+ errors,
69
+ eventErrors: null,
70
+ }));
71
+
72
+ const result = await LocksHandler.create(ctx);
73
+
74
+ expect(mockFind).toHaveBeenCalledWith(revision.id, "en");
75
+ expect(mockLock).toHaveBeenCalledWith(
76
+ revision.id,
77
+ "en",
78
+ lockSettings.message
79
+ );
80
+
81
+ expect(result).toEqual({
82
+ assigns: {
83
+ resource: {
84
+ id: revision.id,
85
+ originalId: revision.originalId,
86
+ message: lockSettings.message,
87
+ },
88
+ errors: {
89
+ resource: { message: "Cannot be blank" },
90
+ },
91
+ _translations: [],
92
+ },
93
+ });
94
+ });
95
+
96
+ test("lock failed with event errors", async () => {
97
+ const revision = Factory.build("event_revision");
98
+ const lockSettings = { message: "Some lock message" };
99
+ const ctx = buildCtx(revision, lockSettings);
100
+ const eventErrors = [
101
+ { key: "generalError", message: "Failed to lock revision" },
102
+ ];
103
+
104
+ const mockFind = jest
105
+ .spyOn(ctx.client.eventRevisions, "find")
106
+ .mockImplementation(() => revision);
107
+
108
+ const mockLock = jest
109
+ .spyOn(ctx.client.eventRevisions, "lock")
110
+ .mockImplementation(() => ({
111
+ revision: null,
112
+ errors: null,
113
+ eventErrors,
114
+ }));
115
+
116
+ await expect(LocksHandler.create(ctx)).rejects.toThrow(
117
+ `Failed to lock revision: ${JSON.stringify(eventErrors)}`
118
+ );
119
+
120
+ expect(mockFind).toHaveBeenCalledWith(revision.id, "en");
121
+ expect(mockLock).toHaveBeenCalledWith(
122
+ revision.id,
123
+ "en",
124
+ lockSettings.message
125
+ );
126
+ });
127
+
128
+ test("create for non existing event revision", async () => {
129
+ const lockSettings = { message: "Some lock message" };
130
+ const ctx = buildCtx({ id: 42 }, lockSettings);
131
+
132
+ const mockFind = jest
133
+ .spyOn(ctx.client.eventRevisions, "find")
134
+ .mockImplementation(() => null);
135
+
136
+ await expect(LocksHandler.create(ctx)).rejects.toThrow(
137
+ `Missing revision #42`
138
+ );
139
+
140
+ expect(mockFind).toHaveBeenCalledWith(42, "en");
141
+ });
142
+ });
@@ -0,0 +1,55 @@
1
+ import Factory from "../../../support/factory";
2
+ import EventRevisions from "../../../../cloud/EventRevisions";
3
+ import LocksHandler from "../../../../handlers/event_revisions/LocksHandler";
4
+
5
+ function buildCtx(revision) {
6
+ return {
7
+ client: {
8
+ eventRevisions: new EventRevisions(() => ({}), "token"),
9
+ },
10
+ params: { parent_id: revision.id },
11
+ locale: "en",
12
+ };
13
+ }
14
+
15
+ describe("New event revision lock", () => {
16
+ test("create_form for locking event revision", async () => {
17
+ const revision = Factory.build("event_revision");
18
+ const ctx = buildCtx(revision);
19
+
20
+ const mockFind = jest
21
+ .spyOn(ctx.client.eventRevisions, "find")
22
+ .mockImplementation(() => revision);
23
+
24
+ const result = await LocksHandler.create_form(ctx);
25
+
26
+ expect(mockFind).toHaveBeenCalledWith(revision.id, "en");
27
+
28
+ expect(result).toEqual({
29
+ assigns: {
30
+ resource: {
31
+ id: revision.id,
32
+ originalId: revision.originalId,
33
+ message: "",
34
+ },
35
+ errors: {},
36
+ _translations: [],
37
+ },
38
+ });
39
+ });
40
+
41
+ test("create_form for non existing event revision", async () => {
42
+ const nonExistentRevision = Factory.build("event_revision");
43
+ const ctx = buildCtx(nonExistentRevision);
44
+
45
+ const mockFind = jest
46
+ .spyOn(ctx.client.eventRevisions, "find")
47
+ .mockImplementation(() => null);
48
+
49
+ await expect(LocksHandler.create_form(ctx)).rejects.toThrow(
50
+ `Missing revision #${nonExistentRevision.id}`
51
+ );
52
+
53
+ expect(mockFind).toHaveBeenCalledWith(nonExistentRevision.id, "en");
54
+ });
55
+ });
@@ -0,0 +1,84 @@
1
+ import Factory from "../../../support/factory";
2
+ import EventRevisions from "../../../../cloud/EventRevisions";
3
+ import UnlocksHandler from "../../../../handlers/event_revisions/UnlocksHandler";
4
+
5
+ function buildCtx(revision) {
6
+ return {
7
+ client: {
8
+ eventRevisions: new EventRevisions(() => ({}), "token"),
9
+ },
10
+ params: { parent_id: revision.id },
11
+ locale: "en",
12
+ resourceConfig: {
13
+ eventType: "event",
14
+ eventTypePlural: "events",
15
+ },
16
+ };
17
+ }
18
+
19
+ describe("Event revision unlock", () => {
20
+ test("unlock successful", async () => {
21
+ const revision = Factory.build("event_revision");
22
+ const ctx = buildCtx(revision);
23
+
24
+ const mockUnlock = jest
25
+ .spyOn(ctx.client.eventRevisions, "unlock")
26
+ .mockImplementation(() => ({
27
+ revision: revision,
28
+ errors: null,
29
+ eventErrors: null,
30
+ }));
31
+
32
+ const result = await UnlocksHandler.create(ctx);
33
+
34
+ expect(mockUnlock).toHaveBeenCalledWith(revision.id, "en");
35
+
36
+ expect(result).toEqual({
37
+ redirect: `/en/events/${revision.originalId}`,
38
+ });
39
+ });
40
+
41
+ test("unlock failed with errors", async () => {
42
+ const revision = Factory.build("event_revision");
43
+ const ctx = buildCtx(revision);
44
+ const errors = [
45
+ { key: "generalError", message: "Failed to unlock revision" },
46
+ ];
47
+
48
+ const mockUnlock = jest
49
+ .spyOn(ctx.client.eventRevisions, "unlock")
50
+ .mockImplementation(() => ({
51
+ revision: null,
52
+ errors,
53
+ eventErrors: null,
54
+ }));
55
+
56
+ await expect(UnlocksHandler.create(ctx)).rejects.toThrow(
57
+ `Failed to unlock revision: ${JSON.stringify(errors)}`
58
+ );
59
+
60
+ expect(mockUnlock).toHaveBeenCalledWith(revision.id, "en");
61
+ });
62
+
63
+ test("unlock failed with event errors", async () => {
64
+ const revision = Factory.build("event_revision");
65
+ const ctx = buildCtx(revision);
66
+ const eventErrors = [
67
+ { key: "generalError", message: "Failed to start revision" },
68
+ ];
69
+
70
+ const mockUnlock = jest
71
+ .spyOn(ctx.client.eventRevisions, "unlock")
72
+ .mockImplementation(() => ({
73
+ revision: null,
74
+ errors: null,
75
+ eventErrors,
76
+ }));
77
+
78
+ await expect(UnlocksHandler.create(ctx)).rejects.toThrow(
79
+ `Failed to start revision: ${JSON.stringify(eventErrors)}`
80
+ );
81
+
82
+ expect(mockUnlock).toHaveBeenCalledWith(revision.id, "en");
83
+ });
84
+ });
@@ -18,7 +18,7 @@ describe("Page revision code settings", () => {
18
18
  const revision = Factory.build("page_revision", {
19
19
  settings: {
20
20
  codes: {
21
- structured_data: {},
21
+ structured_json: {},
22
22
  scripts: [],
23
23
  },
24
24
  },
@@ -28,7 +28,7 @@ describe("Page revision code settings", () => {
28
28
  settings: {
29
29
  codes: {
30
30
  scripts: JSON.stringify([{ type: "bla" }]),
31
- structured_data: JSON.stringify({ type: "article" }),
31
+ structured_json: JSON.stringify({ type: "article" }),
32
32
  },
33
33
  },
34
34
  };
@@ -60,7 +60,7 @@ describe("Page revision code settings", () => {
60
60
  ...revision.settings,
61
61
  codes: {
62
62
  scripts: [{ type: "bla" }],
63
- structured_data: { type: "article" },
63
+ structured_json: { type: "article" },
64
64
  },
65
65
  },
66
66
  });
@@ -77,7 +77,7 @@ describe("Page revision code settings", () => {
77
77
  settings: {
78
78
  codes: {
79
79
  scripts: JSON.stringify([{ type: "bla" }]),
80
- structured_data: JSON.stringify({ type: "article" }),
80
+ structured_json: JSON.stringify({ type: "article" }),
81
81
  },
82
82
  },
83
83
  };
@@ -109,7 +109,7 @@ describe("Page revision code settings", () => {
109
109
  ...revision.settings,
110
110
  codes: {
111
111
  scripts: [{ type: "bla" }],
112
- structured_data: { type: "article" },
112
+ structured_json: { type: "article" },
113
113
  },
114
114
  },
115
115
  });
@@ -122,7 +122,7 @@ describe("Page revision code settings", () => {
122
122
  ...revision.settings,
123
123
  codes: {
124
124
  scripts: [{ type: "bla" }],
125
- structured_data: { type: "article" },
125
+ structured_json: { type: "article" },
126
126
  },
127
127
  },
128
128
  },
@@ -0,0 +1,138 @@
1
+ import Factory from "../../../support/factory";
2
+ import PageRevisions from "../../../../cloud/PageRevisions";
3
+ import LocksHandler from "../../../../handlers/page_revisions/LocksHandler";
4
+
5
+ function buildCtx(revision, lockSettings) {
6
+ return {
7
+ client: {
8
+ pageRevisions: new PageRevisions(() => ({}), "token"),
9
+ },
10
+ params: { parent_id: revision.id },
11
+ resourceParams: {
12
+ resource: lockSettings,
13
+ },
14
+ locale: "en",
15
+ resourceConfig: {
16
+ pageType: "page",
17
+ pageTypePlural: "pages",
18
+ },
19
+ };
20
+ }
21
+
22
+ describe("Page revision lock ", () => {
23
+ test("lock successful", async () => {
24
+ const revision = Factory.build("page_revision");
25
+ const lockSettings = { message: "Some lock message" };
26
+ const ctx = buildCtx(revision, lockSettings);
27
+
28
+ const mockFind = jest
29
+ .spyOn(ctx.client.pageRevisions, "find")
30
+ .mockImplementation(() => revision);
31
+
32
+ const mockLock = jest
33
+ .spyOn(ctx.client.pageRevisions, "lock")
34
+ .mockImplementation(() => ({
35
+ revision,
36
+ errors: null,
37
+ pageErrors: null,
38
+ }));
39
+
40
+ const result = await LocksHandler.create(ctx);
41
+
42
+ expect(mockFind).toHaveBeenCalledWith(revision.id, "en");
43
+ expect(mockLock).toHaveBeenCalledWith(
44
+ revision.id,
45
+ "en",
46
+ lockSettings.message
47
+ );
48
+
49
+ expect(result).toEqual({
50
+ redirect: `/en/pages/${revision.originalId}`,
51
+ });
52
+ });
53
+
54
+ test("lock failed with errors", async () => {
55
+ const revision = Factory.build("page_revision");
56
+ const lockSettings = { message: "" };
57
+ const ctx = buildCtx(revision, lockSettings);
58
+ const errors = [{ key: "message", message: "Cannot be blank" }];
59
+
60
+ const mockFind = jest
61
+ .spyOn(ctx.client.pageRevisions, "find")
62
+ .mockImplementation(() => revision);
63
+
64
+ const mockLock = jest
65
+ .spyOn(ctx.client.pageRevisions, "lock")
66
+ .mockImplementation(() => ({ revision: null, errors, pageErrors: null }));
67
+
68
+ const result = await LocksHandler.create(ctx);
69
+
70
+ expect(mockFind).toHaveBeenCalledWith(revision.id, "en");
71
+ expect(mockLock).toHaveBeenCalledWith(
72
+ revision.id,
73
+ "en",
74
+ lockSettings.message
75
+ );
76
+
77
+ expect(result).toEqual({
78
+ assigns: {
79
+ resource: {
80
+ id: revision.id,
81
+ originalId: revision.originalId,
82
+ message: lockSettings.message,
83
+ },
84
+ errors: {
85
+ resource: { message: "Cannot be blank" },
86
+ },
87
+ _translations: [],
88
+ },
89
+ });
90
+ });
91
+
92
+ test("lock failed with page errors", async () => {
93
+ const revision = Factory.build("page_revision");
94
+ const lockSettings = { message: "Some lock message" };
95
+ const ctx = buildCtx(revision, lockSettings);
96
+ const pageErrors = [
97
+ { key: "generalError", message: "Failed to lock revision" },
98
+ ];
99
+
100
+ const mockFind = jest
101
+ .spyOn(ctx.client.pageRevisions, "find")
102
+ .mockImplementation(() => revision);
103
+
104
+ const mockLock = jest
105
+ .spyOn(ctx.client.pageRevisions, "lock")
106
+ .mockImplementation(() => ({
107
+ revision: null,
108
+ errors: null,
109
+ pageErrors,
110
+ }));
111
+
112
+ await expect(LocksHandler.create(ctx)).rejects.toThrow(
113
+ `Failed to lock revision: ${JSON.stringify(pageErrors)}`
114
+ );
115
+
116
+ expect(mockFind).toHaveBeenCalledWith(revision.id, "en");
117
+ expect(mockLock).toHaveBeenCalledWith(
118
+ revision.id,
119
+ "en",
120
+ lockSettings.message
121
+ );
122
+ });
123
+
124
+ test("create for non existing page revision", async () => {
125
+ const lockSettings = { message: "Some lock message" };
126
+ const ctx = buildCtx({ id: 42 }, lockSettings);
127
+
128
+ const mockFind = jest
129
+ .spyOn(ctx.client.pageRevisions, "find")
130
+ .mockImplementation(() => null);
131
+
132
+ await expect(LocksHandler.create(ctx)).rejects.toThrow(
133
+ `Missing revision #42`
134
+ );
135
+
136
+ expect(mockFind).toHaveBeenCalledWith(42, "en");
137
+ });
138
+ });