@neuralinnovations/dataisland-sdk 0.0.1-dev3 → 0.0.1-dev5

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,12 +1,13 @@
1
1
  import { Context } from "../context"
2
2
  import { Disposable } from "../disposable"
3
3
  import { FileDto, FileListResponse } from "../dto/workspacesResponse"
4
- import { OrganizationService } from "../services/organizationService"
5
4
  import { RpcService } from "../services/rpcService"
6
5
  import { FileImpl } from "./file.impl"
7
- import { File, Files, FilesEvent, FilesList as FilesPage } from "./files"
6
+ import { Files, FilesEvent, UploadFile } from "./files"
8
7
  import { WorkspaceImpl } from "./workspace.impl"
9
8
  import { ResponseUtils } from "../services/responseUtils"
9
+ import { File } from "./file"
10
+ import { FilesPage } from "./filesPage"
10
11
 
11
12
  export class FilesPageImpl extends FilesPage implements Disposable {
12
13
  private _isDisposed: boolean = false
@@ -100,9 +101,16 @@ export class FilesImpl extends Files {
100
101
  page: number,
101
102
  limit: number
102
103
  ): Promise<FilesPage> {
104
+
105
+ // check page
103
106
  if (page === undefined || page === null) {
104
107
  throw new Error("File fetch, page is undefined or null")
105
108
  }
109
+ if (page < 0) {
110
+ throw new Error("File fetch, page is negative")
111
+ }
112
+
113
+ // check limit
106
114
  if (limit === undefined || limit === null) {
107
115
  throw new Error("File fetch, limit is undefined or null")
108
116
  }
@@ -110,23 +118,19 @@ export class FilesImpl extends Files {
110
118
  throw new Error("File fetch, limit is 0")
111
119
  }
112
120
 
113
- const orgService = this.context.resolve(OrganizationService)
114
-
115
- if (orgService === undefined) {
116
- throw new Error("File fetch, organization service undefined")
117
- }
118
-
121
+ // send request to the server
119
122
  const response = await this.context
120
123
  .resolve(RpcService)
121
124
  ?.requestBuilder("api/v1/Files/list")
122
125
 
123
126
  .searchParam("workspaceId", this.workspace.id)
124
- .searchParam("organizationId", orgService.organizations.current)
127
+ .searchParam("organizationId", this.workspace.organization.id)
125
128
  .searchParam("query", query)
126
129
  .searchParam("page", page.toString())
127
130
  .searchParam("limit", limit.toString())
128
131
  .sendGet()
129
132
 
133
+ // check response status
130
134
  if (ResponseUtils.isFail(response)) {
131
135
  await ResponseUtils.throwError(
132
136
  `Files fetch query:${query}, page:${page}, limit:${limit}, failed`,
@@ -134,57 +138,74 @@ export class FilesImpl extends Files {
134
138
  )
135
139
  }
136
140
 
141
+ // parse files from the server's response
137
142
  const files = (await response!.json()) as FileListResponse
138
143
 
144
+ // create files list
139
145
  const filesList = new FilesPageImpl()
140
146
  filesList.total = files.totalFilesCount
141
147
  filesList.filesPerPage = files.filesPerPage
142
148
  filesList.page = page
149
+
150
+ // init files from the server's response
143
151
  for (const fl of files.files) {
152
+
153
+ // create file implementation
144
154
  const file = new FileImpl(this.context).initFrom(fl)
145
155
 
156
+ // add file to the collection
146
157
  filesList.files.push(file)
147
158
 
159
+ // dispatch event, file added
148
160
  this.dispatch({
149
161
  type: FilesEvent.ADDED,
150
162
  data: file
151
163
  })
152
164
  }
153
165
 
166
+ // set files list
154
167
  this.filesList = filesList
155
168
 
156
169
  return filesList
157
170
  }
158
171
 
159
- async internalUpload(file: any): Promise<File> {
160
- const orgService = this.context.resolve(OrganizationService)
161
-
162
- if (orgService === undefined) {
163
- throw new Error("File load, organization service undefined")
172
+ async internalUpload(file: UploadFile): Promise<File> {
173
+ // check file
174
+ if (file === undefined || file === null) {
175
+ throw new Error("File upload, file is undefined or null")
164
176
  }
165
177
 
178
+ // form data to send
166
179
  const form = new FormData()
167
- form.append("organizationId", orgService.organizations.current)
180
+ form.append("organizationId", this.workspace.organization.id)
168
181
  form.append("workspaceId", this.workspace.id)
169
182
  form.append("name", file.name)
170
183
  form.append("file", file, file.name)
171
184
 
185
+ // send request to the server
172
186
  const response = await this.context
173
187
  .resolve(RpcService)
174
188
  ?.requestBuilder("api/v1/Files")
175
- .sendPost(form)
189
+ .sendPostFormData(form)
190
+
191
+ // check response status
176
192
  if (ResponseUtils.isFail(response)) {
177
- await ResponseUtils.throwError(`File upload ${file}`, response)
193
+ await ResponseUtils.throwError(`File upload ${file.name}`, response)
178
194
  }
195
+
196
+ // parse file from the server's response
179
197
  const result = (await response!.json()).file as FileDto
180
198
 
199
+ // create file implementation
181
200
  const fileImpl = new FileImpl(this.context).initFrom(result)
182
201
 
183
- this.filesList!.files.push(file)
202
+ // TODO: why is this here?
203
+ this.filesList?.files.push(fileImpl)
184
204
 
205
+ // dispatch event, file added
185
206
  this.dispatch({
186
207
  type: FilesEvent.ADDED,
187
- data: file
208
+ data: fileImpl
188
209
  })
189
210
 
190
211
  return fileImpl
@@ -1,39 +1,19 @@
1
- import { FileProgressDto } from '../dto/workspacesResponse'
2
- import { EventDispatcher } from '../events'
3
-
4
- export type FileId = string
1
+ import { EventDispatcher } from "../events"
2
+ import { File, FileId } from "./file"
3
+ import { FilesPage } from "./filesPage"
5
4
 
5
+ /**
6
+ * Files event.
7
+ */
6
8
  export enum FilesEvent {
7
- ADDED = 'added',
8
- REMOVED = 'removed'
9
+ ADDED = "added",
10
+ REMOVED = "removed"
9
11
  }
10
12
 
11
- export type UploadFile = File | Blob | string
12
-
13
13
  /**
14
- * File.
14
+ * Upload file.
15
15
  */
16
- export abstract class File {
17
- /**
18
- * File id.
19
- */
20
- abstract get id(): FileId
21
-
22
- /**
23
- * File name.
24
- */
25
- abstract get name(): string
26
-
27
- /**
28
- * Get temporary url.
29
- */
30
- abstract url(): Promise<string>
31
-
32
- /**
33
- * Get file status.
34
- */
35
- abstract status(): Promise<FileProgressDto>
36
- }
16
+ export type UploadFile = globalThis.File
37
17
 
38
18
  /**
39
19
  * Files storage.
@@ -42,7 +22,7 @@ export abstract class Files extends EventDispatcher<FilesEvent, File> {
42
22
  /**
43
23
  * Get file by id.
44
24
  */
45
- abstract upload(file: any): Promise<File>
25
+ abstract upload(file: UploadFile): Promise<File>
46
26
 
47
27
  /**
48
28
  * Delete file.
@@ -53,15 +33,6 @@ export abstract class Files extends EventDispatcher<FilesEvent, File> {
53
33
  /**
54
34
  * Query files.
55
35
  */
56
- abstract query(query: string, page: number, limit: number): Promise<FilesList>
36
+ abstract query(query: string, page: number, limit: number): Promise<FilesPage>
57
37
  }
58
38
 
59
- export abstract class FilesList {
60
- abstract get files(): File[]
61
-
62
- abstract get pages(): number
63
-
64
- abstract get total(): number
65
-
66
- abstract get page(): number
67
- }
@@ -0,0 +1,27 @@
1
+ import { File } from "./file"
2
+
3
+ /**
4
+ * Files page.
5
+ */
6
+ export abstract class FilesPage {
7
+
8
+ /**
9
+ * Get files.
10
+ */
11
+ abstract get files(): File[]
12
+
13
+ /**
14
+ * Get pages count.
15
+ */
16
+ abstract get pages(): number
17
+
18
+ /**
19
+ * Get total count.
20
+ */
21
+ abstract get total(): number
22
+
23
+ /**
24
+ * Get current page.
25
+ */
26
+ abstract get page(): number
27
+ }
@@ -73,12 +73,12 @@ export class GroupImpl extends Group implements Disposable {
73
73
  } catch (e) {
74
74
  console.error(e)
75
75
  }
76
-
76
+
77
77
  throw new Error(
78
78
  `Groups get workspaces, response is not ok, status: ${response?.status},${response?.statusText} ${text}`
79
79
  )
80
80
  }
81
-
81
+
82
82
  const workspaces = (await response.json()) as WorkspacesResponse
83
83
 
84
84
  return workspaces.workspaces
@@ -101,7 +101,7 @@ export class GroupImpl extends Group implements Disposable {
101
101
  const response = await this.context
102
102
  .resolve(RpcService)
103
103
  ?.requestBuilder("api/v1/AccessGroups/name")
104
- .sendPut({
104
+ .sendPutJson({
105
105
  groupId: this.id,
106
106
  name: name
107
107
  })
@@ -117,7 +117,7 @@ export class GroupImpl extends Group implements Disposable {
117
117
  const response = await this.context
118
118
  .resolve(RpcService)
119
119
  ?.requestBuilder("api/v1/AccessGroups/permits")
120
- .sendPut({
120
+ .sendPutJson({
121
121
  groupId: this.id,
122
122
  permits: permits
123
123
  })
@@ -138,7 +138,7 @@ export class GroupImpl extends Group implements Disposable {
138
138
  const response = await this.context
139
139
  .resolve(RpcService)
140
140
  ?.requestBuilder("api/v1/AccessGroups/workspaces")
141
- .sendPut({
141
+ .sendPutJson({
142
142
  groupId: this.id,
143
143
  actualWorkspaceIds: workspaces
144
144
  })
@@ -159,7 +159,7 @@ export class GroupImpl extends Group implements Disposable {
159
159
  const response = await this.context
160
160
  .resolve(RpcService)
161
161
  ?.requestBuilder("api/v1/AccessGroups/members")
162
- .sendPut({
162
+ .sendPutJson({
163
163
  groupId: this.id,
164
164
  memberIds: members
165
165
  })
@@ -227,12 +227,12 @@ export class GroupsImpl extends Groups {
227
227
  } catch (e) {
228
228
  console.error(e)
229
229
  }
230
-
230
+
231
231
  throw new Error(
232
232
  `Groups init, response is not ok, status: ${response?.status},${response?.statusText} ${text}`
233
233
  )
234
234
  }
235
-
235
+
236
236
  const groups = (await response.json()) as AccessGroupsResponse
237
237
 
238
238
  for (const gr of groups.groups){
@@ -258,7 +258,7 @@ export class GroupsImpl extends Groups {
258
258
  const response = await this.context
259
259
  .resolve(RpcService)
260
260
  ?.requestBuilder("api/v1/AccessGroups")
261
- .sendPost({
261
+ .sendPostJson({
262
262
  name: name,
263
263
  organizationId: organizationId,
264
264
  permits: permits,
@@ -333,5 +333,5 @@ export class GroupsImpl extends Groups {
333
333
  group.dispose()
334
334
  }
335
335
 
336
-
336
+
337
337
  }
@@ -130,7 +130,7 @@ export class OrganizationsImpl extends Organizations {
130
130
  const response = await this.context
131
131
  .resolve(RpcService)
132
132
  ?.requestBuilder("api/v1/Organizations")
133
- .sendPost({
133
+ .sendPostJson({
134
134
  profile: {
135
135
  name: name,
136
136
  description: description
@@ -72,7 +72,7 @@ export class WorkspaceImpl extends Workspace {
72
72
  const response = await this.context
73
73
  .resolve(RpcService)
74
74
  ?.requestBuilder("api/v1/Workspaces")
75
- .sendPut({
75
+ .sendPutJson({
76
76
  workspaceId: this.id,
77
77
  profile: {
78
78
  name,
@@ -1,6 +1,7 @@
1
1
  import { EventDispatcher } from "../events"
2
2
  import { Files } from "./files"
3
3
  import { WorkspaceId } from "./workspaces"
4
+ import { Organization } from "./organization"
4
5
 
5
6
  /**
6
7
  * Workspace event.
@@ -16,6 +17,11 @@ export abstract class Workspace extends EventDispatcher<
16
17
  WorkspaceEvent,
17
18
  Workspace
18
19
  > {
20
+ /**
21
+ * Organization.
22
+ */
23
+ abstract get organization(): Organization
24
+
19
25
  /**
20
26
  * Workspace id.
21
27
  */
@@ -87,7 +87,7 @@ export class WorkspacesImpl extends Workspaces {
87
87
  const response = await this.context
88
88
  .resolve(RpcService)
89
89
  ?.requestBuilder("api/v1/Workspaces")
90
- .sendPost({
90
+ .sendPostJson({
91
91
  organizationId: this.organization.id,
92
92
  profile: {
93
93
  name: name,
package/src/unitTest.ts CHANGED
@@ -9,7 +9,7 @@ export enum UnitTest {
9
9
  export type UnitTestProfileSyncAction = () => void
10
10
  export type UnitTestProfileAsyncAction = () => Promise<void>
11
11
 
12
- export class AppSdkUnitTest {
12
+ class AppSdkUnitTest {
13
13
  private static _stack: UnitTest[] = [UnitTest.DO_NOTHING]
14
14
 
15
15
  public static get current(): UnitTest {
@@ -37,6 +37,17 @@ export class AppSdkUnitTest {
37
37
  }
38
38
  }
39
39
 
40
+ export const appTest = async (
41
+ unitTest: UnitTest = UnitTest.DEFAULT,
42
+ func: UnitTestProfileSyncAction | UnitTestProfileAsyncAction
43
+ ): Promise<void> => {
44
+ await AppSdkUnitTest.test(unitTest, func)
45
+ }
46
+
47
+ export const appTestCurrent = (): UnitTest => {
48
+ return AppSdkUnitTest.current
49
+ }
50
+
40
51
  export const isUnitTest = (mask: UnitTest): boolean => {
41
52
  return (AppSdkUnitTest.current & mask) == mask
42
53
  }
@@ -1,6 +1,6 @@
1
1
  import { Command, CommandHandler } from "../src/services/commandService"
2
- import { appSdk } from "../src"
3
- import { UnitTest, AppSdkUnitTest } from "../src/unitTest"
2
+ import { dataIslandApp } from "../src"
3
+ import { appTest, UnitTest } from "../src/unitTest"
4
4
 
5
5
  class Cmd extends Command {
6
6
  constructor(public readonly name: string = "test") {
@@ -15,8 +15,8 @@ class CmdHandler extends CommandHandler<Cmd> {
15
15
  }
16
16
 
17
17
  test("Commands test", async () => {
18
- await AppSdkUnitTest.test(UnitTest.DEFAULT, async () => {
19
- const app = await appSdk("test-commands", async builder => {
18
+ await appTest(UnitTest.DEFAULT, async () => {
19
+ const app = await dataIslandApp("test-commands", async builder => {
20
20
  builder.registerCommand(Cmd, context => new CmdHandler(context))
21
21
  })
22
22
  expect(app.context.execute(new Cmd("test-command"))).toBeDefined()
@@ -0,0 +1,52 @@
1
+ import fs from "fs"
2
+ import { testInWorkspace } from "./setup"
3
+
4
+ test("Files", async () => {
5
+ await testInWorkspace(async (app, org, ws) => {
6
+
7
+ expect(app).not.toBeUndefined()
8
+ expect(org).not.toBeUndefined()
9
+
10
+ const buffer = fs.readFileSync("test/data/test_file.pdf")
11
+ const file_obj = new File([new Uint8Array(buffer)], "test_file.pdf", {
12
+ type: "application/pdf"
13
+ })
14
+
15
+ const filePromise = ws.files.upload(file_obj)
16
+ await expect(filePromise).resolves.not.toThrow()
17
+ const file = await filePromise
18
+
19
+ expect(file).not.toBeUndefined()
20
+ expect(file).not.toBeNull()
21
+ expect(file.name).toBe("test_file.pdf")
22
+
23
+ let status = await file.status()
24
+
25
+ expect(status).not.toBeUndefined()
26
+ expect(status).not.toBeNull()
27
+ if (!status.success && status.error) {
28
+ console.error(status.error)
29
+ }
30
+ expect(status.success).toBe(true)
31
+ expect(status.file_id).toBe(file.id)
32
+ expect(status.file_parts_count).toBeGreaterThanOrEqual(status.completed_parts_count)
33
+
34
+ while (
35
+ status.success &&
36
+ status.completed_parts_count !== status.file_parts_count
37
+ ) {
38
+ await new Promise(r => setTimeout(r, 1000))
39
+ status = await file.status()
40
+ }
41
+
42
+ const queryPromise = ws.files.query("", 0, 20)
43
+ await expect(queryPromise).resolves.not.toThrow()
44
+ const filePage = await queryPromise
45
+ expect(filePage).not.toBeUndefined()
46
+ expect(filePage).not.toBeNull()
47
+ expect(filePage.files.length).toBe(1)
48
+ expect(filePage.pages).toBe(1)
49
+
50
+ await expect(ws.files.delete(file.id)).resolves.not.toThrow()
51
+ })
52
+ })
@@ -1,8 +1,8 @@
1
1
  import { version } from "../package.json"
2
2
  import {
3
- AppSdk,
3
+ DataIslandApp,
4
4
  BasicCredential,
5
- appSdk,
5
+ dataIslandApp,
6
6
  SDK_VERSION,
7
7
  DEFAULT_NAME,
8
8
  DebugCredential
@@ -11,10 +11,8 @@ import { MiddlewareService } from "../src/services/middlewareService"
11
11
  import { CredentialService } from "../src/services/credentialService"
12
12
  import { RpcService } from "../src/services/rpcService"
13
13
  import { AppBuilder } from "../src/appBuilder"
14
- import { UnitTest, AppSdkUnitTest } from "../src/unitTest"
15
- import { HOST, TOKEN } from "./setup"
16
- import { OrganizationImpl } from "../src/storages/organization.impl"
17
- import * as fs from "fs"
14
+ import { UnitTest, appTest } from "../src/unitTest"
15
+ import { HOST, randomHash, TOKEN } from "./setup"
18
16
 
19
17
  test("SDK_VERSION", () => {
20
18
  expect(SDK_VERSION).toBe(version)
@@ -22,120 +20,16 @@ test("SDK_VERSION", () => {
22
20
 
23
21
  test("Default SDK", async () => {
24
22
  // default
25
- const app = await appSdk(DEFAULT_NAME, async (builder: AppBuilder) => {
23
+ const app = await dataIslandApp(DEFAULT_NAME, async (builder: AppBuilder) => {
26
24
  builder.useHost(HOST)
27
25
  builder.useCredential(new DebugCredential(TOKEN))
28
26
  })
29
27
  expect(app).not.toBeUndefined()
30
28
  })
31
29
 
32
- test("Create and delete organization, create and delete workspace", async () => {
33
- const randomName = `org-test-${Math.random().toString(16)}`
34
- const app = await appSdk(randomName, async builder => {
35
- builder.useHost(HOST)
36
- builder.useCredential(new DebugCredential(TOKEN))
37
- })
38
-
39
- const initLength = app.organizations.collection.length
40
-
41
- const org = await app.organizations.create(
42
- randomName,
43
- "this is a unitTest description"
44
- )
45
-
46
- // check organization
47
- expect(org).not.toBeUndefined()
48
- expect(org).not.toBeNull()
49
- expect(org).toBeInstanceOf(OrganizationImpl)
50
-
51
- expect(org.id).not.toBeUndefined()
52
- expect(org.id).not.toBeNull()
53
- expect(org.id.trim()).not.toBe("")
54
-
55
- // check name
56
- expect(org.name).not.toBeUndefined()
57
- expect(org.name).not.toBeNull()
58
- expect(org.name.trim()).not.toBe("")
59
-
60
- // check description
61
- expect(org.description).not.toBeUndefined()
62
- expect(org.description).not.toBeNull()
63
- expect(org.description.trim()).not.toBe("")
64
-
65
- // check organizations
66
- expect(app.organizations.get(org.id)).toBe(org)
67
- expect(app.organizations.tryGet(org.id)).toBe(org)
68
- expect(app.organizations.collection.length).toBe(initLength + 1)
69
-
70
- const initWorkspacesLength = org.workspaces.collection.length
71
-
72
- const wsPromise = org.workspaces.create(
73
- "test-workspace",
74
- "test-workspace-description"
75
- )
76
- await expect(wsPromise).resolves.not.toThrow()
77
- const ws = await wsPromise
78
- expect(ws).not.toBeUndefined()
79
- expect(ws).not.toBeNull()
80
- expect(ws.name).toBe("test-workspace")
81
- expect(ws.description).toBe("test-workspace-description")
82
- expect(app.organizations.get(org.id).workspaces.collection.length).toBe(
83
- initWorkspacesLength + 1
84
- )
85
- expect(org.workspaces.collection.length).toBe(initWorkspacesLength + 1)
86
- expect(org.workspaces.get(ws.id)).toBe(ws)
87
- expect(org.workspaces.tryGet(ws.id)).toBe(ws)
88
- expect(org.workspaces.contains(ws.id)).toBe(true)
89
-
90
- const buffer = fs.readFileSync("test_file.pdf")
91
- const file_obj = new File([new Uint8Array(buffer)], "test_file.pdf", {
92
- type: "text/plain"
93
- })
94
-
95
- const filePromise = ws.files.upload(file_obj)
96
- await expect(filePromise).resolves.not.toThrow()
97
- const file = await filePromise
98
-
99
- expect(file).not.toBeUndefined()
100
- expect(file).not.toBeNull()
101
- expect(file.name).toBe("test_file.pdf")
102
-
103
- let status = await file.status()
104
-
105
- expect(status).not.toBeUndefined()
106
- expect(status).not.toBeNull()
107
- expect(status.file_id).toBe(file.id)
108
- expect(status.file_parts_count).toBeGreaterThan(status.completed_parts_count)
109
-
110
- while (
111
- status.success == true &&
112
- status.completed_parts_count !== status.file_parts_count
113
- ) {
114
- await new Promise(r => setTimeout(r, 1000))
115
- status = await file.status()
116
- }
117
-
118
- const queryPromise = ws.files.query("", 0, 20)
119
- await expect(queryPromise).resolves.not.toThrow()
120
- const filePage = await queryPromise
121
- expect(filePage).not.toBeUndefined()
122
- expect(filePage).not.toBeNull()
123
- expect(filePage.files.length).toBe(1)
124
- expect(filePage.pages).toBe(1)
125
-
126
- await expect(ws.files.delete(file.id)).resolves.not.toThrow()
127
-
128
- await expect(org.workspaces.delete(ws.id)).resolves.not.toThrow()
129
-
130
- await expect(app.organizations.delete(org.id)).resolves.not.toThrow()
131
- expect((<OrganizationImpl>org).isDisposed).toBe(true)
132
- expect(app.organizations.collection.length).toBe(initLength)
133
- expect(app.organizations.tryGet(org.id)).toBeUndefined()
134
- })
135
-
136
30
  test("SDK, middleware", async () => {
137
- await AppSdkUnitTest.test(UnitTest.DEFAULT, async () => {
138
- const app = await appSdk("test-settings", async (builder: AppBuilder) => {
31
+ await appTest(UnitTest.DEFAULT, async () => {
32
+ const app = await dataIslandApp("test-settings", async (builder: AppBuilder) => {
139
33
  builder.useHost("https://test.com")
140
34
  builder.useAutomaticDataCollectionEnabled(false)
141
35
  builder.useCredential(new BasicCredential("email", "password"))
@@ -151,8 +45,8 @@ test("SDK, middleware", async () => {
151
45
  })
152
46
 
153
47
  test("SDK, services", async () => {
154
- await AppSdkUnitTest.test(UnitTest.DEFAULT, async () => {
155
- const app = await appSdk("test-sdk")
48
+ await appTest(UnitTest.DEFAULT, async () => {
49
+ const app = await dataIslandApp("test-sdk")
156
50
  const middlewareService = app.resolve(MiddlewareService)
157
51
  expect(middlewareService).not.toBeUndefined()
158
52
  expect(app.resolve(MiddlewareService)).toBe(middlewareService)
@@ -163,8 +57,8 @@ test("SDK, services", async () => {
163
57
  })
164
58
 
165
59
  test("SDK, middleware", async () => {
166
- await AppSdkUnitTest.test(UnitTest.DEFAULT, async () => {
167
- const app = await appSdk("test-middleware")
60
+ await appTest(UnitTest.DEFAULT, async () => {
61
+ const app = await dataIslandApp("test-middleware")
168
62
  const middlewareService = app.resolve(MiddlewareService)
169
63
  expect(middlewareService).not.toBeUndefined()
170
64
  expect(app.resolve(MiddlewareService)).toBe(middlewareService)
@@ -199,27 +93,30 @@ test("SDK, middleware", async () => {
199
93
  })
200
94
 
201
95
  test("SDK, it is impossible to setup the same application", async () => {
202
- await AppSdkUnitTest.test(UnitTest.DEFAULT, async () => {
96
+ await appTest(UnitTest.DEFAULT, async () => {
203
97
  // this test is not stable if you run all tests at once
204
98
  // because the app is cached all app instances
205
99
  // we use a random identifier every time
206
- const testId = Math.random().toString(16)
207
- const promise = appSdk(`test-setup-${testId}`).then(() => {})
100
+ const testId = `test-setup-${randomHash()}`
101
+ const promise = dataIslandApp(testId).then(() => {
102
+ })
208
103
  await expect(
209
- appSdk(`test-setup-${testId}`, async () => {})
104
+ dataIslandApp(testId, async () => {
105
+ })
210
106
  ).rejects.toThrow()
211
107
  await promise
212
108
  })
213
109
  })
214
110
 
215
111
  test("SDK, setup and get this app", async () => {
216
- await AppSdkUnitTest.test(UnitTest.DEFAULT, async () => {
112
+ await appTest(UnitTest.DEFAULT, async () => {
217
113
  // this test is not stable if you run all tests at once
218
114
  // because the app is cached all app instances
219
115
  // we use a random identifier every time
220
- const testId = Math.random().toString(16)
221
- const promise = appSdk(`test-get-${testId}`).then(() => {})
222
- await expect(appSdk(`test-get-${testId}`)).resolves.toBeInstanceOf(AppSdk)
116
+ const testId = `test-get-${randomHash()}`
117
+ const promise = dataIslandApp(testId).then(() => {
118
+ })
119
+ await expect(dataIslandApp(testId)).resolves.toBeInstanceOf(DataIslandApp)
223
120
  await promise
224
121
  })
225
122
  })