@neuralinnovations/dataisland-sdk 0.0.1-dev2 → 0.0.1-dev3
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/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 +1 -1
- 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 +1 -1
- package/src/index.ts +10 -12
- package/src/internal/app.impl.ts +21 -21
- 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 +3 -3
- package/src/services/organizationService.ts +18 -116
- package/src/services/requestBuilder.ts +6 -6
- package/src/services/responseUtils.ts +32 -0
- package/src/services/rpcService.ts +5 -5
- package/src/services/service.ts +3 -3
- package/src/services/userProfileService.ts +18 -66
- package/src/storages/chat.ts +37 -0
- package/src/storages/file.impl.ts +68 -0
- package/src/storages/files.impl.ts +192 -0
- package/src/storages/files.ts +67 -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 +43 -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/disposable.test.ts +3 -3
- package/test/events.test.ts +4 -4
- package/test/index.test.ts +102 -40
- package/test/registry.test.ts +8 -8
- package/test/services.test.ts +15 -15
- package/test/unitTest.test.ts +2 -2
- package/test_file.pdf +0 -0
- package/src/services/organizationImpl.ts +0 -51
- package/src/services/organizationsImpl.ts +0 -55
- package/src/types.ts +0 -86
@@ -0,0 +1,53 @@
|
|
1
|
+
import { EventDispatcher } from "../events"
|
2
|
+
import { Workspace } from "./workspace"
|
3
|
+
|
4
|
+
export type WorkspaceId = string
|
5
|
+
|
6
|
+
/**
|
7
|
+
* Workspaces event.
|
8
|
+
*/
|
9
|
+
export enum WorkspacesEvent {
|
10
|
+
ADDED = "added",
|
11
|
+
REMOVED = "removed"
|
12
|
+
}
|
13
|
+
|
14
|
+
/**
|
15
|
+
* Organization's workspaces.
|
16
|
+
*/
|
17
|
+
export abstract class Workspaces extends EventDispatcher<
|
18
|
+
WorkspacesEvent,
|
19
|
+
Workspace
|
20
|
+
> {
|
21
|
+
/**
|
22
|
+
* Workspaces.
|
23
|
+
*/
|
24
|
+
abstract get collection(): ReadonlyArray<Workspace>
|
25
|
+
|
26
|
+
/**
|
27
|
+
* Get workspace by id.
|
28
|
+
* @param id
|
29
|
+
*/
|
30
|
+
abstract get(id: WorkspaceId): Workspace
|
31
|
+
|
32
|
+
/**
|
33
|
+
* Try to get workspace by id.
|
34
|
+
* @param id
|
35
|
+
*/
|
36
|
+
abstract tryGet(id: WorkspaceId): Workspace | undefined
|
37
|
+
|
38
|
+
/**
|
39
|
+
* Check if workspace exists.
|
40
|
+
* @param id
|
41
|
+
*/
|
42
|
+
abstract contains(id: WorkspaceId): boolean
|
43
|
+
|
44
|
+
/**
|
45
|
+
* Create workspace.
|
46
|
+
*/
|
47
|
+
abstract create(name: string, description: string): Promise<Workspace>
|
48
|
+
|
49
|
+
/**
|
50
|
+
* Delete workspace.
|
51
|
+
*/
|
52
|
+
abstract delete(id: WorkspaceId): Promise<void>
|
53
|
+
}
|
package/test/commands.test.ts
CHANGED
@@ -1,24 +1,24 @@
|
|
1
|
-
import { Command, CommandHandler } from
|
2
|
-
import { appSdk } from
|
3
|
-
import { UnitTest, AppSdkUnitTest } from
|
1
|
+
import { Command, CommandHandler } from "../src/services/commandService"
|
2
|
+
import { appSdk } from "../src"
|
3
|
+
import { UnitTest, AppSdkUnitTest } from "../src/unitTest"
|
4
4
|
|
5
5
|
class Cmd extends Command {
|
6
|
-
constructor(public readonly name: string =
|
6
|
+
constructor(public readonly name: string = "test") {
|
7
7
|
super()
|
8
8
|
}
|
9
9
|
}
|
10
10
|
|
11
11
|
class CmdHandler extends CommandHandler<Cmd> {
|
12
12
|
async execute(message: Cmd): Promise<void> {
|
13
|
-
expect(message.name).toBe(
|
13
|
+
expect(message.name).toBe("test-command")
|
14
14
|
}
|
15
15
|
}
|
16
16
|
|
17
|
-
test(
|
17
|
+
test("Commands test", async () => {
|
18
18
|
await AppSdkUnitTest.test(UnitTest.DEFAULT, async () => {
|
19
|
-
const app = await appSdk(
|
19
|
+
const app = await appSdk("test-commands", async builder => {
|
20
20
|
builder.registerCommand(Cmd, context => new CmdHandler(context))
|
21
21
|
})
|
22
|
-
expect(app.context.execute(new Cmd(
|
22
|
+
expect(app.context.execute(new Cmd("test-command"))).toBeDefined()
|
23
23
|
})
|
24
24
|
})
|
package/test/disposable.test.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import { DisposableContainer } from
|
1
|
+
import { DisposableContainer } from "../src"
|
2
2
|
|
3
|
-
test(
|
3
|
+
test("DisposableContainer", () => {
|
4
4
|
const disposable = new DisposableContainer()
|
5
5
|
expect(disposable.isDisposed).toBe(false)
|
6
6
|
expect(disposable.lifetime.isDisposed).toBe(false)
|
@@ -9,7 +9,7 @@ test('DisposableContainer', () => {
|
|
9
9
|
expect(disposable.lifetime.isDisposed).toBe(true)
|
10
10
|
})
|
11
11
|
|
12
|
-
test(
|
12
|
+
test("DisposableContainer, dispose order", () => {
|
13
13
|
const indexes: number[] = []
|
14
14
|
const disposable = new DisposableContainer()
|
15
15
|
disposable.addCallback(() => {
|
package/test/events.test.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import { EventDispatcher } from
|
1
|
+
import { EventDispatcher } from "../src"
|
2
2
|
|
3
|
-
test(
|
3
|
+
test("Events, test general", () => {
|
4
4
|
enum ET {
|
5
5
|
A,
|
6
6
|
B
|
@@ -78,7 +78,7 @@ test('Events, test general', () => {
|
|
78
78
|
expect(b2).toBe(3)
|
79
79
|
})
|
80
80
|
|
81
|
-
test(
|
81
|
+
test("Events, test this", () => {
|
82
82
|
enum ET {
|
83
83
|
A,
|
84
84
|
B
|
@@ -128,7 +128,7 @@ test('Events, test this', () => {
|
|
128
128
|
expect(b.value).toBe(2)
|
129
129
|
})
|
130
130
|
|
131
|
-
test(
|
131
|
+
test("Events, test unsubscribe", () => {
|
132
132
|
const dispatch = new EventDispatcher<unknown, number>()
|
133
133
|
|
134
134
|
let index = 0
|
package/test/index.test.ts
CHANGED
@@ -1,45 +1,46 @@
|
|
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
|
-
import { OrganizationImpl } from
|
17
|
-
|
18
|
-
|
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, TOKEN } from "./setup"
|
16
|
+
import { OrganizationImpl } from "../src/storages/organization.impl"
|
17
|
+
import * as fs from "fs"
|
18
|
+
|
19
|
+
test("SDK_VERSION", () => {
|
19
20
|
expect(SDK_VERSION).toBe(version)
|
20
21
|
})
|
21
22
|
|
22
|
-
test(
|
23
|
+
test("Default SDK", async () => {
|
23
24
|
// default
|
24
25
|
const app = await appSdk(DEFAULT_NAME, async (builder: AppBuilder) => {
|
25
26
|
builder.useHost(HOST)
|
26
|
-
builder.useCredential(new
|
27
|
+
builder.useCredential(new DebugCredential(TOKEN))
|
27
28
|
})
|
28
29
|
expect(app).not.toBeUndefined()
|
29
30
|
})
|
30
31
|
|
31
|
-
test(
|
32
|
+
test("Create and delete organization, create and delete workspace", async () => {
|
32
33
|
const randomName = `org-test-${Math.random().toString(16)}`
|
33
34
|
const app = await appSdk(randomName, async builder => {
|
34
35
|
builder.useHost(HOST)
|
35
|
-
builder.useCredential(new
|
36
|
+
builder.useCredential(new DebugCredential(TOKEN))
|
36
37
|
})
|
37
38
|
|
38
39
|
const initLength = app.organizations.collection.length
|
39
40
|
|
40
41
|
const org = await app.organizations.create(
|
41
42
|
randomName,
|
42
|
-
|
43
|
+
"this is a unitTest description"
|
43
44
|
)
|
44
45
|
|
45
46
|
// check organization
|
@@ -49,48 +50,109 @@ test('Create and delete organization', async () => {
|
|
49
50
|
|
50
51
|
expect(org.id).not.toBeUndefined()
|
51
52
|
expect(org.id).not.toBeNull()
|
52
|
-
expect(org.id.trim()).not.toBe(
|
53
|
+
expect(org.id.trim()).not.toBe("")
|
53
54
|
|
54
55
|
// check name
|
55
56
|
expect(org.name).not.toBeUndefined()
|
56
57
|
expect(org.name).not.toBeNull()
|
57
|
-
expect(org.name.trim()).not.toBe(
|
58
|
+
expect(org.name.trim()).not.toBe("")
|
58
59
|
|
59
60
|
// check description
|
60
61
|
expect(org.description).not.toBeUndefined()
|
61
62
|
expect(org.description).not.toBeNull()
|
62
|
-
expect(org.description.trim()).not.toBe(
|
63
|
+
expect(org.description.trim()).not.toBe("")
|
63
64
|
|
64
65
|
// check organizations
|
65
66
|
expect(app.organizations.get(org.id)).toBe(org)
|
67
|
+
expect(app.organizations.tryGet(org.id)).toBe(org)
|
66
68
|
expect(app.organizations.collection.length).toBe(initLength + 1)
|
67
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
|
+
|
68
130
|
await expect(app.organizations.delete(org.id)).resolves.not.toThrow()
|
69
131
|
expect((<OrganizationImpl>org).isDisposed).toBe(true)
|
70
132
|
expect(app.organizations.collection.length).toBe(initLength)
|
71
133
|
expect(app.organizations.tryGet(org.id)).toBeUndefined()
|
72
134
|
})
|
73
135
|
|
74
|
-
test(
|
136
|
+
test("SDK, middleware", async () => {
|
75
137
|
await AppSdkUnitTest.test(UnitTest.DEFAULT, async () => {
|
76
|
-
const app = await appSdk(
|
77
|
-
builder.useHost(
|
138
|
+
const app = await appSdk("test-settings", async (builder: AppBuilder) => {
|
139
|
+
builder.useHost("https://test.com")
|
78
140
|
builder.useAutomaticDataCollectionEnabled(false)
|
79
|
-
builder.useCredential(new BasicCredential(
|
141
|
+
builder.useCredential(new BasicCredential("email", "password"))
|
80
142
|
builder.registerMiddleware(async (req, next) => {
|
81
|
-
req.headers.set(
|
143
|
+
req.headers.set("X-Test", "test")
|
82
144
|
return await next(req)
|
83
145
|
})
|
84
146
|
})
|
85
|
-
expect(app.name).toBe(
|
86
|
-
expect(app.host).toBe(
|
147
|
+
expect(app.name).toBe("test-settings")
|
148
|
+
expect(app.host).toBe("https://test.com")
|
87
149
|
expect(app.automaticDataCollectionEnabled).toBe(false)
|
88
150
|
})
|
89
151
|
})
|
90
152
|
|
91
|
-
test(
|
153
|
+
test("SDK, services", async () => {
|
92
154
|
await AppSdkUnitTest.test(UnitTest.DEFAULT, async () => {
|
93
|
-
const app = await appSdk(
|
155
|
+
const app = await appSdk("test-sdk")
|
94
156
|
const middlewareService = app.resolve(MiddlewareService)
|
95
157
|
expect(middlewareService).not.toBeUndefined()
|
96
158
|
expect(app.resolve(MiddlewareService)).toBe(middlewareService)
|
@@ -100,35 +162,35 @@ test('SDK, services', async () => {
|
|
100
162
|
})
|
101
163
|
})
|
102
164
|
|
103
|
-
test(
|
165
|
+
test("SDK, middleware", async () => {
|
104
166
|
await AppSdkUnitTest.test(UnitTest.DEFAULT, async () => {
|
105
|
-
const app = await appSdk(
|
167
|
+
const app = await appSdk("test-middleware")
|
106
168
|
const middlewareService = app.resolve(MiddlewareService)
|
107
169
|
expect(middlewareService).not.toBeUndefined()
|
108
170
|
expect(app.resolve(MiddlewareService)).toBe(middlewareService)
|
109
171
|
expect(app.resolve(CredentialService)).not.toBeUndefined()
|
110
172
|
|
111
173
|
const response = await middlewareService?.process(
|
112
|
-
new Request(
|
174
|
+
new Request("http://localhost:8080"),
|
113
175
|
async (req: Request): Promise<Response> => {
|
114
|
-
const headerXTest = req.headers.get(
|
176
|
+
const headerXTest = req.headers.get("Custom-Test-Header")
|
115
177
|
expect(headerXTest).toBeNull()
|
116
|
-
return new Response(
|
178
|
+
return new Response("", { status: 200 })
|
117
179
|
}
|
118
180
|
)
|
119
181
|
expect(response).not.toBeUndefined()
|
120
182
|
expect(response?.status).toBe(200)
|
121
183
|
|
122
184
|
middlewareService?.useMiddleware(async (req, next) => {
|
123
|
-
req.headers.set(
|
185
|
+
req.headers.set("X-Test", "test-value")
|
124
186
|
return await next(req)
|
125
187
|
})
|
126
188
|
|
127
189
|
const response2 = await middlewareService?.process(
|
128
|
-
new Request(
|
190
|
+
new Request("https://localhost:8080"),
|
129
191
|
async (req: Request): Promise<Response> => {
|
130
|
-
expect(req.headers.get(
|
131
|
-
return new Response(
|
192
|
+
expect(req.headers.get("X-Test")).toBe("test-value")
|
193
|
+
return new Response("", { status: 400 })
|
132
194
|
}
|
133
195
|
)
|
134
196
|
expect(response2).not.toBeUndefined()
|
@@ -136,7 +198,7 @@ test('SDK, middleware', async () => {
|
|
136
198
|
})
|
137
199
|
})
|
138
200
|
|
139
|
-
test(
|
201
|
+
test("SDK, it is impossible to setup the same application", async () => {
|
140
202
|
await AppSdkUnitTest.test(UnitTest.DEFAULT, async () => {
|
141
203
|
// this test is not stable if you run all tests at once
|
142
204
|
// because the app is cached all app instances
|
@@ -150,7 +212,7 @@ test('SDK, it is impossible to setup the same application', async () => {
|
|
150
212
|
})
|
151
213
|
})
|
152
214
|
|
153
|
-
test(
|
215
|
+
test("SDK, setup and get this app", async () => {
|
154
216
|
await AppSdkUnitTest.test(UnitTest.DEFAULT, async () => {
|
155
217
|
// this test is not stable if you run all tests at once
|
156
218
|
// because the app is cached all app instances
|
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/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, () => {
|
package/test_file.pdf
ADDED
Binary file
|
@@ -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
|
-
}
|