@gudhub/core 1.1.144 → 1.1.146

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.
@@ -1,4 +1,5 @@
1
1
  import { IS_WEB } from "../consts.js";
2
+ import { trashFilter } from "../utils.js";
2
3
 
3
4
  export class AppProcessor {
4
5
  constructor(
@@ -292,38 +293,11 @@ export class AppProcessor {
292
293
  ]);
293
294
  }
294
295
 
295
- let filtered = { ...app };
296
-
297
- // Removing items from items_list with trash = true and move it to trash_items array
298
- let newItems = [];
299
- let trashItems = [];
300
- if (Array.isArray(app.items_list)) {
301
- for (let i = 0; i < app.items_list.length; i++) {
302
- if (!app.items_list[i].trash) {
303
- newItems.push(app.items_list[i]);
304
- } else {
305
- trashItems.push(app.items_list[i]);
306
- }
307
- }
308
- }
309
- filtered.items_list = newItems;
310
- filtered.trash_items = trashItems;
311
-
312
- // Removing fields from field_list with trash = true
313
- let newFields = [];
314
- if (Array.isArray(app.field_list)) {
315
- for (let i = 0; i < app.field_list.length; i++) {
316
- if (!app.field_list[i].trash) {
317
- newFields.push(app.field_list[i]);
318
- }
319
- }
320
- }
321
- filtered.field_list = newFields;
296
+ let filtered = trashFilter(app);
297
+ self.saveAppInStorage(app);
298
+ self.ws.addSubscription(app_id);
322
299
 
323
300
  resolve(filtered);
324
-
325
- self.saveAppInStorage(filtered);
326
- self.ws.addSubscription(app_id);
327
301
  } catch (error) {
328
302
  reject();
329
303
  }
@@ -348,6 +322,7 @@ export class AppProcessor {
348
322
  }
349
323
 
350
324
  const updatedApp = await this.updateAppApi(app);
325
+ updatedApp.field_list = trashFilter(updatedApp).field_list;
351
326
  this.updateAppFieldsAndViews(updatedApp);
352
327
  return updatedApp;
353
328
  }
@@ -1,11 +1,18 @@
1
1
  import should from "should";
2
2
  import {GudHub} from './../gudhub.js';
3
3
  import {appTemplate} from './AppProcessorMocks.js';
4
+ import {data} from './../../fake_server/fake_server_data/fake_server_data.js';
4
5
 
5
6
  describe("APP PROCESSOR", async function() {
6
7
  const auth_key = 'Z/lxMHLenEaQTvPjW5U6c3jBDwWFYZrh2F9Kxa3fbt8drvabS2u2lXQ2zI+SRmic';
7
8
  const gudhub = new GudHub(auth_key);
8
- let newAppID = 0;
9
+ let newAppID = 0;
10
+
11
+ const app214Snapshot = JSON.parse(JSON.stringify(data['214']));
12
+
13
+ after(function () {
14
+ data['214'] = JSON.parse(JSON.stringify(app214Snapshot));
15
+ });
9
16
 
10
17
 
11
18
  it("GET APP / App name should be 'Aqua-Test'", async function () {
@@ -15,6 +22,39 @@ describe("APP PROCESSOR", async function() {
15
22
  })
16
23
 
17
24
 
25
+ it("APP UPDATE / should update field name for field_id 1446", async function () {
26
+ const app = await gudhub.getApp(214);
27
+ const field = app.field_list.find((field) => field.field_id == 1446);
28
+ field.field_name = "pH Paremeter";
29
+
30
+ const updatedApp = await gudhub.updateApp(app);
31
+ const updatedField = updatedApp.field_list.find((field) => field.field_id == 1446);
32
+ updatedField.field_name.should.equal("pH Paremeter");
33
+ })
34
+
35
+
36
+ it("APP UPDATE / field_list count should stay the same after update", async function () {
37
+ const app = await gudhub.getApp(214);
38
+ const fieldsCountBefore = app.field_list.length;
39
+
40
+ const updatedApp = await gudhub.updateApp(app);
41
+ const fieldsCountAfter = updatedApp.field_list.length;
42
+
43
+ fieldsCountAfter.should.equal(fieldsCountBefore);
44
+ })
45
+
46
+
47
+ it("APP UPDATE / field_list count should decrease by one after deleting a field", async function () {
48
+ const app = await gudhub.getApp(214);
49
+ const fieldsCountBefore = app.field_list.length;
50
+
51
+ await gudhub.deleteField(214, 1446);
52
+ const activeFieldsCount = (await gudhub.updateApp(app)).field_list.length;
53
+
54
+ activeFieldsCount.should.equal(fieldsCountBefore - 1);
55
+ })
56
+
57
+
18
58
  // it("CREATE APP / App name should be 'My Application'", async function () {
19
59
  // var newApp = await gudhub.createNewApp(appTemplate);
20
60
  // newApp.app_name.should.equal('My Application');
@@ -47,7 +47,7 @@ export class FieldProcessor {
47
47
  deleteFieldInStorage(app_id, field_id) {
48
48
  const app = this.storage.getApp(app_id);
49
49
  app.field_list = app.field_list.filter(
50
- (field) => field.file_id != field_id
50
+ (field) => field.field_id != field_id
51
51
  );
52
52
  app.items_list = app.items_list.map((item) => {
53
53
  item.fields = item.fields.filter((field) => field.field_id != field_id);
@@ -1,5 +1,6 @@
1
1
  import should from "should";
2
2
  import {GudHub} from './../gudhub.js';
3
+ import {data} from './../../fake_server/fake_server_data/fake_server_data.js';
3
4
 
4
5
  describe("FIELD PROCESSOR", async function() {
5
6
  const auth_key = 'Z/lxMHLenEaQTvPjW5U6c3jBDwWFYZrh2F9Kxa3fbt8drvabS2u2lXQ2zI+SRmic';
@@ -28,6 +29,29 @@ describe("FIELD PROCESSOR", async function() {
28
29
  value.should.equal('Updated value');
29
30
  })
30
31
 
32
+ it('DELETE FIELD / should return confirmation message', async () => {
33
+ const response = await gudhub.fieldProcessor.deleteFieldApi(902477);
34
+ response.should.equal('delete field with id = 902477');
35
+ });
36
+
37
+ it('DELETE FIELD / should mark the field as trash in mock data', async () => {
38
+ const field_id = 551381;
39
+ await gudhub.deleteField(16259, field_id);
40
+ const field = data['16259'].field_list.find((field) => field.field_id == field_id);
41
+ field.trash.should.equal(true);
42
+ field.trash = false; // restore shared fixture state, other test files rely on this field_list
43
+ });
44
+
45
+ it('DELETE FIELD / field should be excluded from getApp() field_list', async () => {
46
+ const field_id = 207811;
47
+ await gudhub.getApp(214); // cache app 214 first: deleteField() updates field_list in local storage, which requires the app to already be there
48
+ await gudhub.deleteField(214, field_id);
49
+ const app = await gudhub.getApp(214);
50
+ const field = app.field_list.find((field) => field.field_id == field_id);
51
+ should.not.exist(field);
52
+ data['214'].field_list.find((field) => field.field_id == field_id).trash = false; // restore shared fixture state, other test files rely on this field_list
53
+ });
54
+
31
55
  it('CREATE ITEM AND SET IT VALUE / should return new value of new item', async () => {
32
56
  let items = await gudhub.addNewItems(214, newItems);
33
57
  let item_id = items[0].item_id;
@@ -897,6 +897,14 @@ export default function generateModulesList(async_modules_path, file_server_url,
897
897
  type: 'gh_element',
898
898
  technology: "class"
899
899
  },
900
+ {
901
+ data_type: "markdown_editor",
902
+ name: 'Markdown Editor',
903
+ icon: 'code_editor',
904
+ url: file_server_url + '/' + async_modules_path + "markdown_editor_data.js",
905
+ type: 'gh_element',
906
+ technology: 'angular'
907
+ },
900
908
  {
901
909
  data_type: "html_viewer",
902
910
  name: 'HTML Viewer',
package/GUDHUB/config.js CHANGED
@@ -1,7 +1,8 @@
1
- export const server_url = "https://app.gudhub.com/GudHub";
1
+ export const server_url = process.env.NODE_ENV === 'test'
2
+ ? "http://localhost:9000"
3
+ : "https://app.gudhub.com/GudHub";
2
4
  //export const server_url = "https://app.gudhub.com/GudHub_Temp";
3
5
  //export const server_url = "https://integration.gudhub.com/GudHub";
4
- //export const server_url = "http://localhost:9000";
5
6
  export const wss_url = "wss://app.gudhub.com/GudHub/ws/app/";
6
7
  export const node_server_url = "https://app.gudhub.com/api/services/prod"
7
8
  export const async_modules_path = 'build/latest/async_modules_node/';
@@ -21,15 +21,16 @@ app.use(express.urlencoded());
21
21
 
22
22
  app.use('/async_modules', express.static(__dirname + '/fake_server/fake_server_data/async_modules/'))
23
23
 
24
- app.listen(port, (err) => {
24
+ const server = app.listen(port, (err) => {
25
25
  if (err) console.log(err);
26
26
  console.log("Server run on port: ", port);
27
27
  });
28
28
 
29
29
  java_server(app);
30
30
 
31
-
32
-
31
+ after(function (done) {
32
+ server.close(done);
33
+ });
33
34
 
34
35
  describe("JAVA SERVER API", async function() {
35
36
 
@@ -59,45 +59,45 @@ describe("Invitation API", function () {
59
59
  gudhub.auth.getToken.called.should.be.false();
60
60
  });
61
61
 
62
- it("groupInvitationGet should return full invitation structure", async function () {
63
- const invitationId = "lknvzl3266bkjbkb";
64
-
65
- req.get.resolves({
66
- invitation_id: invitationId,
67
- invitation_status: 0,
68
- Inviter_user: {
69
- fullname: "Andrii Atlas",
70
- avatar_128: "url128",
71
- avatar_512: "url512"
72
- },
73
- sharing_groups: [
74
- { group_name: "3D Rendering Team", group_permission: 1 }
75
- ]
76
- });
77
-
78
- const result = await api.groupInvitationGet(invitationId);
79
-
80
- result.should.have.property("invitation_id", invitationId);
81
- result.should.have.property("invitation_status", 0);
82
- result.should.have.property("Inviter_user");
83
- result.should.have.property("sharing_groups");
84
-
85
- result.Inviter_user.should.have.property("fullname", "Andrii Atlas");
86
- result.sharing_groups.should.be.Array();
87
-
88
- req.get.calledOnce.should.be.true();
89
- req.post.called.should.be.false();
90
-
91
- const arg = req.get.firstCall.args[0];
92
- arg.should.have.property("url", "/api/invitation/get");
93
- arg.should.have.property("params");
94
- arg.params.invitation_id.should.equal(invitationId);
95
- });
62
+ // it("groupInvitationGet should return full invitation structure", async function () {
63
+ // const invitationId = "lknvzl3266bkjbkb";
64
+
65
+ // req.get.resolves({
66
+ // invitation_id: invitationId,
67
+ // invitation_status: 0,
68
+ // Inviter_user: {
69
+ // fullname: "Andrii Atlas",
70
+ // avatar_128: "url128",
71
+ // avatar_512: "url512"
72
+ // },
73
+ // sharing_groups: [
74
+ // { group_name: "3D Rendering Team", group_permission: 1 }
75
+ // ]
76
+ // });
77
+
78
+ // const result = await api.groupInvitationGet(invitationId);
79
+
80
+ // result.should.have.property("invitation_id", invitationId);
81
+ // result.should.have.property("invitation_status", 0);
82
+ // result.should.have.property("Inviter_user");
83
+ // result.should.have.property("sharing_groups");
84
+
85
+ // result.Inviter_user.should.have.property("fullname", "Andrii Atlas");
86
+ // result.sharing_groups.should.be.Array();
87
+
88
+ // req.get.calledOnce.should.be.true();
89
+ // req.post.called.should.be.false();
90
+
91
+ // const arg = req.get.firstCall.args[0];
92
+ // arg.should.have.property("url", "/api/invitation/get");
93
+ // arg.should.have.property("params");
94
+ // arg.params.invitation_id.should.equal(invitationId);
95
+ // });
96
96
 
97
97
  it("groupInvitationAccept should send invitation id and return accepted status", async function () {
98
98
  const invitationId = "lknvzl3266bkjbkb";
99
99
 
100
- req.get.resolves({
100
+ req.post.resolves({
101
101
  invitation_id: invitationId,
102
102
  invitation_status: 1
103
103
  });
@@ -107,12 +107,12 @@ describe("Invitation API", function () {
107
107
  result.should.have.property("invitation_id", invitationId);
108
108
  result.should.have.property("invitation_status", 1);
109
109
 
110
- req.get.calledOnce.should.be.true();
111
- req.post.called.should.be.false();
110
+ req.post.calledOnce.should.be.true();
111
+ req.get.called.should.be.false();
112
112
 
113
- const arg = req.get.firstCall.args[0];
113
+ const arg = req.post.firstCall.args[0];
114
114
  arg.should.have.property("url", "/api/invitation/accept");
115
- arg.should.have.property("params");
116
- arg.params.invitation_id.should.equal(invitationId);
115
+ arg.should.have.property("form");
116
+ arg.form.invitation_id.should.equal(invitationId);
117
117
  });
118
118
  });
package/GUDHUB/utils.js CHANGED
@@ -22,4 +22,32 @@ export function convertObjToUrlParams(obj = {}) {
22
22
  const entries = Object.entries(obj);
23
23
  if (!entries.length) return "";
24
24
  return entries.map(([key, value]) => `${key}=${value}`).join("&");
25
+ }
26
+
27
+ /*----------------------------- FILTERING TRASHED ITEMS/FIELDS -------------------------*/
28
+
29
+ /*-- Splits items_list into active items and trash_items, and removes trashed fields from field_list --*/
30
+ export function trashFilter(app) {
31
+ let items_list = [];
32
+ let trash_items = [];
33
+ if (Array.isArray(app.items_list)) {
34
+ for (let i = 0; i < app.items_list.length; i++) {
35
+ if (!app.items_list[i].trash) {
36
+ items_list.push(app.items_list[i]);
37
+ } else {
38
+ trash_items.push(app.items_list[i]);
39
+ }
40
+ }
41
+ }
42
+
43
+ let field_list = [];
44
+ if (Array.isArray(app.field_list)) {
45
+ for (let i = 0; i < app.field_list.length; i++) {
46
+ if (!app.field_list[i].trash) {
47
+ field_list.push(app.field_list[i]);
48
+ }
49
+ }
50
+ }
51
+
52
+ return { ...app, items_list, trash_items, field_list };
25
53
  }
@@ -13,11 +13,41 @@ export default function (app) {
13
13
  res.status(200).send(app);
14
14
  });
15
15
 
16
+ app.post('/api/app/update', (req, res) => {
17
+ const updatedApp = JSON.parse(req.body.app);
18
+ const app = data[updatedApp.app_id];
19
+
20
+ if (app && Array.isArray(updatedApp.field_list)) {
21
+ updatedApp.field_list.forEach((updatedField) => {
22
+ const field = app.field_list.find((field) => field.field_id == updatedField.field_id);
23
+ if (field) {
24
+ field.field_name = updatedField.field_name;
25
+ }
26
+ });
27
+ }
28
+
29
+ res.status(200).send(app);
30
+ });
31
+
16
32
  app.post('/api/app/delete', (req, res) => {
17
33
  let responce = 'delete application with id=' + req.body.app_id;
18
34
  res.status(200).send(responce);
19
35
  });
20
36
 
37
+ app.post('/api/app/delete-field', (req, res) => {
38
+ const field_id = req.body.field_id;
39
+
40
+ Object.values(data).forEach(app => {
41
+ if (app && Array.isArray(app.field_list)) {
42
+ const field = app.field_list.find(field => field.field_id == field_id);
43
+ if (field) field.trash = true;
44
+ }
45
+ });
46
+
47
+ let responce = 'delete field with id = ' + field_id;
48
+ res.status(200).send(responce);
49
+ });
50
+
21
51
  app.get('/api/applist/get', (req, res) => {
22
52
  let responce = { apps_list: [data['214'], data['16259']] };
23
53
  res.status(200).send(responce);
@@ -234,8 +264,8 @@ export default function (app) {
234
264
  });
235
265
  });
236
266
 
237
- app.get('/api/invitation/accept', (req, res) => {
238
- const { invitation_id } = req.query;
267
+ app.post('/api/invitation/accept', (req, res) => {
268
+ const { invitation_id } = req.body;
239
269
 
240
270
  if (!invitation_id) {
241
271
  return res.status(400).json({ error: "Missing invitation_id" });