@neuralinnovations/dataisland-sdk 0.0.1-dev2 → 0.0.1-dev4
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/.editorconfig +4 -1
- package/.eslintrc.json +1 -1
- package/README.md +91 -2
- package/jest.config.ts +3 -3
- package/jest.setup.ts +2 -2
- package/package.json +3 -2
- package/src/appBuilder.ts +6 -6
- package/src/appSdk.ts +6 -6
- package/src/commands/startCommandHandler.ts +2 -2
- package/src/context.ts +3 -3
- package/src/credentials.ts +29 -7
- package/src/disposable.ts +3 -4
- package/src/dto/accessGroupResponse.ts +35 -0
- package/src/dto/chatResponse.ts +104 -0
- package/src/dto/userInfoResponse.ts +11 -1
- package/src/dto/workspacesResponse.ts +49 -0
- package/src/events.ts +13 -13
- package/src/index.ts +24 -12
- package/src/internal/app.impl.ts +25 -28
- package/src/internal/appBuilder.impl.ts +16 -16
- package/src/internal/createApp.impl.ts +3 -3
- package/src/services/commandService.ts +3 -3
- package/src/services/credentialService.ts +3 -3
- package/src/services/middlewareService.ts +4 -4
- package/src/services/organizationService.ts +18 -116
- package/src/services/requestBuilder.ts +40 -15
- package/src/services/responseUtils.ts +32 -0
- package/src/services/rpcService.ts +28 -11
- package/src/services/service.ts +10 -8
- package/src/services/userProfileService.ts +18 -66
- package/src/storages/chat.ts +21 -0
- package/src/storages/chats.ts +17 -0
- package/src/storages/file.impl.ts +69 -0
- package/src/storages/file.ts +28 -0
- package/src/storages/files.impl.ts +213 -0
- package/src/storages/files.ts +38 -0
- package/src/storages/filesPage.ts +27 -0
- package/src/storages/groups.impl.ts +337 -0
- package/src/storages/groups.ts +43 -0
- package/src/storages/organization.impl.ts +68 -0
- package/src/storages/organization.ts +33 -0
- package/src/storages/organizations.impl.ts +191 -0
- package/src/storages/organizations.ts +8 -28
- package/src/storages/userProfile.impl.ts +56 -0
- package/src/storages/userProfile.ts +2 -2
- package/src/storages/workspace.impl.ts +109 -0
- package/src/storages/workspace.ts +49 -0
- package/src/storages/workspaces.impl.ts +212 -0
- package/src/storages/workspaces.ts +53 -0
- package/test/commands.test.ts +8 -8
- package/test/data/test_file.pdf +0 -0
- package/test/disposable.test.ts +3 -3
- package/test/events.test.ts +4 -4
- package/test/files.test.ts +52 -0
- package/test/index.test.ts +42 -83
- package/test/organization.test.ts +57 -0
- package/test/registry.test.ts +8 -8
- package/test/services.test.ts +15 -15
- package/test/setup.ts +52 -0
- package/test/unitTest.test.ts +2 -2
- package/test/workspace.test.ts +71 -0
- package/src/services/organizationImpl.ts +0 -51
- package/src/services/organizationsImpl.ts +0 -55
- package/src/types.ts +0 -86
package/test/index.test.ts
CHANGED
@@ -1,96 +1,52 @@
|
|
1
|
-
import { version } from
|
1
|
+
import { version } from "../package.json"
|
2
2
|
import {
|
3
3
|
AppSdk,
|
4
4
|
BasicCredential,
|
5
5
|
appSdk,
|
6
6
|
SDK_VERSION,
|
7
7
|
DEFAULT_NAME,
|
8
|
-
|
9
|
-
} from
|
10
|
-
import { MiddlewareService } from
|
11
|
-
import { CredentialService } from
|
12
|
-
import { RpcService } from
|
13
|
-
import { AppBuilder } from
|
14
|
-
import { UnitTest, AppSdkUnitTest } from
|
15
|
-
import { HOST, TOKEN } from
|
16
|
-
|
17
|
-
|
18
|
-
test('SDK_VERSION', () => {
|
8
|
+
DebugCredential
|
9
|
+
} from "../src"
|
10
|
+
import { MiddlewareService } from "../src/services/middlewareService"
|
11
|
+
import { CredentialService } from "../src/services/credentialService"
|
12
|
+
import { RpcService } from "../src/services/rpcService"
|
13
|
+
import { AppBuilder } from "../src/appBuilder"
|
14
|
+
import { UnitTest, AppSdkUnitTest } from "../src/unitTest"
|
15
|
+
import { HOST, randomHash, TOKEN } from "./setup"
|
16
|
+
|
17
|
+
test("SDK_VERSION", () => {
|
19
18
|
expect(SDK_VERSION).toBe(version)
|
20
19
|
})
|
21
20
|
|
22
|
-
test(
|
21
|
+
test("Default SDK", async () => {
|
23
22
|
// default
|
24
23
|
const app = await appSdk(DEFAULT_NAME, async (builder: AppBuilder) => {
|
25
24
|
builder.useHost(HOST)
|
26
|
-
builder.useCredential(new
|
25
|
+
builder.useCredential(new DebugCredential(TOKEN))
|
27
26
|
})
|
28
27
|
expect(app).not.toBeUndefined()
|
29
28
|
})
|
30
29
|
|
31
|
-
test(
|
32
|
-
const randomName = `org-test-${Math.random().toString(16)}`
|
33
|
-
const app = await appSdk(randomName, async builder => {
|
34
|
-
builder.useHost(HOST)
|
35
|
-
builder.useCredential(new BearerCredential(TOKEN))
|
36
|
-
})
|
37
|
-
|
38
|
-
const initLength = app.organizations.collection.length
|
39
|
-
|
40
|
-
const org = await app.organizations.create(
|
41
|
-
randomName,
|
42
|
-
'this is a unitTest description'
|
43
|
-
)
|
44
|
-
|
45
|
-
// check organization
|
46
|
-
expect(org).not.toBeUndefined()
|
47
|
-
expect(org).not.toBeNull()
|
48
|
-
expect(org).toBeInstanceOf(OrganizationImpl)
|
49
|
-
|
50
|
-
expect(org.id).not.toBeUndefined()
|
51
|
-
expect(org.id).not.toBeNull()
|
52
|
-
expect(org.id.trim()).not.toBe('')
|
53
|
-
|
54
|
-
// check name
|
55
|
-
expect(org.name).not.toBeUndefined()
|
56
|
-
expect(org.name).not.toBeNull()
|
57
|
-
expect(org.name.trim()).not.toBe('')
|
58
|
-
|
59
|
-
// check description
|
60
|
-
expect(org.description).not.toBeUndefined()
|
61
|
-
expect(org.description).not.toBeNull()
|
62
|
-
expect(org.description.trim()).not.toBe('')
|
63
|
-
|
64
|
-
// check organizations
|
65
|
-
expect(app.organizations.get(org.id)).toBe(org)
|
66
|
-
expect(app.organizations.collection.length).toBe(initLength + 1)
|
67
|
-
|
68
|
-
await expect(app.organizations.delete(org.id)).resolves.not.toThrow()
|
69
|
-
expect((<OrganizationImpl>org).isDisposed).toBe(true)
|
70
|
-
expect(app.organizations.collection.length).toBe(initLength)
|
71
|
-
expect(app.organizations.tryGet(org.id)).toBeUndefined()
|
72
|
-
})
|
73
|
-
|
74
|
-
test('SDK, middleware', async () => {
|
30
|
+
test("SDK, middleware", async () => {
|
75
31
|
await AppSdkUnitTest.test(UnitTest.DEFAULT, async () => {
|
76
|
-
const app = await appSdk(
|
77
|
-
builder.useHost(
|
32
|
+
const app = await appSdk("test-settings", async (builder: AppBuilder) => {
|
33
|
+
builder.useHost("https://test.com")
|
78
34
|
builder.useAutomaticDataCollectionEnabled(false)
|
79
|
-
builder.useCredential(new BasicCredential(
|
35
|
+
builder.useCredential(new BasicCredential("email", "password"))
|
80
36
|
builder.registerMiddleware(async (req, next) => {
|
81
|
-
req.headers.set(
|
37
|
+
req.headers.set("X-Test", "test")
|
82
38
|
return await next(req)
|
83
39
|
})
|
84
40
|
})
|
85
|
-
expect(app.name).toBe(
|
86
|
-
expect(app.host).toBe(
|
41
|
+
expect(app.name).toBe("test-settings")
|
42
|
+
expect(app.host).toBe("https://test.com")
|
87
43
|
expect(app.automaticDataCollectionEnabled).toBe(false)
|
88
44
|
})
|
89
45
|
})
|
90
46
|
|
91
|
-
test(
|
47
|
+
test("SDK, services", async () => {
|
92
48
|
await AppSdkUnitTest.test(UnitTest.DEFAULT, async () => {
|
93
|
-
const app = await appSdk(
|
49
|
+
const app = await appSdk("test-sdk")
|
94
50
|
const middlewareService = app.resolve(MiddlewareService)
|
95
51
|
expect(middlewareService).not.toBeUndefined()
|
96
52
|
expect(app.resolve(MiddlewareService)).toBe(middlewareService)
|
@@ -100,35 +56,35 @@ test('SDK, services', async () => {
|
|
100
56
|
})
|
101
57
|
})
|
102
58
|
|
103
|
-
test(
|
59
|
+
test("SDK, middleware", async () => {
|
104
60
|
await AppSdkUnitTest.test(UnitTest.DEFAULT, async () => {
|
105
|
-
const app = await appSdk(
|
61
|
+
const app = await appSdk("test-middleware")
|
106
62
|
const middlewareService = app.resolve(MiddlewareService)
|
107
63
|
expect(middlewareService).not.toBeUndefined()
|
108
64
|
expect(app.resolve(MiddlewareService)).toBe(middlewareService)
|
109
65
|
expect(app.resolve(CredentialService)).not.toBeUndefined()
|
110
66
|
|
111
67
|
const response = await middlewareService?.process(
|
112
|
-
new Request(
|
68
|
+
new Request("http://localhost:8080"),
|
113
69
|
async (req: Request): Promise<Response> => {
|
114
|
-
const headerXTest = req.headers.get(
|
70
|
+
const headerXTest = req.headers.get("Custom-Test-Header")
|
115
71
|
expect(headerXTest).toBeNull()
|
116
|
-
return new Response(
|
72
|
+
return new Response("", { status: 200 })
|
117
73
|
}
|
118
74
|
)
|
119
75
|
expect(response).not.toBeUndefined()
|
120
76
|
expect(response?.status).toBe(200)
|
121
77
|
|
122
78
|
middlewareService?.useMiddleware(async (req, next) => {
|
123
|
-
req.headers.set(
|
79
|
+
req.headers.set("X-Test", "test-value")
|
124
80
|
return await next(req)
|
125
81
|
})
|
126
82
|
|
127
83
|
const response2 = await middlewareService?.process(
|
128
|
-
new Request(
|
84
|
+
new Request("https://localhost:8080"),
|
129
85
|
async (req: Request): Promise<Response> => {
|
130
|
-
expect(req.headers.get(
|
131
|
-
return new Response(
|
86
|
+
expect(req.headers.get("X-Test")).toBe("test-value")
|
87
|
+
return new Response("", { status: 400 })
|
132
88
|
}
|
133
89
|
)
|
134
90
|
expect(response2).not.toBeUndefined()
|
@@ -136,28 +92,31 @@ test('SDK, middleware', async () => {
|
|
136
92
|
})
|
137
93
|
})
|
138
94
|
|
139
|
-
test(
|
95
|
+
test("SDK, it is impossible to setup the same application", async () => {
|
140
96
|
await AppSdkUnitTest.test(UnitTest.DEFAULT, async () => {
|
141
97
|
// this test is not stable if you run all tests at once
|
142
98
|
// because the app is cached all app instances
|
143
99
|
// we use a random identifier every time
|
144
|
-
const testId =
|
145
|
-
const promise = appSdk(
|
100
|
+
const testId = `test-setup-${randomHash()}`
|
101
|
+
const promise = appSdk(testId).then(() => {
|
102
|
+
})
|
146
103
|
await expect(
|
147
|
-
appSdk(
|
104
|
+
appSdk(testId, async () => {
|
105
|
+
})
|
148
106
|
).rejects.toThrow()
|
149
107
|
await promise
|
150
108
|
})
|
151
109
|
})
|
152
110
|
|
153
|
-
test(
|
111
|
+
test("SDK, setup and get this app", async () => {
|
154
112
|
await AppSdkUnitTest.test(UnitTest.DEFAULT, async () => {
|
155
113
|
// this test is not stable if you run all tests at once
|
156
114
|
// because the app is cached all app instances
|
157
115
|
// we use a random identifier every time
|
158
|
-
const testId =
|
159
|
-
const promise = appSdk(
|
160
|
-
|
116
|
+
const testId = `test-get-${randomHash()}`
|
117
|
+
const promise = appSdk(testId).then(() => {
|
118
|
+
})
|
119
|
+
await expect(appSdk(testId)).resolves.toBeInstanceOf(AppSdk)
|
161
120
|
await promise
|
162
121
|
})
|
163
122
|
})
|
@@ -0,0 +1,57 @@
|
|
1
|
+
import { appSdk, 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 appSdk(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/registry.test.ts
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
import { Registry } from
|
1
|
+
import { Registry } from "../src/internal/registry"
|
2
2
|
|
3
3
|
class TestClass {
|
4
4
|
constructor(public readonly value: string) {}
|
5
5
|
}
|
6
6
|
|
7
|
-
test(
|
7
|
+
test("Registry, test factory", () => {
|
8
8
|
const registry = new Registry()
|
9
9
|
|
10
|
-
const item = new TestClass(
|
10
|
+
const item = new TestClass("test1")
|
11
11
|
registry.map(TestClass).asValue(item)
|
12
12
|
expect(registry.get(TestClass)).toBe(item)
|
13
13
|
|
@@ -22,22 +22,22 @@ test('Registry, test factory', () => {
|
|
22
22
|
expect(registry.get(TestClass)).not.toBe(item)
|
23
23
|
expect(registry.get(TestClass)).not.toBe(registry.get(TestClass))
|
24
24
|
|
25
|
-
expect(registry.get(TestClass)?.value).toBe(
|
25
|
+
expect(registry.get(TestClass)?.value).toBe("test_5")
|
26
26
|
})
|
27
27
|
|
28
|
-
test(
|
28
|
+
test("Registry, test value", () => {
|
29
29
|
const registry = new Registry()
|
30
30
|
|
31
|
-
const item = new TestClass(
|
31
|
+
const item = new TestClass("test1")
|
32
32
|
registry.map(TestClass).asValue(item)
|
33
33
|
expect(registry.get(TestClass)).toBeInstanceOf(TestClass)
|
34
34
|
expect(registry.get(TestClass)).toBe(item)
|
35
35
|
})
|
36
36
|
|
37
|
-
test(
|
37
|
+
test("Registry, test singleton", () => {
|
38
38
|
const registry = new Registry()
|
39
39
|
|
40
|
-
registry.map(TestClass).asSingleton(() => new TestClass(
|
40
|
+
registry.map(TestClass).asSingleton(() => new TestClass("test1"))
|
41
41
|
const singleton = registry.get(TestClass)
|
42
42
|
expect(singleton).toBeInstanceOf(TestClass)
|
43
43
|
expect(singleton).toBe(registry.get(TestClass))
|
package/test/services.test.ts
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
import { appSdk, BasicCredential, DefaultCredential } from
|
2
|
-
import { CredentialService } from
|
3
|
-
import { MiddlewareService } from
|
4
|
-
import { UnitTest, AppSdkUnitTest } from
|
1
|
+
import { appSdk, BasicCredential, DefaultCredential } from "../src"
|
2
|
+
import { CredentialService } from "../src/services/credentialService"
|
3
|
+
import { MiddlewareService } from "../src/services/middlewareService"
|
4
|
+
import { UnitTest, AppSdkUnitTest } from "../src/unitTest"
|
5
5
|
|
6
|
-
test(
|
6
|
+
test("CredentialService", async () => {
|
7
7
|
await AppSdkUnitTest.test(UnitTest.DEFAULT, async () => {
|
8
|
-
const app = await appSdk(
|
8
|
+
const app = await appSdk("test-services", async builder => {
|
9
9
|
builder.env.unitTest = UnitTest.DO_NOT_START
|
10
10
|
})
|
11
11
|
const credentialService = app.resolve(CredentialService)
|
@@ -14,7 +14,7 @@ test('CredentialService', async () => {
|
|
14
14
|
expect(app.resolve(CredentialService)).toBeInstanceOf(CredentialService)
|
15
15
|
expect(app.credential).not.toBeUndefined()
|
16
16
|
|
17
|
-
const credential = new BasicCredential(
|
17
|
+
const credential = new BasicCredential("email", "password")
|
18
18
|
app.credential = credential
|
19
19
|
expect(app.credential).toBe(credential)
|
20
20
|
expect(credentialService?.credential).toBe(credential)
|
@@ -22,15 +22,15 @@ test('CredentialService', async () => {
|
|
22
22
|
const middleware = app.resolve(MiddlewareService) as MiddlewareService
|
23
23
|
const emailPasswordDisposable = middleware.useMiddleware(
|
24
24
|
async (req, next) => {
|
25
|
-
expect(req.headers.get(
|
26
|
-
await next(req)
|
25
|
+
expect(req.headers.get("Authorization")).toBe("Basic email:password")
|
26
|
+
return await next(req)
|
27
27
|
}
|
28
28
|
)
|
29
29
|
expect(emailPasswordDisposable).not.toBeUndefined()
|
30
30
|
await middleware.process(
|
31
|
-
new Request(
|
31
|
+
new Request("https://localhost:8080"),
|
32
32
|
async () => {
|
33
|
-
return new Response(
|
33
|
+
return new Response("", { status: 200 })
|
34
34
|
}
|
35
35
|
)
|
36
36
|
emailPasswordDisposable?.dispose()
|
@@ -41,14 +41,14 @@ test('CredentialService', async () => {
|
|
41
41
|
expect(credentialService?.credential).toBe(credential2)
|
42
42
|
|
43
43
|
const defaultDisposable = middleware.useMiddleware(async (req, next) => {
|
44
|
-
expect(req.headers.get(
|
45
|
-
await next(req)
|
44
|
+
expect(req.headers.get("Authorization")).toBeNull()
|
45
|
+
return await next(req)
|
46
46
|
})
|
47
47
|
expect(defaultDisposable).not.toBeUndefined()
|
48
48
|
await middleware.process(
|
49
|
-
new Request(
|
49
|
+
new Request("https://localhost:8080"),
|
50
50
|
async () => {
|
51
|
-
return new Response(
|
51
|
+
return new Response("", { status: 200 })
|
52
52
|
}
|
53
53
|
)
|
54
54
|
defaultDisposable?.dispose()
|
package/test/setup.ts
CHANGED
@@ -1,2 +1,54 @@
|
|
1
|
+
import { appSdk, AppSdk, DebugCredential } from "../src"
|
2
|
+
import { Organization } from "../src/storages/organization"
|
3
|
+
import { Workspace } from "../src/storages/workspace"
|
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: AppSdk, 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 appSdk(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: AppSdk, 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,6 +1,6 @@
|
|
1
|
-
import { AppSdkUnitTest, UnitTest } from
|
1
|
+
import { AppSdkUnitTest, UnitTest } from "../src/unitTest"
|
2
2
|
|
3
|
-
test(
|
3
|
+
test("SDK, unitTest", async () => {
|
4
4
|
expect(AppSdkUnitTest.current).toBe(UnitTest.DO_NOTHING)
|
5
5
|
expect(
|
6
6
|
await AppSdkUnitTest.test(UnitTest.DO_NOT_PRINT_INITIALIZED_LOG, () => {
|
@@ -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
|
+
})
|
@@ -1,51 +0,0 @@
|
|
1
|
-
import { Organization, OrganizationId } from '../storages/organizations'
|
2
|
-
import { Disposable } from '../disposable'
|
3
|
-
import { OrganizationDto } from '../dto/userInfoResponse'
|
4
|
-
import { OrganizationService } from './organizationService'
|
5
|
-
import { OrganizationsImpl } from './organizationsImpl'
|
6
|
-
|
7
|
-
export class OrganizationImpl extends Organization implements Disposable {
|
8
|
-
private _isDisposed: boolean = false
|
9
|
-
private _isAdmin: boolean = false
|
10
|
-
private _content?: OrganizationDto
|
11
|
-
|
12
|
-
constructor(
|
13
|
-
private readonly service: OrganizationService,
|
14
|
-
private readonly organizations: OrganizationsImpl
|
15
|
-
) {
|
16
|
-
super()
|
17
|
-
}
|
18
|
-
|
19
|
-
get isAdmin(): boolean {
|
20
|
-
return this._isAdmin
|
21
|
-
}
|
22
|
-
|
23
|
-
get isDisposed(): boolean {
|
24
|
-
return this._isDisposed
|
25
|
-
}
|
26
|
-
|
27
|
-
dispose(): void {
|
28
|
-
this._isDisposed = true
|
29
|
-
}
|
30
|
-
|
31
|
-
public initFrom(
|
32
|
-
content: OrganizationDto,
|
33
|
-
isAdmin: boolean
|
34
|
-
): OrganizationImpl {
|
35
|
-
this._content = content
|
36
|
-
this._isAdmin = isAdmin
|
37
|
-
return this
|
38
|
-
}
|
39
|
-
|
40
|
-
get id(): OrganizationId {
|
41
|
-
return <OrganizationId>this._content?.id
|
42
|
-
}
|
43
|
-
|
44
|
-
get name(): string {
|
45
|
-
return <OrganizationId>this._content?.profile.name
|
46
|
-
}
|
47
|
-
|
48
|
-
get description(): string {
|
49
|
-
return <OrganizationId>this._content?.profile.description
|
50
|
-
}
|
51
|
-
}
|
@@ -1,55 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
Organization,
|
3
|
-
OrganizationEvent,
|
4
|
-
OrganizationId,
|
5
|
-
Organizations
|
6
|
-
} from '../storages/organizations'
|
7
|
-
import { OrganizationImpl } from './organizationImpl'
|
8
|
-
import { OrganizationService } from './organizationService'
|
9
|
-
|
10
|
-
export class OrganizationsImpl extends Organizations {
|
11
|
-
constructor(public readonly service: OrganizationService) {
|
12
|
-
super()
|
13
|
-
}
|
14
|
-
|
15
|
-
public organizations: OrganizationImpl[] = []
|
16
|
-
public currentOrganizationId?: OrganizationId
|
17
|
-
|
18
|
-
get collection(): readonly Organization[] {
|
19
|
-
return this.organizations
|
20
|
-
}
|
21
|
-
|
22
|
-
get current(): OrganizationId {
|
23
|
-
return <OrganizationId>this.currentOrganizationId
|
24
|
-
}
|
25
|
-
|
26
|
-
set current(value: OrganizationId) {
|
27
|
-
if (this.currentOrganizationId !== value) {
|
28
|
-
this.currentOrganizationId = value
|
29
|
-
this.dispatch({
|
30
|
-
type: OrganizationEvent.CURRENT_CHANGED,
|
31
|
-
data: this
|
32
|
-
})
|
33
|
-
}
|
34
|
-
}
|
35
|
-
|
36
|
-
get(id: OrganizationId): Organization {
|
37
|
-
return <Organization>this.tryGet(id)
|
38
|
-
}
|
39
|
-
|
40
|
-
tryGet(id: OrganizationId): Organization | undefined {
|
41
|
-
return this.organizations.find(organization => organization.id === id)
|
42
|
-
}
|
43
|
-
|
44
|
-
contains(id: OrganizationId): boolean {
|
45
|
-
return this.organizations.some(organization => organization.id === id)
|
46
|
-
}
|
47
|
-
|
48
|
-
async create(name: string, description: string): Promise<Organization> {
|
49
|
-
return this.service.createOrganization(name, description)
|
50
|
-
}
|
51
|
-
|
52
|
-
delete(id: string): Promise<void> {
|
53
|
-
return this.service.deleteOrganization(id)
|
54
|
-
}
|
55
|
-
}
|