@localazy/strapi-plugin 0.1.0

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 (150) hide show
  1. package/.babelrc +7 -0
  2. package/.eslintrc +7 -0
  3. package/.github/workflows/.build.yml +39 -0
  4. package/.nvmrc +1 -0
  5. package/LICENSE +21 -0
  6. package/README.md +40 -0
  7. package/admin/src/.eslintrc +3 -0
  8. package/admin/src/components/Initializer/index.js +26 -0
  9. package/admin/src/components/PluginIcon/index.js +14 -0
  10. package/admin/src/i18n.js +37 -0
  11. package/admin/src/index.js +106 -0
  12. package/admin/src/modules/@common/components/Icons/Localazy/index.js +12 -0
  13. package/admin/src/modules/@common/components/SideNav/index.js +46 -0
  14. package/admin/src/modules/@common/components/TransferReport/index.js +54 -0
  15. package/admin/src/modules/@common/locale/en.js +13 -0
  16. package/admin/src/modules/@common/services/i18n-service.js +15 -0
  17. package/admin/src/modules/@common/services/project-service.js +15 -0
  18. package/admin/src/modules/@common/services/user-service.js +38 -0
  19. package/admin/src/modules/@common/utils/are-locales-compatible.js +42 -0
  20. package/admin/src/modules/@common/utils/functions/flatten-deep.js +23 -0
  21. package/admin/src/modules/@common/utils/get-default-locale.js +32 -0
  22. package/admin/src/modules/@common/utils/get-header-subtitle.js +21 -0
  23. package/admin/src/modules/@common/utils/get-header-title.js +24 -0
  24. package/admin/src/modules/@common/utils/get-nav.js +35 -0
  25. package/admin/src/modules/@common/utils/history.js +6 -0
  26. package/admin/src/modules/@common/utils/is-plugin-route.js +15 -0
  27. package/admin/src/modules/@common/utils/iso-locales-utils.js +15 -0
  28. package/admin/src/modules/@common/utils/redirect-to-plugin-route.js +22 -0
  29. package/admin/src/modules/@common/utils/sort-by-model-name.js +10 -0
  30. package/admin/src/modules/localazy-download/locale/en.js +20 -0
  31. package/admin/src/modules/localazy-download/services/localazy-download-service.js +16 -0
  32. package/admin/src/modules/localazy-upload/components/ReadDocsButton.js +21 -0
  33. package/admin/src/modules/localazy-upload/locale/en.js +18 -0
  34. package/admin/src/modules/localazy-upload/services/localazy-upload-service.js +16 -0
  35. package/admin/src/modules/login/components/LoginButton/index.js +56 -0
  36. package/admin/src/modules/login/components/LogoutButton/index.js +50 -0
  37. package/admin/src/modules/login/locale/en.js +7 -0
  38. package/admin/src/modules/login/services/localazy-login-service.js +29 -0
  39. package/admin/src/modules/plugin-settings/components/ContentTransferSetup/index.js +292 -0
  40. package/admin/src/modules/plugin-settings/components/Tree/index.js +120 -0
  41. package/admin/src/modules/plugin-settings/components/TreeItem/index.js +48 -0
  42. package/admin/src/modules/plugin-settings/functions/build-content-transfer-setup-schema.js +71 -0
  43. package/admin/src/modules/plugin-settings/functions/has-model-changed.js +85 -0
  44. package/admin/src/modules/plugin-settings/locale/en.js +19 -0
  45. package/admin/src/modules/plugin-settings/services/plugin-settings-service.js +32 -0
  46. package/admin/src/modules/plugin-settings/services/strapi-model-service.js +26 -0
  47. package/admin/src/modules/plugin-settings/utils/__tests__/get-models-tree.test.js +135 -0
  48. package/admin/src/modules/plugin-settings/utils/array-of-models-to-object.js +6 -0
  49. package/admin/src/modules/plugin-settings/utils/find-model-value-by-key.js +8 -0
  50. package/admin/src/modules/plugin-settings/utils/get-filtered-models-schemas.js +34 -0
  51. package/admin/src/modules/plugin-settings/utils/get-models-tree.js +73 -0
  52. package/admin/src/modules/settings/components/OverviewItem/index.js +44 -0
  53. package/admin/src/modules/settings/components/OverviewItemLink/index.js +34 -0
  54. package/admin/src/modules/settings/components/PrerequisitiesInfo/index.js +30 -0
  55. package/admin/src/modules/settings/locale/en.js +13 -0
  56. package/admin/src/modules/user/model/localazy-identity.js +14 -0
  57. package/admin/src/modules/user/services/localazy-user-service.js +38 -0
  58. package/admin/src/pages/App/index.js +152 -0
  59. package/admin/src/pages/Download/index.js +179 -0
  60. package/admin/src/pages/Index/index.js +8 -0
  61. package/admin/src/pages/Login/index.js +94 -0
  62. package/admin/src/pages/PluginSettings/index.js +42 -0
  63. package/admin/src/pages/Settings/index.js +120 -0
  64. package/admin/src/pages/Upload/index.js +187 -0
  65. package/admin/src/pluginId.js +5 -0
  66. package/admin/src/plugins/apolloClient.js +33 -0
  67. package/admin/src/state/localazy-identity.js +29 -0
  68. package/admin/src/tests/fixtures/all-models.js +877 -0
  69. package/admin/src/tests/fixtures/restaurant-model.js +230 -0
  70. package/admin/src/translations/en.json +4 -0
  71. package/admin/src/translations/fr.json +1 -0
  72. package/admin/src/utils/createAxiosInstance.js +52 -0
  73. package/admin/src/utils/getTrad.js +5 -0
  74. package/jest.config.js +0 -0
  75. package/package.json +60 -0
  76. package/server/bootstrap.js +5 -0
  77. package/server/config/development/index.js +15 -0
  78. package/server/config/example/index.js +15 -0
  79. package/server/config/index.js +15 -0
  80. package/server/config/production/index.js +16 -0
  81. package/server/config/schema.graphql.js +21 -0
  82. package/server/content-types/index.js +3 -0
  83. package/server/controllers/index.js +19 -0
  84. package/server/controllers/localazy-auth-controller.js +46 -0
  85. package/server/controllers/localazy-project-controller.js +21 -0
  86. package/server/controllers/localazy-transfer-controller.js +469 -0
  87. package/server/controllers/localazy-user-controller.js +24 -0
  88. package/server/controllers/my-controller.js +10 -0
  89. package/server/controllers/plugin-settings-controller.js +17 -0
  90. package/server/controllers/strapi-controller.js +16 -0
  91. package/server/db/model/content-transfer-setup.js +13 -0
  92. package/server/db/model/localazy-user.js +23 -0
  93. package/server/db/model/utils/get-strapi-store.js +9 -0
  94. package/server/destroy.js +5 -0
  95. package/server/index.js +25 -0
  96. package/server/middlewares/index.js +3 -0
  97. package/server/policies/index.js +3 -0
  98. package/server/register.js +5 -0
  99. package/server/routes/index.js +26 -0
  100. package/server/routes/localazy-auth.js +22 -0
  101. package/server/routes/localazy-project.js +14 -0
  102. package/server/routes/localazy-transfer.js +22 -0
  103. package/server/routes/localazy-user.js +30 -0
  104. package/server/routes/plugin-settings.js +22 -0
  105. package/server/routes/strapi.js +22 -0
  106. package/server/services/index.js +21 -0
  107. package/server/services/localazy-auth-service.js +38 -0
  108. package/server/services/localazy-download-service.js +54 -0
  109. package/server/services/localazy-pubapi-service.js +47 -0
  110. package/server/services/localazy-upload-service.js +95 -0
  111. package/server/services/localazy-user-service.js +29 -0
  112. package/server/services/plugin-settings-service.js +30 -0
  113. package/server/services/strapi-i18n-service.js +132 -0
  114. package/server/services/strapi-service.js +23 -0
  115. package/server/tests/fixtures/all-models-with-multimedia.js +1064 -0
  116. package/server/tests/fixtures/all-models.js +869 -0
  117. package/server/tests/fixtures/collection-flattened.js +76 -0
  118. package/server/tests/fixtures/restaurant-flattened.js +46 -0
  119. package/server/tests/fixtures/restaurant-model.js +230 -0
  120. package/server/tests/fixtures/restaurants-entries.js +152 -0
  121. package/server/tests/fixtures/restaurants-pick-paths.js +15 -0
  122. package/server/tests/fixtures/strapi-book-with-multimedia-components-cs.js +31 -0
  123. package/server/tests/fixtures/stringified-book-cs.js +3 -0
  124. package/server/tests/fixtures/stringified-book-with-multimedia-components-cs.js +3 -0
  125. package/server/tests/fixtures/stringified-restaurant-cs.js +3 -0
  126. package/server/tests/fixtures/stringified-restaurant-de.js +5 -0
  127. package/server/utils/__tests__/build-populate.test.js +85 -0
  128. package/server/utils/__tests__/flatten-object.test.js +171 -0
  129. package/server/utils/__tests__/get-models-tree.test.js +170 -0
  130. package/server/utils/__tests__/parsed-localazy-entry-to-create-entry.test.js +153 -0
  131. package/server/utils/__tests__/parsed-localazy-entry-to-update-entry.test.js +172 -0
  132. package/server/utils/__tests__/pick-entries.test.js +83 -0
  133. package/server/utils/build-populate.js +43 -0
  134. package/server/utils/delay.js +6 -0
  135. package/server/utils/flatten-object.js +52 -0
  136. package/server/utils/get-localazy-api.js +22 -0
  137. package/server/utils/get-main-keys-of-nested-array-objects.js +5 -0
  138. package/server/utils/get-models-tree.js +43 -0
  139. package/server/utils/intl-display-name.js +7 -0
  140. package/server/utils/is-generally-applicable-content-type.js +33 -0
  141. package/server/utils/is-localazy-applicable-content-type.js +36 -0
  142. package/server/utils/iso-locales-utils.js +22 -0
  143. package/server/utils/objectivise-entry.js +41 -0
  144. package/server/utils/omit-deep.js +17 -0
  145. package/server/utils/parsed-localazy-entry-to-create-entry.js +115 -0
  146. package/server/utils/parsed-localazy-entry-to-update-entry.js +31 -0
  147. package/server/utils/pick-entries.js +14 -0
  148. package/server/utils/transfer-setup-utils.js +39 -0
  149. package/strapi-admin.js +14 -0
  150. package/strapi-server.js +5 -0
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+
3
+ const flattenObject = require("../flatten-object");
4
+
5
+ it("should filter out null and undefined values", () => {
6
+ // SETUP
7
+ const object = {
8
+ restaurant: null,
9
+ somethingElse: undefined,
10
+ somethingSomethingElse: false,
11
+ };
12
+
13
+ // EXECUTE
14
+ const result = flattenObject(object);
15
+
16
+ // VERIFY
17
+ const expected = { somethingSomethingElse: false };
18
+ expect(result).toEqual(expected);
19
+ });
20
+
21
+ it("should return the same object if it's already flat", () => {
22
+ // SETUP
23
+ const object = {
24
+ restaurant: {
25
+ id: 2,
26
+ foo: "bar",
27
+ baz: "qux",
28
+ },
29
+ };
30
+
31
+ // EXECUTE
32
+ const result = flattenObject(object);
33
+
34
+ // VERIFY
35
+ const expected = {
36
+ "restaurant[2].foo": "bar",
37
+ "restaurant[2].baz": "qux",
38
+ };
39
+ expect(result).toEqual(expected);
40
+ });
41
+
42
+ it("should use the index of the array if there is no id", () => {
43
+ // SETUP
44
+ const object = {
45
+ restaurant: [{ foo: "bar" }, { baz: "qux" }],
46
+ };
47
+
48
+ // EXECUTE
49
+ const result = flattenObject(object);
50
+
51
+ // VERIFY
52
+ const expected = {
53
+ "restaurant[0].foo": "bar",
54
+ "restaurant[1].baz": "qux",
55
+ };
56
+ expect(result).toEqual(expected);
57
+ });
58
+
59
+ it("should work with a basic array", () => {
60
+ // SETUP
61
+ const object = {
62
+ restaurant: [
63
+ {
64
+ id: 1,
65
+ arrayFoo1: "arrayBar1",
66
+ arrayBaz1: "arrayFaz1",
67
+ },
68
+ {
69
+ id: 2,
70
+ arrayFoo2: "arrayBar2",
71
+ },
72
+ ],
73
+ };
74
+
75
+ // EXECUTE
76
+ const result = flattenObject(object);
77
+
78
+ // VERIFY
79
+ const expected = {
80
+ "restaurant[1].arrayFoo1": "arrayBar1",
81
+ "restaurant[1].arrayBaz1": "arrayFaz1",
82
+ "restaurant[2].arrayFoo2": "arrayBar2",
83
+ };
84
+
85
+ expect(result).toEqual(expected);
86
+ });
87
+
88
+ it("should return nested flattened object", () => {
89
+ // SETUP
90
+ const object = {
91
+ restaurant: {
92
+ id: 2,
93
+ foo: "bar",
94
+ baz: "qux",
95
+ someArray: [
96
+ {
97
+ id: 1,
98
+ arrayFoo1: "arrayBar1",
99
+ },
100
+ {
101
+ id: 2,
102
+ arrayFoo2: "arrayBar2",
103
+ },
104
+ {
105
+ id: 42,
106
+ arrayFoo42: "arrayBar42",
107
+ arrayBoo42: "arrayFar42",
108
+ },
109
+ ],
110
+ },
111
+ };
112
+
113
+ // EXECUTE
114
+ const result = flattenObject(object);
115
+
116
+ // VERIFY
117
+ const expected = {
118
+ "restaurant[2].foo": "bar",
119
+ "restaurant[2].baz": "qux",
120
+ "restaurant[2].someArray[1].arrayFoo1": "arrayBar1",
121
+ "restaurant[2].someArray[2].arrayFoo2": "arrayBar2",
122
+ "restaurant[2].someArray[42].arrayFoo42": "arrayBar42",
123
+ "restaurant[2].someArray[42].arrayBoo42": "arrayFar42",
124
+ };
125
+
126
+ expect(result).toEqual(expected);
127
+ });
128
+
129
+ it("should work for quite complicated structures nested", () => {
130
+ // SETUP
131
+ const object = {
132
+ restaurant: {
133
+ id: 2,
134
+ someArray: [
135
+ {
136
+ id: 1,
137
+ arrayFoo1: "arrayBar1",
138
+ },
139
+ {
140
+ id: 2,
141
+ arrayFoo2: "arrayBar2",
142
+ },
143
+ {
144
+ id: 42,
145
+ arrayFoo42: "arrayBar42",
146
+ arrayBoo42: "arrayFar42",
147
+ subRestaurant: {
148
+ id: 102,
149
+ arrayFoo102: "arrayBar102",
150
+ arrayBoo102: "arrayFar102",
151
+ },
152
+ },
153
+ ],
154
+ },
155
+ };
156
+
157
+ // EXECUTE
158
+ const result = flattenObject(object);
159
+
160
+ // VERIFY
161
+ const expected = {
162
+ "restaurant[2].someArray[1].arrayFoo1": "arrayBar1",
163
+ "restaurant[2].someArray[2].arrayFoo2": "arrayBar2",
164
+ "restaurant[2].someArray[42].arrayFoo42": "arrayBar42",
165
+ "restaurant[2].someArray[42].arrayBoo42": "arrayFar42",
166
+ "restaurant[2].someArray[42].subRestaurant[102].arrayFoo102": "arrayBar102",
167
+ "restaurant[2].someArray[42].subRestaurant[102].arrayBoo102": "arrayFar102",
168
+ };
169
+
170
+ expect(result).toEqual(expected);
171
+ });
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+
3
+ const getModelsTree = require("../get-models-tree");
4
+ const allModels = require("../../tests/fixtures/all-models");
5
+
6
+ it("should return the tree for restaurants", () => {
7
+ // SETUP
8
+ const object = allModels;
9
+
10
+ // EXECUTE
11
+ const result = getModelsTree(object);
12
+
13
+ // VERIFY
14
+ const restaurantModelsTree = result.find((model) => model.restaurants);
15
+ const expected = {
16
+ restaurants: {
17
+ __model__: true,
18
+ title: false,
19
+ description: false,
20
+ books: null,
21
+ recipes: {
22
+ name: false,
23
+ ingredients: {
24
+ name: false,
25
+ pcs: null,
26
+ required: null,
27
+ },
28
+ variants: {
29
+ name: false,
30
+ },
31
+ },
32
+ descs: {
33
+ rich_description: false,
34
+ history: false,
35
+ excerpt: false,
36
+ test_variants: {
37
+ name: false,
38
+ },
39
+ },
40
+ street: false,
41
+ city: false,
42
+ country: false,
43
+ },
44
+ };
45
+ expect(restaurantModelsTree).toEqual(expected);
46
+ });
47
+
48
+ it("should return a tree all all models", () => {
49
+ // SETUP
50
+ const object = allModels;
51
+
52
+ // EXECUTE
53
+ const result = getModelsTree(object);
54
+
55
+ // VERIFY
56
+ const expected = [
57
+ {
58
+ tokens: {
59
+ __model__: true,
60
+ access_token: false,
61
+ },
62
+ },
63
+ {
64
+ testtokens: {
65
+ __model__: true,
66
+ at: false,
67
+ },
68
+ },
69
+ {
70
+ up_users: {
71
+ __model__: true,
72
+ username: false,
73
+ email: null,
74
+ provider: false,
75
+ password: null,
76
+ resetPasswordToken: false,
77
+ confirmationToken: false,
78
+ confirmed: null,
79
+ blocked: null,
80
+ role: null,
81
+ },
82
+ },
83
+ {
84
+ books: {
85
+ __model__: true,
86
+ Title: false,
87
+ Author: false,
88
+ Pages: null,
89
+ additional_info: {
90
+ rich_description: false,
91
+ history: false,
92
+ excerpt: false,
93
+ test_variants: {
94
+ name: false,
95
+ },
96
+ },
97
+ },
98
+ },
99
+ {
100
+ restaurants: {
101
+ __model__: true,
102
+ title: false,
103
+ description: false,
104
+ books: null,
105
+ recipes: {
106
+ name: false,
107
+ ingredients: {
108
+ name: false,
109
+ pcs: null,
110
+ required: null,
111
+ },
112
+ variants: {
113
+ name: false,
114
+ },
115
+ },
116
+ descs: {
117
+ rich_description: false,
118
+ history: false,
119
+ excerpt: false,
120
+ test_variants: {
121
+ name: false,
122
+ },
123
+ },
124
+ street: false,
125
+ city: false,
126
+ country: false,
127
+ },
128
+ },
129
+ {
130
+ components_food_ingredient_variants: {
131
+ __model__: true,
132
+ name: false,
133
+ },
134
+ },
135
+ {
136
+ components_food_ingredients: {
137
+ __model__: true,
138
+ name: false,
139
+ pcs: null,
140
+ required: null,
141
+ },
142
+ },
143
+ {
144
+ components_food_pub_component_1s: {
145
+ __model__: true,
146
+ rich_description: false,
147
+ history: false,
148
+ excerpt: false,
149
+ test_variants: {
150
+ name: false,
151
+ },
152
+ },
153
+ },
154
+ {
155
+ components_food_recipes: {
156
+ __model__: true,
157
+ name: false,
158
+ ingredients: {
159
+ name: false,
160
+ pcs: null,
161
+ required: null,
162
+ },
163
+ variants: {
164
+ name: false,
165
+ },
166
+ },
167
+ },
168
+ ];
169
+ expect(result).toEqual(expected);
170
+ });
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+
3
+ const parsedLocalazyEntryToCreateEntry = require("../parsed-localazy-entry-to-create-entry");
4
+ const allModels = require("../../tests/fixtures/all-models");
5
+ const stringifiedRestaurantCs = require("../../tests/fixtures/stringified-restaurant-cs");
6
+ const stringifiedBookCs = require("../../tests/fixtures/stringified-book-cs");
7
+
8
+ describe("parsed-localazy-entry-to-create-entry.js", () => {
9
+ it("should return transformed restaurant entry to strapi create entry structure", () => {
10
+ // SETUP
11
+ const uid = "api::restaurant.restaurant";
12
+ const entry = JSON.parse(stringifiedRestaurantCs);
13
+
14
+ const locale = "cs";
15
+
16
+ // EXECUTE
17
+ const result = parsedLocalazyEntryToCreateEntry(
18
+ allModels,
19
+ entry,
20
+ uid,
21
+ locale
22
+ );
23
+
24
+ // VERIFY
25
+ const expected = {
26
+ locale: "cs",
27
+ title: "Plná restaurace",
28
+ description: "S nějakým skvělým popisem",
29
+ recipes: [
30
+ // is repeatable - array
31
+ {
32
+ // id: 2,
33
+ __component: "food.recipe",
34
+ name: "Hovězí vývar",
35
+ ingredients: [
36
+ // is repeatable - array
37
+ {
38
+ // id: 4,
39
+ __component: "food.ingredients",
40
+ name: "Hovězí",
41
+ },
42
+ {
43
+ // id: 5,
44
+ __component: "food.ingredients",
45
+ name: "Voda",
46
+ },
47
+ ],
48
+ },
49
+ {
50
+ // id: 3,
51
+ __component: "food.recipe",
52
+ name: "Rajčatová polévka",
53
+ ingredients: [
54
+ // is repeatable - array
55
+ {
56
+ // id: 2,
57
+ __component: "food.ingredients",
58
+ name: "rajče",
59
+ },
60
+ {
61
+ // id: 3,
62
+ __component: "food.ingredients",
63
+ name: "Polévka",
64
+ },
65
+ ],
66
+ variants: {
67
+ // is not repeatable - object
68
+ // id: 4,
69
+ __component: "food.ingredient-variants",
70
+ name: "Červená, žlutá, zelená",
71
+ },
72
+ },
73
+ {
74
+ // id: 4,
75
+ __component: "food.recipe",
76
+ name: "Guláš",
77
+ ingredients: [
78
+ // is repeatable - array
79
+ {
80
+ // id: 6,
81
+ __component: "food.ingredients",
82
+ name: "Hovězí maso",
83
+ },
84
+ {
85
+ // id: 7,
86
+ __component: "food.ingredients",
87
+ name: "Pepř",
88
+ },
89
+ {
90
+ // id: 8,
91
+ __component: "food.ingredients",
92
+ name: "pepř, koření",
93
+ },
94
+ {
95
+ // id: 9,
96
+ __component: "food.ingredients",
97
+ name: "Voda",
98
+ },
99
+ ],
100
+ },
101
+ ],
102
+ descs: {
103
+ // is not repeatable - object
104
+ // id: 3,
105
+ __component: "food.pub-component-1",
106
+ rich_description: "Další restaurace desc",
107
+ history: "Est. 2022, se sídlem v NY, NY",
108
+ excerpt: "Est. 2022",
109
+ test_variants: {
110
+ // is not repeatable - object
111
+ // id: 5,
112
+ __component: "food.ingredient-variants",
113
+ name: "nic takového...",
114
+ },
115
+ },
116
+ };
117
+ expect(result).toEqual(expected);
118
+ });
119
+ it("should return transformed book entry to strapi create entry structure", () => {
120
+ // SETUP
121
+ const uid = "api::book.book";
122
+ const entry = JSON.parse(stringifiedBookCs);
123
+
124
+ const locale = "cs";
125
+
126
+ // EXECUTE
127
+ const result = parsedLocalazyEntryToCreateEntry(
128
+ allModels,
129
+ entry,
130
+ uid,
131
+ locale
132
+ );
133
+
134
+ // VERIFY
135
+ const expected = {
136
+ locale: "cs",
137
+ Title: "Moje první dětská kniha",
138
+ additional_info: {
139
+ __component: "food.pub-component-1",
140
+ rich_description:
141
+ "# H1\n## H2\n#### H4\n\n** Jedna** _dva_ <u>tři</u>... a možná ještě více pohádek...",
142
+ history: "Není tu žádný...",
143
+ excerpt: "Krátký výňatek",
144
+ test_variants: {
145
+ __component: "food.ingredient-variants",
146
+ name: "toto je finální verze",
147
+ },
148
+ },
149
+ };
150
+
151
+ expect(result).toEqual(expected);
152
+ });
153
+ });
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+
3
+ const parsedLocalazyEntryToUpdateEntry = require("../parsed-localazy-entry-to-update-entry");
4
+ const allModelsWithMultimedia = require("../../tests/fixtures/all-models-with-multimedia");
5
+ const allModels = require("../../tests/fixtures/all-models");
6
+ const stringifiedBookCs = require("../../tests/fixtures/stringified-book-with-multimedia-components-cs");
7
+ const stringifiedRestaurantDe = require("../../tests/fixtures/stringified-restaurant-de");
8
+ const currentBookEntry = require("../../tests/fixtures/strapi-book-with-multimedia-components-cs");
9
+ const restaurantsEntries = require("../../tests/fixtures/restaurants-entries");
10
+
11
+ describe("parsed-localazy-entry-to-update-entry.js", () => {
12
+ it("should return transformed book entry to strapi update entry structure", () => {
13
+ // SETUP
14
+ const uid = "api::book.book";
15
+ const entry = JSON.parse(stringifiedBookCs);
16
+
17
+ // EXECUTE
18
+ const result = parsedLocalazyEntryToUpdateEntry(
19
+ allModelsWithMultimedia,
20
+ entry,
21
+ currentBookEntry,
22
+ uid
23
+ );
24
+
25
+ // VERIFY
26
+ const expected = {
27
+ id: 29,
28
+ Title: "Kniha s obálkou 2",
29
+ Author: null,
30
+ Pages: null,
31
+ non_localizable_name: "Non localizable book for kids",
32
+ additional_info: {
33
+ id: 38,
34
+ rich_description: "RD",
35
+ history: "H 2",
36
+ excerpt: "E",
37
+ test_variants: {
38
+ id: 38,
39
+ name: "Nejsou k dispozici žádné varianty, proč?",
40
+ },
41
+ },
42
+ seo_setup: [
43
+ {
44
+ id: 21,
45
+ seo_desc: "nastavení 1",
46
+ main_image: null,
47
+ rest: null,
48
+ },
49
+ {
50
+ id: 22,
51
+ seo_desc: "nastavení 2",
52
+ main_image: null,
53
+ rest: null,
54
+ },
55
+ ],
56
+ };
57
+
58
+ expect(result).toEqual(expected);
59
+ });
60
+ it.only("should return transformed restaurant entry to strapi update entry structure", () => {
61
+ // SETUP
62
+ const uid = "api::restaurant.restaurant";
63
+ const entry = JSON.parse(stringifiedRestaurantDe);
64
+ const currentRestaurantEntry = restaurantsEntries[2];
65
+
66
+ // EXECUTE
67
+ const result = parsedLocalazyEntryToUpdateEntry(
68
+ allModels,
69
+ entry,
70
+ currentRestaurantEntry,
71
+ uid
72
+ );
73
+
74
+ // VERIFY
75
+ const expected = {
76
+ city: "Testow",
77
+ country: "Test Rep.",
78
+ description: "Mit einer großartigen Beschreibung",
79
+ descs: {
80
+ excerpt: "Est. 2022",
81
+ history: "Est. 2022, mit Sitz in NY, NY",
82
+ id: 3,
83
+ rich_description: "Ein weiteres Restaurant desc",
84
+ test_variants: {
85
+ id: 5,
86
+ name: "so etwas nicht...",
87
+ },
88
+ },
89
+ id: 3,
90
+ recipes: [
91
+ {
92
+ id: 3,
93
+ ingredients: [
94
+ {
95
+ id: 2,
96
+ name: "Rindfleisch",
97
+ pcs: 4,
98
+ required: false,
99
+ },
100
+ {
101
+ id: 3,
102
+ name: "Wasser",
103
+ pcs: 1,
104
+ required: true,
105
+ },
106
+ ],
107
+ name: "Rinderbrühe",
108
+ variants: {
109
+ id: 4,
110
+ name: "Red, yellow, green",
111
+ },
112
+ },
113
+ {
114
+ id: 2,
115
+ ingredients: [
116
+ {
117
+ id: 4,
118
+ name: "Tomate",
119
+ pcs: 1,
120
+ required: true,
121
+ },
122
+ {
123
+ id: 5,
124
+ name: "Suppe",
125
+ pcs: 2,
126
+ required: true,
127
+ },
128
+ ],
129
+ name: "Tomatensuppe",
130
+ variants: {
131
+ name: "Rot, gelb, grün",
132
+ },
133
+ },
134
+ {
135
+ id: 4,
136
+ ingredients: [
137
+ {
138
+ id: 6,
139
+ name: "Rindfleisch",
140
+ pcs: 1,
141
+ required: true,
142
+ },
143
+ {
144
+ id: 7,
145
+ name: "Pfeffer",
146
+ pcs: 4,
147
+ required: null,
148
+ },
149
+ {
150
+ id: 8,
151
+ name: "Pfeffer-Gewürze",
152
+ pcs: 1,
153
+ required: true,
154
+ },
155
+ {
156
+ id: 9,
157
+ name: "Wasser",
158
+ pcs: 1,
159
+ required: null,
160
+ },
161
+ ],
162
+ name: "Gulasch",
163
+ variants: null,
164
+ },
165
+ ],
166
+ street: "Testowa",
167
+ title: "Volles Restaurant",
168
+ };
169
+
170
+ expect(result).toEqual(expected);
171
+ });
172
+ });