@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.
- package/README.md +91 -2
- package/package.json +1 -1
- package/src/{appSdk.ts → dataIslandApp.ts} +1 -1
- package/src/disposable.ts +2 -3
- package/src/dto/workspacesResponse.ts +2 -2
- package/src/events.ts +12 -12
- package/src/index.ts +27 -10
- package/src/internal/app.impl.ts +9 -12
- package/src/internal/createApp.impl.ts +4 -4
- package/src/services/middlewareService.ts +1 -1
- package/src/services/requestBuilder.ts +35 -10
- package/src/services/rpcService.ts +23 -6
- package/src/services/service.ts +7 -5
- package/src/storages/chat.ts +0 -16
- package/src/storages/chats.ts +17 -0
- package/src/storages/file.impl.ts +5 -4
- package/src/storages/file.ts +28 -0
- package/src/storages/files.impl.ts +40 -19
- package/src/storages/files.ts +12 -41
- package/src/storages/filesPage.ts +27 -0
- package/src/storages/groups.impl.ts +10 -10
- package/src/storages/organizations.impl.ts +1 -1
- package/src/storages/workspace.impl.ts +1 -1
- package/src/storages/workspace.ts +6 -0
- package/src/storages/workspaces.impl.ts +1 -1
- package/src/unitTest.ts +12 -1
- package/test/commands.test.ts +4 -4
- package/test/files.test.ts +52 -0
- package/test/index.test.ts +22 -125
- package/test/organization.test.ts +57 -0
- package/test/services.test.ts +4 -4
- package/test/setup.ts +52 -0
- package/test/unitTest.test.ts +7 -7
- package/test/workspace.test.ts +71 -0
- /package/{test_file.pdf → test/data/test_file.pdf} +0 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
import { dataIslandApp, DebugCredential } from "../src"
|
2
|
+
import { HOST, randomHash, TOKEN } from "./setup"
|
3
|
+
import { OrganizationImpl } from "../src/storages/organization.impl"
|
4
|
+
|
5
|
+
test("Organization", async () => {
|
6
|
+
// make random name
|
7
|
+
const randomName = `org-test-${randomHash()}`
|
8
|
+
|
9
|
+
// create app
|
10
|
+
const app = await dataIslandApp(randomName, async builder => {
|
11
|
+
builder.useHost(HOST)
|
12
|
+
builder.useCredential(new DebugCredential(TOKEN))
|
13
|
+
})
|
14
|
+
|
15
|
+
// save init length
|
16
|
+
const initLength = app.organizations.collection.length
|
17
|
+
|
18
|
+
// create organization
|
19
|
+
const org = await app.organizations.create(
|
20
|
+
randomName,
|
21
|
+
"this is a unitTest description"
|
22
|
+
)
|
23
|
+
|
24
|
+
// check organization
|
25
|
+
expect(org).not.toBeUndefined()
|
26
|
+
expect(org).not.toBeNull()
|
27
|
+
expect(org).toBeInstanceOf(OrganizationImpl)
|
28
|
+
|
29
|
+
expect(org.id).not.toBeUndefined()
|
30
|
+
expect(org.id).not.toBeNull()
|
31
|
+
expect(org.id.trim()).not.toBe("")
|
32
|
+
|
33
|
+
// check name
|
34
|
+
expect(org.name).not.toBeUndefined()
|
35
|
+
expect(org.name).not.toBeNull()
|
36
|
+
expect(org.name.trim()).not.toBe("")
|
37
|
+
|
38
|
+
// check description
|
39
|
+
expect(org.description).not.toBeUndefined()
|
40
|
+
expect(org.description).not.toBeNull()
|
41
|
+
expect(org.description.trim()).not.toBe("")
|
42
|
+
|
43
|
+
// check organizations
|
44
|
+
expect(app.organizations.get(org.id)).toBe(org)
|
45
|
+
expect(app.organizations.tryGet(org.id)).toBe(org)
|
46
|
+
expect(app.organizations.collection.length).toBe(initLength + 1)
|
47
|
+
|
48
|
+
// delete organization
|
49
|
+
await expect(app.organizations.delete(org.id)).resolves.not.toThrow()
|
50
|
+
expect((<OrganizationImpl>org).isDisposed).toBe(true)
|
51
|
+
|
52
|
+
// check init length
|
53
|
+
expect(app.organizations.collection.length).toBe(initLength)
|
54
|
+
|
55
|
+
// check organization must be undefined because it was deleted
|
56
|
+
expect(app.organizations.tryGet(org.id)).toBeUndefined()
|
57
|
+
})
|
package/test/services.test.ts
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
import {
|
1
|
+
import { dataIslandApp, BasicCredential, DefaultCredential } from "../src"
|
2
2
|
import { CredentialService } from "../src/services/credentialService"
|
3
3
|
import { MiddlewareService } from "../src/services/middlewareService"
|
4
|
-
import { UnitTest,
|
4
|
+
import { UnitTest, appTest } from "../src/unitTest"
|
5
5
|
|
6
6
|
test("CredentialService", async () => {
|
7
|
-
await
|
8
|
-
const app = await
|
7
|
+
await appTest(UnitTest.DEFAULT, async () => {
|
8
|
+
const app = await dataIslandApp("test-services", async builder => {
|
9
9
|
builder.env.unitTest = UnitTest.DO_NOT_START
|
10
10
|
})
|
11
11
|
const credentialService = app.resolve(CredentialService)
|
package/test/setup.ts
CHANGED
@@ -1,2 +1,54 @@
|
|
1
|
+
import { dataIslandApp, DataIslandApp, DebugCredential } from "../src"
|
2
|
+
import { Organization } from "../src"
|
3
|
+
import { Workspace } from "../src"
|
4
|
+
|
1
5
|
export const HOST = <string>process.env.HOST
|
2
6
|
export const TOKEN = <string>process.env.TOKEN
|
7
|
+
|
8
|
+
export const randomHash = (length: number = 5) => {
|
9
|
+
if (length <= 0) length = 1
|
10
|
+
return `name-${((Math.random() * Math.pow(10, length)) | 0).toString(16)}`
|
11
|
+
}
|
12
|
+
|
13
|
+
export const testInOrganization = async (func: (app: DataIslandApp, org: Organization) => Promise<void>, config ?: {
|
14
|
+
host: string,
|
15
|
+
token: string
|
16
|
+
}
|
17
|
+
): Promise<void> => {
|
18
|
+
const randomName = `org-name-${randomHash()}`
|
19
|
+
const app = await dataIslandApp(randomName, async builder => {
|
20
|
+
builder.useHost(config?.host ?? HOST)
|
21
|
+
builder.useCredential(new DebugCredential(config?.token ?? TOKEN))
|
22
|
+
})
|
23
|
+
const org = await app.organizations.create(
|
24
|
+
randomName,
|
25
|
+
"this is a unitTest description"
|
26
|
+
)
|
27
|
+
try {
|
28
|
+
await func(app, org)
|
29
|
+
} finally {
|
30
|
+
if (app
|
31
|
+
.organizations.tryGet(org.id)
|
32
|
+
) {
|
33
|
+
await app.organizations.delete(org.id)
|
34
|
+
}
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
export const testInWorkspace = async (func: (app: DataIslandApp, org: Organization, workspace: Workspace)
|
39
|
+
=> Promise<void>, config?: {
|
40
|
+
host: string,
|
41
|
+
token: string,
|
42
|
+
}): Promise<void> => {
|
43
|
+
await testInOrganization(async (app, org) => {
|
44
|
+
const randomName = `workspace-${randomHash()}`
|
45
|
+
const workspace = await org.workspaces.create(randomName, `description of ${randomName}`)
|
46
|
+
try {
|
47
|
+
await func(app, org, workspace)
|
48
|
+
} finally {
|
49
|
+
if (org.workspaces.tryGet(workspace.id)) {
|
50
|
+
await org.workspaces.delete(workspace.id)
|
51
|
+
}
|
52
|
+
}
|
53
|
+
}, config)
|
54
|
+
}
|
package/test/unitTest.test.ts
CHANGED
@@ -1,21 +1,21 @@
|
|
1
|
-
import {
|
1
|
+
import { appTest, appTestCurrent, UnitTest } from "../src/unitTest"
|
2
2
|
|
3
3
|
test("SDK, unitTest", async () => {
|
4
|
-
expect(
|
4
|
+
expect(appTestCurrent()).toBe(UnitTest.DO_NOTHING)
|
5
5
|
expect(
|
6
|
-
await
|
7
|
-
expect(
|
6
|
+
await appTest(UnitTest.DO_NOT_PRINT_INITIALIZED_LOG, () => {
|
7
|
+
expect(appTestCurrent()).toBe(UnitTest.DO_NOT_PRINT_INITIALIZED_LOG)
|
8
8
|
})
|
9
9
|
)
|
10
10
|
expect(
|
11
|
-
await
|
11
|
+
await appTest(
|
12
12
|
UnitTest.DO_NOT_PRINT_INITIALIZED_LOG,
|
13
13
|
async () => {
|
14
|
-
expect(
|
14
|
+
expect(appTestCurrent()).toBe(
|
15
15
|
UnitTest.DO_NOT_PRINT_INITIALIZED_LOG
|
16
16
|
)
|
17
17
|
}
|
18
18
|
)
|
19
19
|
)
|
20
|
-
expect(
|
20
|
+
expect(appTestCurrent()).toBe(UnitTest.DO_NOTHING)
|
21
21
|
})
|
@@ -0,0 +1,71 @@
|
|
1
|
+
import { testInOrganization, testInWorkspace } from "./setup"
|
2
|
+
|
3
|
+
test("Workspace create / delete", async () => {
|
4
|
+
await testInOrganization(async (app, org) => {
|
5
|
+
// save init length
|
6
|
+
const initWorkspaceCount = org.workspaces.collection.length
|
7
|
+
|
8
|
+
// create workspace
|
9
|
+
const wsPromise = org.workspaces.create(
|
10
|
+
"test-workspace",
|
11
|
+
"test-workspace-description"
|
12
|
+
)
|
13
|
+
|
14
|
+
// check not throw
|
15
|
+
await expect(wsPromise).resolves.not.toThrow()
|
16
|
+
|
17
|
+
// get workspace
|
18
|
+
const ws = await wsPromise
|
19
|
+
|
20
|
+
// check exists
|
21
|
+
expect(ws).not.toBeUndefined()
|
22
|
+
|
23
|
+
// check exists
|
24
|
+
expect(ws).not.toBeNull()
|
25
|
+
|
26
|
+
// check name
|
27
|
+
expect(ws.name).toBe("test-workspace")
|
28
|
+
|
29
|
+
// check description
|
30
|
+
expect(ws.description).toBe("test-workspace-description")
|
31
|
+
|
32
|
+
// check collection length
|
33
|
+
expect(app.organizations.get(org.id).workspaces.collection.length).toBe(
|
34
|
+
initWorkspaceCount + 1
|
35
|
+
)
|
36
|
+
|
37
|
+
// check collection length
|
38
|
+
expect(org.workspaces.collection.length).toBe(initWorkspaceCount + 1)
|
39
|
+
|
40
|
+
// check get
|
41
|
+
expect(org.workspaces.get(ws.id)).toBe(ws)
|
42
|
+
|
43
|
+
// check tryGet
|
44
|
+
expect(org.workspaces.tryGet(ws.id)).toBe(ws)
|
45
|
+
|
46
|
+
// check contains
|
47
|
+
expect(org.workspaces.contains(ws.id)).toBe(true)
|
48
|
+
|
49
|
+
// check delete
|
50
|
+
await expect(org.workspaces.delete(ws.id)).resolves.not.toThrow()
|
51
|
+
})
|
52
|
+
})
|
53
|
+
|
54
|
+
test("Workspace, change", async () => {
|
55
|
+
await testInWorkspace(async (app, org, ws) => {
|
56
|
+
|
57
|
+
expect(ws.name).not.toBe("new-name")
|
58
|
+
|
59
|
+
// rename
|
60
|
+
await ws.change("new-name", "new-description")
|
61
|
+
|
62
|
+
// check name
|
63
|
+
expect(ws.name).toBe("new-name")
|
64
|
+
|
65
|
+
// check description
|
66
|
+
expect(ws.description).toBe("new-description")
|
67
|
+
|
68
|
+
// check name
|
69
|
+
expect(ws.name).toBe("new-name")
|
70
|
+
})
|
71
|
+
})
|
File without changes
|