@carbonorm/carbonreact 3.4.4 → 3.4.5
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/dist/CarbonReact.d.ts +3 -0
- package/dist/index.cjs.js +2133 -5049
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +0 -49
- package/dist/index.esm.js +2114 -4952
- package/dist/index.esm.js.map +1 -1
- package/package.json +2 -2
- package/src/CarbonReact.tsx +3 -0
- package/src/index.ts +0 -49
- package/dist/api/rest/C6.d.ts +0 -579
- package/dist/api/rest/Carbons.d.ts +0 -88
- package/dist/api/rest/Carbons.test.d.ts +0 -14
- package/dist/api/rest/Chat_Messages.d.ts +0 -88
- package/dist/api/rest/Chat_Messages.test.d.ts +0 -20
- package/dist/api/rest/Documentation.d.ts +0 -88
- package/dist/api/rest/Documentation.test.d.ts +0 -11
- package/dist/api/rest/Feature_Group_References.d.ts +0 -88
- package/dist/api/rest/Feature_Group_References.test.d.ts +0 -13
- package/dist/api/rest/Features.d.ts +0 -88
- package/dist/api/rest/Features.test.d.ts +0 -14
- package/dist/api/rest/Group_References.d.ts +0 -88
- package/dist/api/rest/Group_References.test.d.ts +0 -13
- package/dist/api/rest/Groups.d.ts +0 -88
- package/dist/api/rest/Groups.test.d.ts +0 -15
- package/dist/api/rest/History_Logs.d.ts +0 -88
- package/dist/api/rest/History_Logs.test.d.ts +0 -13
- package/dist/api/rest/Likes.d.ts +0 -88
- package/dist/api/rest/Likes.test.d.ts +0 -13
- package/dist/api/rest/Location_References.d.ts +0 -88
- package/dist/api/rest/Location_References.test.d.ts +0 -14
- package/dist/api/rest/Locations.d.ts +0 -88
- package/dist/api/rest/Locations.test.d.ts +0 -18
- package/dist/api/rest/Photos.d.ts +0 -88
- package/dist/api/rest/Photos.test.d.ts +0 -20
- package/dist/api/rest/Posts.d.ts +0 -88
- package/dist/api/rest/Posts.test.d.ts +0 -22
- package/dist/api/rest/Projects.d.ts +0 -88
- package/dist/api/rest/Projects.test.d.ts +0 -21
- package/dist/api/rest/Reports.d.ts +0 -88
- package/dist/api/rest/Reports.test.d.ts +0 -11
- package/dist/api/rest/Sessions.d.ts +0 -88
- package/dist/api/rest/Sessions.test.d.ts +0 -14
- package/dist/api/rest/Subscription.d.ts +0 -88
- package/dist/api/rest/Subscription.test.d.ts +0 -20
- package/dist/api/rest/User_Followers.d.ts +0 -88
- package/dist/api/rest/User_Followers.test.d.ts +0 -16
- package/dist/api/rest/User_Groups.d.ts +0 -88
- package/dist/api/rest/User_Groups.test.d.ts +0 -13
- package/dist/api/rest/User_Messages.d.ts +0 -88
- package/dist/api/rest/User_Messages.test.d.ts +0 -20
- package/dist/api/rest/User_Sessions.d.ts +0 -88
- package/dist/api/rest/User_Sessions.test.d.ts +0 -14
- package/dist/api/rest/User_Tasks.d.ts +0 -88
- package/dist/api/rest/User_Tasks.test.d.ts +0 -22
- package/dist/api/rest/Users.d.ts +0 -88
- package/dist/api/rest/Users.test.d.ts +0 -44
- package/dist/api/rest/WsLiveUpdates.d.ts +0 -3
- package/src/api/rest/C6.tsx +0 -2687
- package/src/api/rest/Carbons.test.tsx +0 -128
- package/src/api/rest/Carbons.tsx +0 -145
- package/src/api/rest/Chat_Messages.test.tsx +0 -138
- package/src/api/rest/Chat_Messages.tsx +0 -151
- package/src/api/rest/Documentation.test.tsx +0 -128
- package/src/api/rest/Documentation.tsx +0 -142
- package/src/api/rest/Feature_Group_References.test.tsx +0 -126
- package/src/api/rest/Feature_Group_References.tsx +0 -144
- package/src/api/rest/Features.test.tsx +0 -128
- package/src/api/rest/Features.tsx +0 -145
- package/src/api/rest/Group_References.test.tsx +0 -126
- package/src/api/rest/Group_References.tsx +0 -144
- package/src/api/rest/Groups.test.tsx +0 -130
- package/src/api/rest/Groups.tsx +0 -146
- package/src/api/rest/History_Logs.test.tsx +0 -130
- package/src/api/rest/History_Logs.tsx +0 -144
- package/src/api/rest/Likes.test.tsx +0 -126
- package/src/api/rest/Likes.tsx +0 -144
- package/src/api/rest/Location_References.test.tsx +0 -128
- package/src/api/rest/Location_References.tsx +0 -145
- package/src/api/rest/Locations.test.tsx +0 -137
- package/src/api/rest/Locations.tsx +0 -149
- package/src/api/rest/Photos.test.tsx +0 -139
- package/src/api/rest/Photos.tsx +0 -151
- package/src/api/rest/Posts.test.tsx +0 -142
- package/src/api/rest/Posts.tsx +0 -153
- package/src/api/rest/Projects.test.tsx +0 -144
- package/src/api/rest/Projects.tsx +0 -152
- package/src/api/rest/Reports.test.tsx +0 -128
- package/src/api/rest/Reports.tsx +0 -142
- package/src/api/rest/Sessions.test.tsx +0 -133
- package/src/api/rest/Sessions.tsx +0 -145
- package/src/api/rest/Subscription.test.tsx +0 -138
- package/src/api/rest/Subscription.tsx +0 -151
- package/src/api/rest/User_Followers.test.tsx +0 -130
- package/src/api/rest/User_Followers.tsx +0 -147
- package/src/api/rest/User_Groups.test.tsx +0 -126
- package/src/api/rest/User_Groups.tsx +0 -144
- package/src/api/rest/User_Messages.test.tsx +0 -137
- package/src/api/rest/User_Messages.tsx +0 -151
- package/src/api/rest/User_Sessions.test.tsx +0 -133
- package/src/api/rest/User_Sessions.tsx +0 -145
- package/src/api/rest/User_Tasks.test.tsx +0 -141
- package/src/api/rest/User_Tasks.tsx +0 -153
- package/src/api/rest/Users.test.tsx +0 -193
- package/src/api/rest/Users.tsx +0 -175
- package/src/api/rest/WsLiveUpdates.tsx +0 -150
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import {xdescribe, expect, test} from '@jest/globals';
|
|
2
|
-
import {CarbonReact} from "@carbonorm/carbonreact";
|
|
3
|
-
import {checkAllRequestsComplete} from "@carbonorm/carbonnode";
|
|
4
|
-
import {act, waitFor} from '@testing-library/react';
|
|
5
|
-
import {C6, iRestfulObjectArrayTypes, iReports, reports } from "api/rest/C6";
|
|
6
|
-
import Reports from "./Reports";
|
|
7
|
-
|
|
8
|
-
const randomString = Math.random().toString(36).substring(7);
|
|
9
|
-
const randomInt = Math.floor(Math.random() * 1000000);
|
|
10
|
-
const fillString = 'string' + randomString + randomInt;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
CREATE TABLE `carbon_reports` (
|
|
14
|
-
`log_level` varchar(20) DEFAULT NULL,
|
|
15
|
-
`report` text,
|
|
16
|
-
`date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
17
|
-
`call_trace` text NOT NULL
|
|
18
|
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
19
|
-
**/
|
|
20
|
-
|
|
21
|
-
const Test_Data: iReports = {
|
|
22
|
-
|
|
23
|
-
report: fillString.substring(0, ),
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export default Test_Data;
|
|
28
|
-
|
|
29
|
-
xdescribe('REST Reports api', () => {
|
|
30
|
-
|
|
31
|
-
let testData = Test_Data;
|
|
32
|
-
|
|
33
|
-
test('GET POST PUT DELETE', async () => {
|
|
34
|
-
|
|
35
|
-
await act(async () => {
|
|
36
|
-
|
|
37
|
-
let selectAllResponse = await Reports.Get({})
|
|
38
|
-
|
|
39
|
-
if ('function' === typeof selectAllResponse) {
|
|
40
|
-
throw Error('selectAllResponse is a promise, this typically means this specific get request has already run during test setup.');
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// We don't care if it is filled or not, just that the request can be made.
|
|
44
|
-
expect(selectAllResponse?.data?.rest).not.toBeUndefined();
|
|
45
|
-
|
|
46
|
-
const postResponse = await Reports.Post(testData);
|
|
47
|
-
|
|
48
|
-
console.log('postResponse', postResponse?.data)
|
|
49
|
-
|
|
50
|
-
expect(postResponse?.data?.created).not.toBeUndefined();
|
|
51
|
-
|
|
52
|
-
const primaryKey = reports.PRIMARY_SHORT[0];
|
|
53
|
-
|
|
54
|
-
const postID = postResponse?.data?.created
|
|
55
|
-
|
|
56
|
-
const singleRowSelect = await Reports.Get({
|
|
57
|
-
[C6.WHERE]: {
|
|
58
|
-
[reports[primaryKey.toUpperCase()]]: postID,
|
|
59
|
-
}
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
if ('function' === typeof singleRowSelect) {
|
|
63
|
-
throw Error('singleRowSelect is a promise, this is unexpected.');
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
console.log('singleRowSelect', singleRowSelect?.data)
|
|
67
|
-
|
|
68
|
-
// Ensure the expected response datastructure is returned
|
|
69
|
-
expect(singleRowSelect?.data?.rest).not.toBeUndefined();
|
|
70
|
-
|
|
71
|
-
// Make sure the previously created post is now returned
|
|
72
|
-
expect(typeof singleRowSelect?.data?.rest).toEqual('object');
|
|
73
|
-
|
|
74
|
-
// todo - make this work correctly with multiple primary keys
|
|
75
|
-
const selectedPostId = singleRowSelect?.data?.rest[0][primaryKey]
|
|
76
|
-
|
|
77
|
-
expect(selectedPostId).toEqual(postID);
|
|
78
|
-
|
|
79
|
-
const multipleRowSelect = await Reports.Get({
|
|
80
|
-
[C6.WHERE]: {
|
|
81
|
-
[reports[primaryKey.toUpperCase()]]: [C6.IN, [0, postID]],
|
|
82
|
-
}
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
if ('function' === typeof multipleRowSelect) {
|
|
86
|
-
throw Error('singleRowSelect is a promise, this is unexpected.');
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
console.log('singleRowSelect', multipleRowSelect?.data)
|
|
90
|
-
|
|
91
|
-
// Ensure the expected response datastructure is returned
|
|
92
|
-
expect(multipleRowSelect?.data?.rest).not.toBeUndefined();
|
|
93
|
-
|
|
94
|
-
// Make sure the previously created post is now returned
|
|
95
|
-
expect(typeof multipleRowSelect?.data?.rest).toEqual('object');
|
|
96
|
-
|
|
97
|
-
testData[primaryKey] = postID
|
|
98
|
-
|
|
99
|
-
testData.log_level = fillString.substring(0, 20);
|
|
100
|
-
testData.report = fillString.substring(0, );
|
|
101
|
-
testData.date = fillString.substring(0, );
|
|
102
|
-
testData.call_trace = fillString.substring(0, );
|
|
103
|
-
|
|
104
|
-
// wait for the global state to be updated
|
|
105
|
-
expect(CarbonReact.getState<iRestfulObjectArrayTypes>().reports).not.toBeUndefined();
|
|
106
|
-
|
|
107
|
-
const updateResponse = await Reports.Put(testData)
|
|
108
|
-
|
|
109
|
-
expect(updateResponse?.data?.updated).not.toBeUndefined();
|
|
110
|
-
|
|
111
|
-
const deleteResponse = await Reports.Delete({
|
|
112
|
-
[primaryKey]: postID
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
console.log('deleteResponse', deleteResponse?.data)
|
|
116
|
-
|
|
117
|
-
expect(deleteResponse?.data?.deleted).not.toBeUndefined();
|
|
118
|
-
|
|
119
|
-
await waitFor(async () => {
|
|
120
|
-
expect(checkAllRequestsComplete()).toEqual(true);
|
|
121
|
-
}, {timeout: 10000, interval: 1000});
|
|
122
|
-
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
}, 100000);
|
|
126
|
-
|
|
127
|
-
})
|
|
128
|
-
|
package/src/api/rest/Reports.tsx
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
iPostC6RestResponse,
|
|
3
|
-
restRequest,
|
|
4
|
-
GET,
|
|
5
|
-
POST,
|
|
6
|
-
PUT,
|
|
7
|
-
DELETE,
|
|
8
|
-
iDeleteC6RestResponse,
|
|
9
|
-
iGetC6RestResponse,
|
|
10
|
-
iPutC6RestResponse,
|
|
11
|
-
removeInvalidKeys
|
|
12
|
-
} from "@carbonorm/carbonnode";
|
|
13
|
-
import {AxiosResponse} from "axios";
|
|
14
|
-
import {iAPI, Modify} from "restRequest";
|
|
15
|
-
import {deleteRestfulObjectArrays, updateRestfulObjectArrays} from "@carbonorm/carbonreact";
|
|
16
|
-
import {C6, iReports, reports, RestTableNames} from "./C6";
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
CREATE TABLE `carbon_reports` (
|
|
20
|
-
`log_level` varchar(20) DEFAULT NULL,
|
|
21
|
-
`report` text,
|
|
22
|
-
`date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
23
|
-
`call_trace` text NOT NULL
|
|
24
|
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
25
|
-
**/
|
|
26
|
-
|
|
27
|
-
type GetCustomAndRequiredFields = {}
|
|
28
|
-
|
|
29
|
-
type GetRequestTableOverrides = {}
|
|
30
|
-
|
|
31
|
-
// required parameters, optional parameters, parameter type overrides, response, and table names
|
|
32
|
-
export const Get = restRequest<GetCustomAndRequiredFields, iReports, GetRequestTableOverrides, iGetC6RestResponse<iReports>, RestTableNames>({
|
|
33
|
-
C6: C6,
|
|
34
|
-
tableName: reports.TABLE_NAME,
|
|
35
|
-
requestMethod: GET,
|
|
36
|
-
queryCallback: (request) => {
|
|
37
|
-
request.success ??= 'Successfully received reports!'
|
|
38
|
-
request.error ??= 'An unknown issue occurred creating the reports!'
|
|
39
|
-
return request
|
|
40
|
-
},
|
|
41
|
-
responseCallback: (response, _request) => {
|
|
42
|
-
updateRestfulObjectArrays<iReports>(response?.data?.rest, "reports", C6.reports.PRIMARY_SHORT as (keyof iReports)[])
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
type PutCustomAndRequiredFields = {}
|
|
47
|
-
|
|
48
|
-
type PutRequestTableOverrides = {}
|
|
49
|
-
|
|
50
|
-
export function putStateReports(response : AxiosResponse<iPutC6RestResponse<iReports>>, request : iAPI<Modify<iReports, PutRequestTableOverrides>> & PutCustomAndRequiredFields) {
|
|
51
|
-
updateRestfulObjectArrays<iReports>([
|
|
52
|
-
removeInvalidKeys<iReports>({
|
|
53
|
-
...request,
|
|
54
|
-
...response?.data?.rest,
|
|
55
|
-
}, C6.TABLES)
|
|
56
|
-
], "reports", reports.PRIMARY_SHORT as (keyof iReports)[])
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export const Put = restRequest<PutCustomAndRequiredFields, iReports, PutRequestTableOverrides, iPutC6RestResponse<iReports>, RestTableNames>({
|
|
60
|
-
C6: C6,
|
|
61
|
-
tableName: reports.TABLE_NAME,
|
|
62
|
-
requestMethod: PUT,
|
|
63
|
-
queryCallback: (request) => {
|
|
64
|
-
request.success ??= 'Successfully updated reports data!'
|
|
65
|
-
request.error ??= 'An unknown issue occurred updating the reports data!'
|
|
66
|
-
return request
|
|
67
|
-
},
|
|
68
|
-
responseCallback: putStateReports
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
type PostCustomAndRequiredFields = {}
|
|
72
|
-
|
|
73
|
-
type PostRequestTableOverrides = {}
|
|
74
|
-
|
|
75
|
-
export function postStateReports(response : AxiosResponse<iPostC6RestResponse<iReports>>, request : iAPI<Modify<iReports, PostRequestTableOverrides>> & PostCustomAndRequiredFields, id: string | number | boolean) {
|
|
76
|
-
if ('number' === typeof id || 'string' === typeof id) {
|
|
77
|
-
if (1 !== reports.PRIMARY_SHORT.length) {
|
|
78
|
-
console.error("C6 received unexpected result's given the primary key length");
|
|
79
|
-
} else {
|
|
80
|
-
request[reports.PRIMARY_SHORT[0]] = id
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
updateRestfulObjectArrays<iReports>(
|
|
84
|
-
undefined !== request.dataInsertMultipleRows
|
|
85
|
-
? request.dataInsertMultipleRows.map((request, index) => {
|
|
86
|
-
return removeInvalidKeys<iReports>({
|
|
87
|
-
...request,
|
|
88
|
-
...(index === 0 ? response?.data?.rest : {}),
|
|
89
|
-
}, C6.TABLES)
|
|
90
|
-
})
|
|
91
|
-
: [
|
|
92
|
-
removeInvalidKeys<iReports>({
|
|
93
|
-
...request,
|
|
94
|
-
...response?.data?.rest,
|
|
95
|
-
}, C6.TABLES)
|
|
96
|
-
],
|
|
97
|
-
"reports",
|
|
98
|
-
reports.PRIMARY_SHORT as (keyof iReports)[]
|
|
99
|
-
)
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export const Post = restRequest<PostCustomAndRequiredFields, iReports, PostRequestTableOverrides, iPostC6RestResponse<iReports>, RestTableNames>({
|
|
103
|
-
C6: C6,
|
|
104
|
-
tableName: reports.TABLE_NAME,
|
|
105
|
-
requestMethod: POST,
|
|
106
|
-
queryCallback: (request) => {
|
|
107
|
-
request.success ??= 'Successfully created the reports data!'
|
|
108
|
-
request.error ??= 'An unknown issue occurred creating the reports data!'
|
|
109
|
-
return request
|
|
110
|
-
},
|
|
111
|
-
responseCallback: postStateReports
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
type DeleteCustomAndRequiredFields = {}
|
|
115
|
-
|
|
116
|
-
type DeleteRequestTableOverrides = {}
|
|
117
|
-
|
|
118
|
-
export function deleteStateReports(_response : AxiosResponse<iDeleteC6RestResponse<iReports>>, request : iAPI<Modify<iReports, DeleteRequestTableOverrides>> & DeleteCustomAndRequiredFields) {
|
|
119
|
-
deleteRestfulObjectArrays<iReports>([
|
|
120
|
-
request
|
|
121
|
-
], "reports", reports.PRIMARY_SHORT as (keyof iReports)[])
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export const Delete = restRequest<DeleteCustomAndRequiredFields, iReports, DeleteRequestTableOverrides, iDeleteC6RestResponse<iReports>, RestTableNames>({
|
|
125
|
-
C6: C6,
|
|
126
|
-
tableName: reports.TABLE_NAME,
|
|
127
|
-
requestMethod: DELETE,
|
|
128
|
-
queryCallback: (request) => {
|
|
129
|
-
request.success ??= 'Successfully removed the reports data!'
|
|
130
|
-
request.error ??= 'An unknown issue occurred removing the reports data!'
|
|
131
|
-
return request
|
|
132
|
-
},
|
|
133
|
-
responseCallback: deleteStateReports
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
export default {
|
|
137
|
-
// Export all GET, POST, PUT, DELETE functions for each table
|
|
138
|
-
Get,
|
|
139
|
-
Post,
|
|
140
|
-
Put,
|
|
141
|
-
Delete,
|
|
142
|
-
}
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import {xdescribe, expect, test} from '@jest/globals';
|
|
2
|
-
import {CarbonReact} from "@carbonorm/carbonreact";
|
|
3
|
-
import {checkAllRequestsComplete} from "@carbonorm/carbonnode";
|
|
4
|
-
import {act, waitFor} from '@testing-library/react';
|
|
5
|
-
import {C6, iRestfulObjectArrayTypes, iSessions, sessions } from "api/rest/C6";
|
|
6
|
-
import Sessions from "./Sessions";
|
|
7
|
-
|
|
8
|
-
const randomString = Math.random().toString(36).substring(7);
|
|
9
|
-
const randomInt = Math.floor(Math.random() * 1000000);
|
|
10
|
-
const fillString = 'string' + randomString + randomInt;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
CREATE TABLE `carbon_sessions` (
|
|
14
|
-
`user_id` binary(16) NOT NULL,
|
|
15
|
-
`user_ip` varchar(20) DEFAULT NULL,
|
|
16
|
-
`session_id` varchar(255) NOT NULL,
|
|
17
|
-
`session_expires` datetime NOT NULL,
|
|
18
|
-
`session_data` text,
|
|
19
|
-
`user_online_status` tinyint DEFAULT '1',
|
|
20
|
-
PRIMARY KEY (`session_id`)
|
|
21
|
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
22
|
-
**/
|
|
23
|
-
|
|
24
|
-
const Test_Data: iSessions = {
|
|
25
|
-
|
|
26
|
-
session_data: fillString.substring(0, ),
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export default Test_Data;
|
|
31
|
-
|
|
32
|
-
xdescribe('REST Sessions api', () => {
|
|
33
|
-
|
|
34
|
-
let testData = Test_Data;
|
|
35
|
-
|
|
36
|
-
test('GET POST PUT DELETE', async () => {
|
|
37
|
-
|
|
38
|
-
await act(async () => {
|
|
39
|
-
|
|
40
|
-
let selectAllResponse = await Sessions.Get({})
|
|
41
|
-
|
|
42
|
-
if ('function' === typeof selectAllResponse) {
|
|
43
|
-
throw Error('selectAllResponse is a promise, this typically means this specific get request has already run during test setup.');
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// We don't care if it is filled or not, just that the request can be made.
|
|
47
|
-
expect(selectAllResponse?.data?.rest).not.toBeUndefined();
|
|
48
|
-
|
|
49
|
-
const postResponse = await Sessions.Post(testData);
|
|
50
|
-
|
|
51
|
-
console.log('postResponse', postResponse?.data)
|
|
52
|
-
|
|
53
|
-
expect(postResponse?.data?.created).not.toBeUndefined();
|
|
54
|
-
|
|
55
|
-
const primaryKey = sessions.PRIMARY_SHORT[0];
|
|
56
|
-
|
|
57
|
-
const postID = postResponse?.data?.created
|
|
58
|
-
|
|
59
|
-
const singleRowSelect = await Sessions.Get({
|
|
60
|
-
[C6.WHERE]: {
|
|
61
|
-
[sessions[primaryKey.toUpperCase()]]: postID,
|
|
62
|
-
}
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
if ('function' === typeof singleRowSelect) {
|
|
66
|
-
throw Error('singleRowSelect is a promise, this is unexpected.');
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
console.log('singleRowSelect', singleRowSelect?.data)
|
|
70
|
-
|
|
71
|
-
// Ensure the expected response datastructure is returned
|
|
72
|
-
expect(singleRowSelect?.data?.rest).not.toBeUndefined();
|
|
73
|
-
|
|
74
|
-
// Make sure the previously created post is now returned
|
|
75
|
-
expect(typeof singleRowSelect?.data?.rest).toEqual('object');
|
|
76
|
-
|
|
77
|
-
// todo - make this work correctly with multiple primary keys
|
|
78
|
-
const selectedPostId = singleRowSelect?.data?.rest[0][primaryKey]
|
|
79
|
-
|
|
80
|
-
expect(selectedPostId).toEqual(postID);
|
|
81
|
-
|
|
82
|
-
const multipleRowSelect = await Sessions.Get({
|
|
83
|
-
[C6.WHERE]: {
|
|
84
|
-
[sessions[primaryKey.toUpperCase()]]: [C6.IN, [0, postID]],
|
|
85
|
-
}
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
if ('function' === typeof multipleRowSelect) {
|
|
89
|
-
throw Error('singleRowSelect is a promise, this is unexpected.');
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
console.log('singleRowSelect', multipleRowSelect?.data)
|
|
93
|
-
|
|
94
|
-
// Ensure the expected response datastructure is returned
|
|
95
|
-
expect(multipleRowSelect?.data?.rest).not.toBeUndefined();
|
|
96
|
-
|
|
97
|
-
// Make sure the previously created post is now returned
|
|
98
|
-
expect(typeof multipleRowSelect?.data?.rest).toEqual('object');
|
|
99
|
-
|
|
100
|
-
testData[primaryKey] = postID
|
|
101
|
-
|
|
102
|
-
testData.user_id = fillString.substring(0, 16);
|
|
103
|
-
testData.user_ip = fillString.substring(0, 20);
|
|
104
|
-
testData.session_id = fillString.substring(0, 255);
|
|
105
|
-
testData.session_expires = fillString.substring(0, );
|
|
106
|
-
testData.session_data = fillString.substring(0, );
|
|
107
|
-
testData.user_online_status = fillString.substring(0, );
|
|
108
|
-
|
|
109
|
-
// wait for the global state to be updated
|
|
110
|
-
expect(CarbonReact.getState<iRestfulObjectArrayTypes>().sessions).not.toBeUndefined();
|
|
111
|
-
|
|
112
|
-
const updateResponse = await Sessions.Put(testData)
|
|
113
|
-
|
|
114
|
-
expect(updateResponse?.data?.updated).not.toBeUndefined();
|
|
115
|
-
|
|
116
|
-
const deleteResponse = await Sessions.Delete({
|
|
117
|
-
[primaryKey]: postID
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
console.log('deleteResponse', deleteResponse?.data)
|
|
121
|
-
|
|
122
|
-
expect(deleteResponse?.data?.deleted).not.toBeUndefined();
|
|
123
|
-
|
|
124
|
-
await waitFor(async () => {
|
|
125
|
-
expect(checkAllRequestsComplete()).toEqual(true);
|
|
126
|
-
}, {timeout: 10000, interval: 1000});
|
|
127
|
-
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
}, 100000);
|
|
131
|
-
|
|
132
|
-
})
|
|
133
|
-
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
iPostC6RestResponse,
|
|
3
|
-
restRequest,
|
|
4
|
-
GET,
|
|
5
|
-
POST,
|
|
6
|
-
PUT,
|
|
7
|
-
DELETE,
|
|
8
|
-
iDeleteC6RestResponse,
|
|
9
|
-
iGetC6RestResponse,
|
|
10
|
-
iPutC6RestResponse,
|
|
11
|
-
removeInvalidKeys
|
|
12
|
-
} from "@carbonorm/carbonnode";
|
|
13
|
-
import {AxiosResponse} from "axios";
|
|
14
|
-
import {iAPI, Modify} from "restRequest";
|
|
15
|
-
import {deleteRestfulObjectArrays, updateRestfulObjectArrays} from "@carbonorm/carbonreact";
|
|
16
|
-
import {C6, iSessions, sessions, RestTableNames} from "./C6";
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
CREATE TABLE `carbon_sessions` (
|
|
20
|
-
`user_id` binary(16) NOT NULL,
|
|
21
|
-
`user_ip` varchar(20) DEFAULT NULL,
|
|
22
|
-
`session_id` varchar(255) NOT NULL,
|
|
23
|
-
`session_expires` datetime NOT NULL,
|
|
24
|
-
`session_data` text,
|
|
25
|
-
`user_online_status` tinyint DEFAULT '1',
|
|
26
|
-
PRIMARY KEY (`session_id`)
|
|
27
|
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
28
|
-
**/
|
|
29
|
-
|
|
30
|
-
type GetCustomAndRequiredFields = {}
|
|
31
|
-
|
|
32
|
-
type GetRequestTableOverrides = {}
|
|
33
|
-
|
|
34
|
-
// required parameters, optional parameters, parameter type overrides, response, and table names
|
|
35
|
-
export const Get = restRequest<GetCustomAndRequiredFields, iSessions, GetRequestTableOverrides, iGetC6RestResponse<iSessions>, RestTableNames>({
|
|
36
|
-
C6: C6,
|
|
37
|
-
tableName: sessions.TABLE_NAME,
|
|
38
|
-
requestMethod: GET,
|
|
39
|
-
queryCallback: (request) => {
|
|
40
|
-
request.success ??= 'Successfully received sessions!'
|
|
41
|
-
request.error ??= 'An unknown issue occurred creating the sessions!'
|
|
42
|
-
return request
|
|
43
|
-
},
|
|
44
|
-
responseCallback: (response, _request) => {
|
|
45
|
-
updateRestfulObjectArrays<iSessions>(response?.data?.rest, "sessions", C6.sessions.PRIMARY_SHORT as (keyof iSessions)[])
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
type PutCustomAndRequiredFields = {}
|
|
50
|
-
|
|
51
|
-
type PutRequestTableOverrides = {}
|
|
52
|
-
|
|
53
|
-
export function putStateSessions(response : AxiosResponse<iPutC6RestResponse<iSessions>>, request : iAPI<Modify<iSessions, PutRequestTableOverrides>> & PutCustomAndRequiredFields) {
|
|
54
|
-
updateRestfulObjectArrays<iSessions>([
|
|
55
|
-
removeInvalidKeys<iSessions>({
|
|
56
|
-
...request,
|
|
57
|
-
...response?.data?.rest,
|
|
58
|
-
}, C6.TABLES)
|
|
59
|
-
], "sessions", sessions.PRIMARY_SHORT as (keyof iSessions)[])
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export const Put = restRequest<PutCustomAndRequiredFields, iSessions, PutRequestTableOverrides, iPutC6RestResponse<iSessions>, RestTableNames>({
|
|
63
|
-
C6: C6,
|
|
64
|
-
tableName: sessions.TABLE_NAME,
|
|
65
|
-
requestMethod: PUT,
|
|
66
|
-
queryCallback: (request) => {
|
|
67
|
-
request.success ??= 'Successfully updated sessions data!'
|
|
68
|
-
request.error ??= 'An unknown issue occurred updating the sessions data!'
|
|
69
|
-
return request
|
|
70
|
-
},
|
|
71
|
-
responseCallback: putStateSessions
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
type PostCustomAndRequiredFields = {}
|
|
75
|
-
|
|
76
|
-
type PostRequestTableOverrides = {}
|
|
77
|
-
|
|
78
|
-
export function postStateSessions(response : AxiosResponse<iPostC6RestResponse<iSessions>>, request : iAPI<Modify<iSessions, PostRequestTableOverrides>> & PostCustomAndRequiredFields, id: string | number | boolean) {
|
|
79
|
-
if ('number' === typeof id || 'string' === typeof id) {
|
|
80
|
-
if (1 !== sessions.PRIMARY_SHORT.length) {
|
|
81
|
-
console.error("C6 received unexpected result's given the primary key length");
|
|
82
|
-
} else {
|
|
83
|
-
request[sessions.PRIMARY_SHORT[0]] = id
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
updateRestfulObjectArrays<iSessions>(
|
|
87
|
-
undefined !== request.dataInsertMultipleRows
|
|
88
|
-
? request.dataInsertMultipleRows.map((request, index) => {
|
|
89
|
-
return removeInvalidKeys<iSessions>({
|
|
90
|
-
...request,
|
|
91
|
-
...(index === 0 ? response?.data?.rest : {}),
|
|
92
|
-
}, C6.TABLES)
|
|
93
|
-
})
|
|
94
|
-
: [
|
|
95
|
-
removeInvalidKeys<iSessions>({
|
|
96
|
-
...request,
|
|
97
|
-
...response?.data?.rest,
|
|
98
|
-
}, C6.TABLES)
|
|
99
|
-
],
|
|
100
|
-
"sessions",
|
|
101
|
-
sessions.PRIMARY_SHORT as (keyof iSessions)[]
|
|
102
|
-
)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export const Post = restRequest<PostCustomAndRequiredFields, iSessions, PostRequestTableOverrides, iPostC6RestResponse<iSessions>, RestTableNames>({
|
|
106
|
-
C6: C6,
|
|
107
|
-
tableName: sessions.TABLE_NAME,
|
|
108
|
-
requestMethod: POST,
|
|
109
|
-
queryCallback: (request) => {
|
|
110
|
-
request.success ??= 'Successfully created the sessions data!'
|
|
111
|
-
request.error ??= 'An unknown issue occurred creating the sessions data!'
|
|
112
|
-
return request
|
|
113
|
-
},
|
|
114
|
-
responseCallback: postStateSessions
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
type DeleteCustomAndRequiredFields = {}
|
|
118
|
-
|
|
119
|
-
type DeleteRequestTableOverrides = {}
|
|
120
|
-
|
|
121
|
-
export function deleteStateSessions(_response : AxiosResponse<iDeleteC6RestResponse<iSessions>>, request : iAPI<Modify<iSessions, DeleteRequestTableOverrides>> & DeleteCustomAndRequiredFields) {
|
|
122
|
-
deleteRestfulObjectArrays<iSessions>([
|
|
123
|
-
request
|
|
124
|
-
], "sessions", sessions.PRIMARY_SHORT as (keyof iSessions)[])
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export const Delete = restRequest<DeleteCustomAndRequiredFields, iSessions, DeleteRequestTableOverrides, iDeleteC6RestResponse<iSessions>, RestTableNames>({
|
|
128
|
-
C6: C6,
|
|
129
|
-
tableName: sessions.TABLE_NAME,
|
|
130
|
-
requestMethod: DELETE,
|
|
131
|
-
queryCallback: (request) => {
|
|
132
|
-
request.success ??= 'Successfully removed the sessions data!'
|
|
133
|
-
request.error ??= 'An unknown issue occurred removing the sessions data!'
|
|
134
|
-
return request
|
|
135
|
-
},
|
|
136
|
-
responseCallback: deleteStateSessions
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
export default {
|
|
140
|
-
// Export all GET, POST, PUT, DELETE functions for each table
|
|
141
|
-
Get,
|
|
142
|
-
Post,
|
|
143
|
-
Put,
|
|
144
|
-
Delete,
|
|
145
|
-
}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import {xdescribe, expect, test} from '@jest/globals';
|
|
2
|
-
import {CarbonReact} from "@carbonorm/carbonreact";
|
|
3
|
-
import {checkAllRequestsComplete} from "@carbonorm/carbonnode";
|
|
4
|
-
import {act, waitFor} from '@testing-library/react';
|
|
5
|
-
import {C6, iRestfulObjectArrayTypes, iSubscription, subscription } from "api/rest/C6";
|
|
6
|
-
import Subscription from "./Subscription";
|
|
7
|
-
|
|
8
|
-
const randomString = Math.random().toString(36).substring(7);
|
|
9
|
-
const randomInt = Math.floor(Math.random() * 1000000);
|
|
10
|
-
const fillString = 'string' + randomString + randomInt;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
CREATE TABLE `carbon_subscription` (
|
|
14
|
-
`subscription_id` binary(16) NOT NULL,
|
|
15
|
-
`subscription_to_entity_id` binary(16) DEFAULT NULL,
|
|
16
|
-
`subscription_for_entity_id` binary(16) DEFAULT NULL,
|
|
17
|
-
`subscription_price` varchar(16) DEFAULT NULL,
|
|
18
|
-
`subscription_start_date` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
19
|
-
`subscription_end_date` datetime DEFAULT NULL,
|
|
20
|
-
`subscription_transaction_id` varchar(255) DEFAULT NULL,
|
|
21
|
-
PRIMARY KEY (`subscription_id`),
|
|
22
|
-
KEY `carbon_subscription_carbon_carbons_entity_pk_fk2` (`subscription_to_entity_id`),
|
|
23
|
-
KEY `carbon_subscription_carbon_carbons_entity_pk_fk3` (`subscription_for_entity_id`),
|
|
24
|
-
CONSTRAINT `carbon_subscription_carbon_carbons_entity_pk_fk` FOREIGN KEY (`subscription_id`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
25
|
-
CONSTRAINT `carbon_subscription_carbon_carbons_entity_pk_fk2` FOREIGN KEY (`subscription_to_entity_id`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE,
|
|
26
|
-
CONSTRAINT `carbon_subscription_carbon_carbons_entity_pk_fk3` FOREIGN KEY (`subscription_for_entity_id`) REFERENCES `carbon_carbons` (`entity_pk`) ON DELETE CASCADE ON UPDATE CASCADE
|
|
27
|
-
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
|
|
28
|
-
**/
|
|
29
|
-
|
|
30
|
-
const Test_Data: iSubscription = {
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export default Test_Data;
|
|
35
|
-
|
|
36
|
-
xdescribe('REST Subscription api', () => {
|
|
37
|
-
|
|
38
|
-
let testData = Test_Data;
|
|
39
|
-
|
|
40
|
-
test('GET POST PUT DELETE', async () => {
|
|
41
|
-
|
|
42
|
-
await act(async () => {
|
|
43
|
-
|
|
44
|
-
let selectAllResponse = await Subscription.Get({})
|
|
45
|
-
|
|
46
|
-
if ('function' === typeof selectAllResponse) {
|
|
47
|
-
throw Error('selectAllResponse is a promise, this typically means this specific get request has already run during test setup.');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// We don't care if it is filled or not, just that the request can be made.
|
|
51
|
-
expect(selectAllResponse?.data?.rest).not.toBeUndefined();
|
|
52
|
-
|
|
53
|
-
const postResponse = await Subscription.Post(testData);
|
|
54
|
-
|
|
55
|
-
console.log('postResponse', postResponse?.data)
|
|
56
|
-
|
|
57
|
-
expect(postResponse?.data?.created).not.toBeUndefined();
|
|
58
|
-
|
|
59
|
-
const primaryKey = subscription.PRIMARY_SHORT[0];
|
|
60
|
-
|
|
61
|
-
const postID = postResponse?.data?.created
|
|
62
|
-
|
|
63
|
-
const singleRowSelect = await Subscription.Get({
|
|
64
|
-
[C6.WHERE]: {
|
|
65
|
-
[subscription[primaryKey.toUpperCase()]]: postID,
|
|
66
|
-
}
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
if ('function' === typeof singleRowSelect) {
|
|
70
|
-
throw Error('singleRowSelect is a promise, this is unexpected.');
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
console.log('singleRowSelect', singleRowSelect?.data)
|
|
74
|
-
|
|
75
|
-
// Ensure the expected response datastructure is returned
|
|
76
|
-
expect(singleRowSelect?.data?.rest).not.toBeUndefined();
|
|
77
|
-
|
|
78
|
-
// Make sure the previously created post is now returned
|
|
79
|
-
expect(typeof singleRowSelect?.data?.rest).toEqual('object');
|
|
80
|
-
|
|
81
|
-
// todo - make this work correctly with multiple primary keys
|
|
82
|
-
const selectedPostId = singleRowSelect?.data?.rest[0][primaryKey]
|
|
83
|
-
|
|
84
|
-
expect(selectedPostId).toEqual(postID);
|
|
85
|
-
|
|
86
|
-
const multipleRowSelect = await Subscription.Get({
|
|
87
|
-
[C6.WHERE]: {
|
|
88
|
-
[subscription[primaryKey.toUpperCase()]]: [C6.IN, [0, postID]],
|
|
89
|
-
}
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
if ('function' === typeof multipleRowSelect) {
|
|
93
|
-
throw Error('singleRowSelect is a promise, this is unexpected.');
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
console.log('singleRowSelect', multipleRowSelect?.data)
|
|
97
|
-
|
|
98
|
-
// Ensure the expected response datastructure is returned
|
|
99
|
-
expect(multipleRowSelect?.data?.rest).not.toBeUndefined();
|
|
100
|
-
|
|
101
|
-
// Make sure the previously created post is now returned
|
|
102
|
-
expect(typeof multipleRowSelect?.data?.rest).toEqual('object');
|
|
103
|
-
|
|
104
|
-
testData[primaryKey] = postID
|
|
105
|
-
|
|
106
|
-
testData.subscription_id = fillString.substring(0, 16);
|
|
107
|
-
testData.subscription_to_entity_id = fillString.substring(0, 16);
|
|
108
|
-
testData.subscription_for_entity_id = fillString.substring(0, 16);
|
|
109
|
-
testData.subscription_price = fillString.substring(0, 16);
|
|
110
|
-
testData.subscription_start_date = fillString.substring(0, );
|
|
111
|
-
testData.subscription_end_date = fillString.substring(0, );
|
|
112
|
-
testData.subscription_transaction_id = fillString.substring(0, 255);
|
|
113
|
-
|
|
114
|
-
// wait for the global state to be updated
|
|
115
|
-
expect(CarbonReact.getState<iRestfulObjectArrayTypes>().subscription).not.toBeUndefined();
|
|
116
|
-
|
|
117
|
-
const updateResponse = await Subscription.Put(testData)
|
|
118
|
-
|
|
119
|
-
expect(updateResponse?.data?.updated).not.toBeUndefined();
|
|
120
|
-
|
|
121
|
-
const deleteResponse = await Subscription.Delete({
|
|
122
|
-
[primaryKey]: postID
|
|
123
|
-
})
|
|
124
|
-
|
|
125
|
-
console.log('deleteResponse', deleteResponse?.data)
|
|
126
|
-
|
|
127
|
-
expect(deleteResponse?.data?.deleted).not.toBeUndefined();
|
|
128
|
-
|
|
129
|
-
await waitFor(async () => {
|
|
130
|
-
expect(checkAllRequestsComplete()).toEqual(true);
|
|
131
|
-
}, {timeout: 10000, interval: 1000});
|
|
132
|
-
|
|
133
|
-
})
|
|
134
|
-
|
|
135
|
-
}, 100000);
|
|
136
|
-
|
|
137
|
-
})
|
|
138
|
-
|