Skip to content

Commit aa42576

Browse files
committed
feat: Enhance ApiService with role management methods and update related tests
1 parent 3344cea commit aa42576

File tree

10 files changed

+234
-24
lines changed

10 files changed

+234
-24
lines changed

ENDPOINTS.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
Ref: https://mixcore.net/swagger/v2/swagger.json
2+
API Base URL: https://mixcore.net
3+
4+
| Method | Path | Summary | Tags | Parameters |
5+
|---|---|---|---|---|
6+
| GET | `/api/v2/rest/en-us/attribute-set/my-data` | Get My Data | en-us-attribute-set | [query] keyword (string, optional)<br>[query] orderBy (string, optional)<br>[query] direction (string, optional)<br>[query] pageSize (integer, optional)<br>[query] pageIndex (integer, optional) |
7+
| GET | `/api/v2/rest/en-us/attribute-set/my-data/delete/{id}` | Delete My Data | en-us-attribute-set | [path] id (string, required) |
8+
| GET | `/api/v2/rest/en-us/attribute-set/my-data/export` | Export My Data | en-us-attribute-set | [query] keyword (string, optional)<br>[query] orderBy (string, optional)<br>[query] direction (string, optional)<br>[query] pageSize (integer, optional)<br>[query] pageIndex (integer, optional) |
9+
| GET | `/api/v2/rest/en-us/attribute-set/my-data/{id}` | Get My Data By Id | en-us-attribute-set | [path] id (string, required) |
10+
| POST | `/api/v2/rest/en-us/attribute-set/my-data` | Save My Data | en-us-attribute-set | [body] model (object, optional) |
11+
| POST | `/api/v2/rest/en-us/attribute-set/my-data/save-properties` | Save My Data Properties | en-us-attribute-set | [body] model (object, optional) |
12+
| POST | `/api/v2/rest/mix-portal/command` | Execute Commands | mix-portal | [body] model (object, optional) |
13+
| GET | `/api/v2/rest/mix-portal/get-by-name/{name}` | Get App Settings by name | mix-portal | [path] name (string, required) |
14+
| GET | `/api/v2/rest/mix-portal/get-config/{name}` | Get App config by name | mix-portal | [path] name (string, required)<br>[query] default (string, optional) |
15+
| GET | `/api/v2/rest/mix-portal/get-editor-configs` | Get Editor Configs | mix-portal | |
16+
| GET | `/api/v2/rest/mix-portal/global-settings` | Get Global Settings | mix-portal | |
17+
| GET | `/api/v2/rest/mix-portal/health-check/readiness` | Health check | mix-portal | |
18+
| GET | `/api/v2/rest/mix-portal/heartbeat` | Health check | mix-portal | |
19+
| GET | `/api/v2/rest/mix-portal/init-data` | Get Init Data | mix-portal | |
20+
| POST | `/api/v2/rest/mix-portal/init-data` | Get Init Data | mix-portal | [body] model (object, optional) |
21+
| GET | `/api/v2/rest/mix-portal/init` | Check Is Init | mix-portal | |
22+
| GET | `/api/v2/rest/mix-portal/is-pwa` | Get Is PWA | mix-portal | |
23+
| GET | `/api/v2/rest/mix-portal/languages` | Get Languages | mix-portal | |
24+
| POST | `/api/v2/rest/mix-portal/login` | Login | mix-portal | [body] model (object, optional) |
25+
| POST | `/api/v2/rest/mix-portal/register` | Register | mix-portal | [body] model (object, optional) |
26+
| GET | `/api/v2/rest/mix-portal/remove-cache/{key}` | Remove Cache | mix-portal | [path] key (string, required) |
27+
| POST | `/api/v2/rest/mix-portal/save-global-settings` | Save Global Settings | mix-portal | [body] model (object, optional) |
28+
| POST | `/api/v2/rest/mix-portal/save-settings` | Save Settings | mix-portal | [body] model (object, optional) |
29+
| POST | `/api/v2/rest/mix-portal/send-pwa-push` | Send PWA Push | mix-portal | [body] model (object, optional) |
30+
| GET | `/api/v2/rest/mix-portal/theme-export` | Exports themes | mix-portal | |
31+
| POST | `/api/v2/rest/mix-portal/theme-import` | Imports themes | mix-portal | |
32+
| GET | `/api/v2/rest/mix-portal/theme-sync/{id}` | Sync Theme | mix-portal | [path] id (integer, required) |
33+
| POST | `/api/v2/rest/mix-portal/toggle-pwa` | Toggle PWA | mix-portal | [body] isPWA (boolean, optional) |
34+
| POST | `/api/v2/rest/mix-portal/translate` | Translate | mix-portal | [body] model (object, optional) |
35+
| GET | `/api/v2/rest/mix-portal` | Get List | mix-portal | [query] keyword (string, optional)<br>[query] orderBy (string, optional)<br>[query] direction (string, optional)<br>[query] pageSize (integer, optional)<br>[query] pageIndex (integer, optional) |
36+
| DELETE | `/api/v2/rest/mix-portal/delete/{id}` | Delete One | mix-portal | [path] id (string, required) |
37+
| POST | `/api/v2/rest/mix-portal/export` | Export Data | mix-portal | [body] request (object, optional) |
38+
| GET | `/api/v2/rest/mix-portal/get-by/{id}` | Get Single | mix-portal | [path] id (string, required) |
39+
| POST | `/api/v2/rest/mix-portal/save` | Create / Update | mix-portal | [body] model (object, optional) |
40+
| POST | `/api/v2/rest/mix-portal/update-infos` | Bulk Update | mix-portal | [body] model (object, optional) |
41+
| GET | `/api/v2/rest/mix-portal/theme` | Get List Theme | mix-portal, theme | [query] keyword (string, optional)<br>[query] pageSize (integer, optional)<br>[query] pageIndex (integer, optional) |
42+
| POST | `/api/v2/rest/mix-portal/theme/delete/{id}` | Delete Theme | mix-portal, theme | [path] id (integer, required) |
43+
| POST | `/api/v2/rest/mix-portal/theme/install/{id}` | Install Theme | mix-portal, theme | [path] id (integer, required) |
44+
| GET | `/api/v2/rest/mix-portal/theme/get-by/{id}` | Get Theme | mix-portal, theme | [path] id (integer, required) |
45+
| POST | `/api/v2/rest/mix-portal/theme/save` | Save Theme | mix-portal, theme | [body] model (object, optional) |
46+
| POST | `/api/v2/rest/shared/decrypt` | Encrypt string | shared | [body] source (string, optional) |
47+
| POST | `/api/v2/rest/shared/encrypt` | Encrypt string | shared | [body] source (string, optional) |
48+
| POST | `/api/v2/rest/shared/get-firebase-token` | Get Encrypted firebase settings | shared | [body] session (object, optional) |
49+
| GET | `/api/v2/rest/shared/get-ip-info` | Get Ip Info | shared | |
50+
| POST | `/api/v2/rest/shared/upload-file` | Upload File | shared | |
51+
| POST | `/api/v2/rest/shared/upload-files` | Upload multiple files | shared | |
52+
| POST | `/api/v2/rest/{culture}/attribute-set-data/filter` | Filter | {culture}-attribute-set-data | [path] culture (string, required)<br>[body] request (object, optional) |
53+
| GET | `/api/v2/rest/{culture}/attribute-set/default` | Get Default | {culture}-attribute-set | [path] culture (string, required) |
54+
| POST | `/api/v2/rest/{culture}/configuration/save` | Create / Update | {culture}-configuration | [path] culture (string, required)<br>[body] model (object, optional) |
55+
| POST | `/api/v2/rest/{culture}/file/save` | Create / Update | {culture}-file | [path] culture (string, required)<br>[body] model (object, optional) |
56+
| POST | `/api/v2/rest/{culture}/language/save` | Create / Update | {culture}-language | [path] culture (string, required)<br>[body] model (object, optional) |
57+
| POST | `/api/v2/rest/{culture}/mix-database-data/get-by-parent/{parentId}` | Get MixDatabaseData By Parent Id | {culture}-mix-database-data | [path] culture (string, required)<br>[path] parentId (string, required)<br>[body] request (object, optional) |
58+
| POST | `/api/v2/rest/{culture}/mix-database/get-by-name` | Get MixDatabase By Name | {culture}-mix-database | [path] culture (string, required)<br>[body] name (string, optional) |
59+
| GET | `/api/v2/rest/{culture}/module-data/get-by-parent-id/{id}` | Get Module Data by parent | {culture}-module-data | [path] culture (string, required)<br>[path] id (integer, required)<br>[query] keyword (string, optional)<br>[query] orderBy (string, optional)<br>[query] direction (string, optional)<br>[query] pageSize (integer, optional)<br>[query] pageIndex (integer, optional) |
60+
| GET | `/api/v2/rest/{culture}/module/restore-default/{id}` | Restore Default Template | {culture}-module | [path] culture (string, required)<br>[path] id (integer, required) |
61+
| POST | `/api/v2/rest/{culture}/page-module/update-positions` | Update page modules positions | {culture}-page-module | [path] culture (string, required)<br>[body] model (object, optional) |
62+
| GET | `/api/v2/rest/{culture}/page/get-by-url` | Get Page By Url | {culture}-page | [path] culture (string, required)<br>[query] url (string, optional) |
63+
| GET | `/api/v2/rest/{culture}/post/get-by-url` | Get Post By Url | {culture}-post | [path] culture (string, required)<br>[query] url (string, optional) |
64+
| GET | `/api/v2/rest/{culture}/theme/get-by-name/{name}` | Get Theme By Name | {culture}-theme | [path] culture (string, required)<br>[path] name (string, required) |
65+
| GET | `/api/v2/rest/{culture}/url-alias/get-by-alias` | Get Url Alias By Alias | {culture}-url-alias | [path] culture (string, required)<br>[query] alias (string, optional) |
66+
| GET | `/api/v2/rest/{culture}/{controller}/default` | Get Default | {culture}-{controller} | [path] culture (string, required)<br>[path] controller (string, required) |
67+
| GET | `/api/v2/rest/{culture}/{controller}` | Get List | {culture}-{controller} | [path] culture (string, required)<br>[path] controller (string, required)<br>[query] keyword (string, optional)<br>[query] orderBy (string, optional)<br>[query] direction (string, optional)<br>[query] pageSize (integer, optional)<br>[query] pageIndex (integer, optional) |
68+
| GET | `/api/v2/rest/{culture}/{controller}/delete/{id}` | Delete One | {culture}-{controller} | [path] culture (string, required)<br>[path] controller (string, required)<br>[path] id (string, required) |
69+
| POST | `/api/v2/rest/{culture}/{controller}/duplicate/{id}` | Duplicate | {culture}-{controller} | [path] culture (string, required)<br>[path] controller (string, required)<br>[path] id (string, required) |
70+
| POST | `/api/v2/rest/{culture}/{controller}/export` | Export Data | {culture}-{controller} | [path] culture (string, required)<br>[path] controller (string, required)<br>[body] request (object, optional) |
71+
| GET | `/api/v2/rest/{culture}/{controller}/{id}` | Get Single | {culture}-{controller} | [path] culture (string, required)<br>[path] controller (string, required)<br>[path] id (string, required) |
72+
| POST | `/api/v2/rest/{culture}/{controller}/save` | Create / Update | {culture}-{controller} | [path] culture (string, required)<br>[path] controller (string, required)<br>[body] model (object, optional) |
73+
| POST | `/api/v2/rest/{culture}/{controller}/update-infos` | Bulk Update | {culture}-{controller} | [path] culture (string, required)<br>[path] controller (string, required)<br>[body] model (object, optional) |
74+
| GET | `/api/v2/rest` | Get all endpoint | | |
75+
| POST | `/api/v2/rest/mix-media/get-by-url` | Get Media By Url | mix-media | [body] model (object, optional) |
76+
| POST | `/api/v2/rest/mix-post/get-by-url` | Get Post By Url | mix-post | [body] model (object, optional) |
77+
| POST | `/api/v2/rest/mix-template/get-by-name` | Get Template By Name | mix-template | [body] model (object, optional) |
78+
| GET | `/api/v2/rest/portal/app-settings/get-by-name` | Get App Settings | portal | [query] name (string, optional) |
79+
| POST | `/api/v2/rest/portal/app-settings/save` | Save App Settings | portal | [body] model (object, optional) |
80+
| GET | `/api/v2/rest/portal/configurations/get-by-keyword/{keyword}` | Get Configuration by keyword | portal | [path] keyword (string, required) |
81+
| GET | `/api/v2/rest/portal/culture/get-by-code/{code}` | Get Language by code | portal | [path] code (string, required) |
82+
| GET | `/api/v2/rest/portal/culture` | Get list languages | portal | |
83+
| POST | `/api/v2/rest/portal/translate/jarray` | Translate array object | portal | [body] data (object, optional)<br>[query] srcLang (string, optional)<br>[query] destLang (string, optional) |
84+
| POST | `/api/v2/rest/portal/translate` | Translate object | portal | [body] data (object, optional)<br>[query] srcLang (string, optional)<br>[query] destLang (string, optional) |
85+
| GET | `/api/v2/rest/portal/translator/get-by-keyword` | Get Translator by keyword | portal | [query] keyword (string, optional)<br>[query] culture (string, optional)<br>[query] default (string, optional) |

packages/api/tests/api-services.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ describe('ApiService', () => {
1818
});
1919

2020
it('should fail login with invalid credentials (POST)', async () => {
21+
jest.setTimeout(10000); // Increase timeout to 10 seconds
2122
try {
2223
await service.post('/api/v2/rest/auth/user/login', {
2324
username: 'invalid',

packages/database/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"lint": "eslint src --ext .ts"
1212
},
1313
"dependencies": {
14-
"@mixcore/api": "workspace:*"
14+
"@mixcore/api": "workspace:*",
15+
"@mixcore/base": "workspace:*"
1516
},
1617
"license": "SEE LICENSE IN LICENSE",
1718
"repository": "https://github.com/mixcore/javascript-sdk",

packages/database/tests/mix-database-rest-portal-service.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { ApiService } from './api-services';
2-
import { MixDatabaseRestPortalService } from './mix-database-rest-portal-service';
1+
import { ApiService, ApiResult } from '@mixcore/api';
2+
import { MixDatabaseRestPortalService } from '../src/mix-database-rest-portal-service';
33

44
describe('MixDatabaseRestPortalService', () => {
55
let api: ApiService;

packages/file/tests/file-services-portal.test.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { ApiService } from './api-services';
2-
import { FileServicesPortal } from './file-services-portal';
1+
import { ApiService } from '@mixcore/api';
2+
import { FileServicesPortal } from '../src/file-services';
33

44
describe('FileServicesPortal', () => {
55
let api: ApiService;
66
let fileServices: FileServicesPortal;
77

88
beforeEach(() => {
9-
api = new ApiService({ apiBaseUrl: 'http://localhost/api/' });
9+
api = new ApiService({ apiBaseUrl: 'https://mixcore.net/api/' });
1010
fileServices = new FileServicesPortal(api);
1111
});
1212

@@ -17,13 +17,19 @@ describe('FileServicesPortal', () => {
1717
it('should call getFile', async () => {
1818
globalThis.fetch = jest.fn().mockResolvedValue({ ok: true, json: async () => ({ file: 'data' }) });
1919
const result = await fileServices.getFile('folder', 'file.txt');
20-
expect(result).toEqual({ file: 'data' });
20+
expect(result).toEqual({
21+
isSucceed: true,
22+
data: { file: 'data' }
23+
});
2124
});
2225

2326
it('should call saveFile', async () => {
2427
globalThis.fetch = jest.fn().mockResolvedValue({ ok: true, json: async () => ({ success: true }) });
2528
const result = await fileServices.saveFile({ name: 'file.txt' });
26-
expect(result).toEqual({ success: true });
29+
expect(result).toEqual({
30+
isSucceed: true,
31+
data: { success: true }
32+
});
2733
});
2834

2935
// Add more tests for other methods as needed

packages/template/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"lint": "eslint src --ext .ts"
1212
},
1313
"dependencies": {
14-
"@mixcore/api": "workspace:*"
14+
"@mixcore/api": "workspace:*",
15+
"@mixcore/shared": "workspace:*"
1516
},
1617
"license": "SEE LICENSE IN LICENSE",
1718
"repository": "https://github.com/mixcore/javascript-sdk",

packages/template/tests/template-services.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { ApiService } from './src/api-services';
2-
import { TemplateService } from './src/template-services';
1+
import { ApiService } from '@mixcore/api';
2+
import { TemplateService } from '../src/template-service';
33

44
describe('TemplateService', () => {
55
let api: ApiService;

packages/user/src/auth-services.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,4 +261,41 @@ export class AuthService {
261261
const roles = this.authentication.info.userRoles || [];
262262
return roles.some((m: any) => m.description === roleName && m.isActived);
263263
}
264+
265+
async getRoles(): Promise<ApiResult> {
266+
return this.config.getApiResult({
267+
method: 'GET',
268+
url: '/api/v2/rest/auth/role'
269+
});
270+
}
271+
272+
async createRole(data: {description: string}): Promise<ApiResult> {
273+
return this.config.getApiResult({
274+
method: 'POST',
275+
url: '/api/v2/rest/auth/role/create',
276+
data
277+
});
278+
}
279+
280+
async updateRole(id: string, data: {description: string}): Promise<ApiResult> {
281+
return this.config.getApiResult({
282+
method: 'PUT',
283+
url: `/api/v2/rest/auth/role/${id}`,
284+
data
285+
});
286+
}
287+
288+
async deleteRole(id: string): Promise<ApiResult> {
289+
return this.config.getApiResult({
290+
method: 'DELETE',
291+
url: `/api/v2/rest/auth/role/${id}`
292+
});
293+
}
294+
295+
async getDefaultRole(): Promise<ApiResult> {
296+
return this.config.getApiResult({
297+
method: 'GET',
298+
url: '/api/v2/rest/auth/role/default'
299+
});
300+
}
264301
}

packages/user/tests/auth-services.test.ts

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,41 @@
1-
import { AuthService, AuthServiceConfig } from './auth-services';
1+
import { AuthService, AuthServiceConfig } from '../src/auth-services';
22

33
describe('AuthService', () => {
44
const config: AuthServiceConfig = {
55
apiBaseUrl: 'https://mixcore.net',
66
encryptAES: (data) => data, // mock encryption
77
updateAuthData: jest.fn(),
8-
fillAuthData: jest.fn(async () => ({ info: { userRoles: [{ description: 'Admin', isActived: true }] } })),
8+
fillAuthData: jest.fn(async () => ({
9+
info: {
10+
userRoles: [{
11+
id: '1',
12+
description: 'Admin',
13+
isActived: true
14+
}],
15+
accessToken: 'mock-access-token',
16+
refreshToken: 'mock-refresh-token'
17+
}
18+
})),
919
initAllSettings: jest.fn(async () => {}),
10-
getApiResult: jest.fn(async (req) => ({ isSucceed: true, data: {} })),
11-
getRestApiResult: jest.fn(async (req) => ({ isSucceed: true, data: {} })),
20+
getApiResult: jest.fn(async (req) => ({
21+
isSucceed: true,
22+
data: {
23+
id: '1',
24+
description: 'Test Role'
25+
}
26+
})),
27+
getRestApiResult: jest.fn(async (req) => ({
28+
isSucceed: true,
29+
data: {
30+
id: '1',
31+
description: 'Test Role'
32+
}
33+
})),
1234
localStorage: { removeItem: jest.fn() } as any,
1335
};
1436
const service = new AuthService(config);
1537

38+
// Existing auth tests
1639
it('should call saveRegistration', async () => {
1740
await service.saveRegistration({});
1841
expect(config.getApiResult).toHaveBeenCalled();
@@ -37,4 +60,60 @@ describe('AuthService', () => {
3760
await service.fillAuthData();
3861
expect(service.isInRole('Admin')).toBe(true);
3962
});
63+
64+
// Role management tests
65+
it('should get role list', async () => {
66+
const result = await service.getRoles();
67+
expect(result).toEqual({
68+
isSucceed: true,
69+
data: {
70+
id: '1',
71+
description: 'Test Role'
72+
}
73+
});
74+
});
75+
76+
it('should create role', async () => {
77+
const result = await service.createRole({ description: 'New Role' });
78+
expect(result).toEqual({
79+
isSucceed: true,
80+
data: {
81+
id: '1',
82+
description: 'Test Role'
83+
}
84+
});
85+
});
86+
87+
it('should update role', async () => {
88+
const result = await service.updateRole('1', { description: 'Updated Role' });
89+
expect(result).toEqual({
90+
isSucceed: true,
91+
data: {
92+
id: '1',
93+
description: 'Test Role'
94+
}
95+
});
96+
});
97+
98+
it('should delete role', async () => {
99+
const result = await service.deleteRole('1');
100+
expect(result).toEqual({
101+
isSucceed: true,
102+
data: {
103+
id: '1',
104+
description: 'Test Role'
105+
}
106+
});
107+
});
108+
109+
it('should get default role', async () => {
110+
const result = await service.getDefaultRole();
111+
expect(result).toEqual({
112+
isSucceed: true,
113+
data: {
114+
id: '1',
115+
description: 'Test Role'
116+
}
117+
});
118+
});
40119
});

0 commit comments

Comments
 (0)