Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BC-5736 - Redis for tldraw #4542

Merged
merged 453 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
453 commits
Select commit Hold shift + click to select a range
f11d39f
Improve tests after merge.
blazejpass Oct 18, 2023
6cb919e
Prevent from creating tldraw deploy and service
blazejpass Oct 19, 2023
9be6bf4
Delete tldraw-deployment.yml.j2
blazejpass Oct 20, 2023
b2fd397
Use tldraw-test-module, improve code
blazejpass Oct 20, 2023
7eecf87
Fix tests according to suggested comments.
blazejpass Oct 23, 2023
a9037cf
Change deployment yml to main
blazejpass Oct 25, 2023
336de77
Fix code according to comments
blazejpass Oct 25, 2023
7475bf5
Fix tests code according to comments. Move test helper
blazejpass Oct 25, 2023
55ada6e
Merge remote-tracking branch 'origin/BC-4256-Integration-tldraw' into…
blazejpass Oct 30, 2023
08ca974
Adjust code after merge changes from bc-4256
blazejpass Nov 3, 2023
89c7816
Roll back for tldraw deployment and service declaration
blazejpass Nov 6, 2023
31b4f20
Merge branch 'main' into BC-4710-new-tldraw-manage
blazejpass Nov 6, 2023
bcd3cbe
Adjust code after merge
blazejpass Nov 6, 2023
dc970fc
Add svc ang ingress rules for tldraw
blazejpass Nov 6, 2023
491bcce
Change naming of uml files
blazejpass Nov 8, 2023
4bc510f
Merge branch 'main' into BC-4710-new-tldraw-manage
blazejpass Nov 8, 2023
6b16280
Fix import for module infra
blazejpass Nov 8, 2023
fcfb492
Fix lint suggestions. Fix module shared import.
blazejpass Nov 8, 2023
8a73d1e
Lint fixes
blazejpass Nov 8, 2023
bddb1e4
Lint fixes
blazejpass Nov 8, 2023
334b811
delete element auth fix
blazejpass Nov 9, 2023
ecd2e16
Add mock method destroy to createEsSharedDocDo
blazejpass Nov 9, 2023
62a8676
Att test for recursive copy of drawing element
blazejpass Nov 9, 2023
749e606
Merge branch 'main' into BC-4710-new-tldraw-manage
wiaderwek Nov 9, 2023
f98dcf6
Add ingress declaration
blazejpass Nov 9, 2023
b12eda6
Merge remote-tracking branch 'origin/BC-4710-new-tldraw-manage' into …
blazejpass Nov 9, 2023
785714d
Merge branch 'main' into BC-4710-new-tldraw-manage
wiaderwek Nov 9, 2023
962bbc2
add redis for tldraw
Nov 9, 2023
3778e89
fix imports
Nov 9, 2023
b84f001
temporary change clean.yml
blazejpass Nov 10, 2023
981b677
Merge remote-tracking branch 'origin/BC-4710-new-tldraw-manage' into …
blazejpass Nov 10, 2023
23bc570
change workflows for tests
Nov 10, 2023
044ee76
Merge branch 'BC-4710-new-tldraw-manage' into BC-5736-redis-for-tldraw
Nov 10, 2023
e234a64
add redis module
Nov 10, 2023
13cb011
add ioredis module
Nov 10, 2023
70b82d2
fix tests
Nov 12, 2023
a97b0a1
setup redis
Nov 12, 2023
2c590b4
install ioredis
Nov 13, 2023
079ca95
change ioredis version to 4.28.5
Nov 13, 2023
a5c55c1
remove usage redis module
Nov 13, 2023
0f29122
fix redis error
Nov 13, 2023
01127a3
add log
Nov 13, 2023
3621bc1
add debug logs
davwas Nov 14, 2023
cd115b0
add console logs
davwas Nov 14, 2023
fb75138
change log method
davwas Nov 14, 2023
778ac27
remove duplicate logs
davwas Nov 14, 2023
cdd36de
add console logs again
davwas Nov 14, 2023
b78de7b
add more console logs
davwas Nov 14, 2023
e454d80
add more console logs 2
davwas Nov 14, 2023
8e3c893
add more console logs 3
davwas Nov 14, 2023
63b9623
add more console logs 4
davwas Nov 14, 2023
ccb48d0
fix wscheck
Nov 14, 2023
0f756b2
fix extracting channelId
Nov 14, 2023
ad2255f
fix extracting channelId
Nov 14, 2023
392e9a6
rewrite mongodbprovider to our code
Nov 23, 2023
3e0ca98
fix module configuration
Nov 23, 2023
ca6348d
fix module configuration
Nov 23, 2023
36c3a25
add mikro orm to tldraw ws module
Nov 23, 2023
f87bd99
clean up tldraw app code
davwas Nov 23, 2023
1f2b628
update packages
davwas Nov 23, 2023
f3ec115
add tldraw again to npm scripts
davwas Nov 23, 2023
6e1499c
add tldraw db and index creation
davwas Nov 24, 2023
a81e432
Merge branch 'main' into BC-5736-redis-for-tldraw
davwas Nov 24, 2023
d041766
update tldraw collection names
davwas Nov 24, 2023
b797efa
Merge branch 'main' into BC-5736-redis-for-tldraw
davwas Nov 24, 2023
5976c90
fix saving into db
davwas Nov 24, 2023
9e1e044
remove unused code
Nov 24, 2023
b2c5c64
Merge branch 'main' into BC-5736-redis-for-tldraw
wiaderwek Nov 24, 2023
20f370d
code refactor
Nov 25, 2023
a67ace0
code refactor v2
Nov 26, 2023
5c7b4cb
fix module and transaction error & clean up tldraw app code
davwas Nov 27, 2023
d82a5b4
Merge branch 'main' into BC-5736-redis-for-tldraw
davwas Nov 27, 2023
561c5a3
Merge branch 'main' into BC-5736-redis-for-tldraw
davwas Nov 29, 2023
e6f426b
fix problems after merge
davwas Nov 29, 2023
f908ca3
delete unused files and sync files
davwas Nov 29, 2023
12f654f
Merge branch 'main' into BC-5736-redis-for-tldraw
davwas Nov 29, 2023
2289de2
fix broken tests
davwas Nov 29, 2023
217d1b3
Merge branch 'main' into BC-5736-redis-for-tldraw
davwas Nov 29, 2023
3dca940
set default redis url if key not found
davwas Nov 29, 2023
eb4442f
fix code smells
davwas Nov 29, 2023
1ff203e
add coverage tests
davwas Nov 29, 2023
7034c55
refactor ws shared doc and add tests
davwas Nov 30, 2023
7fc4561
add more coverage tests
davwas Nov 30, 2023
346b9cd
fix spy method
davwas Nov 30, 2023
155ade0
add coverage tests
davwas Nov 30, 2023
34023fe
add missing method test
davwas Nov 30, 2023
edff1ab
Merge branch 'main' into BC-5736-redis-for-tldraw
davwas Dec 1, 2023
403a4f5
Merge branch 'main' into BC-5736-redis-for-tldraw
davwas Dec 4, 2023
8a52067
fix redisHandler error
davwas Dec 4, 2023
522bffe
Merge branch 'main' into BC-5736-redis-for-tldraw
davwas Dec 5, 2023
419a65f
Merge branch 'main' into BC-5736-redis-for-tldraw
davwas Dec 6, 2023
ea25057
fix conflicts
davwas Dec 6, 2023
e8bbedc
Merge branch 'main' into BC-5736-redis-for-tldraw
davwas Dec 8, 2023
23b6550
Update tldraw.repo.spec.ts
WojciechGrancow Dec 13, 2023
241f6c7
Merge branch 'main' into BC-5736-redis-for-tldraw
davwas Dec 14, 2023
f50b253
move env var to test config
davwas Dec 14, 2023
dedd070
Revert "move env var to test config"
davwas Dec 14, 2023
b7e0740
swap legacylogger with logger
davwas Dec 14, 2023
698ea6b
fix imports
davwas Dec 14, 2023
2684a5d
remove eslint comment
davwas Dec 14, 2023
768eb17
remove tldraw db name from config
davwas Dec 14, 2023
f85ce21
move tldraw entity factory to testing, use it in entity tests
davwas Dec 14, 2023
af0e07e
change mockImplementation for mockResolved or mockRejected for promises
davwas Dec 15, 2023
36548f1
Merge branch 'main' into BC-5736-redis-for-tldraw
davwas Dec 15, 2023
29e873c
remove unused type
davwas Dec 15, 2023
5b7f726
refactor ws-shared-doc-do and ws-service, refactor and add tests, add…
davwas Dec 15, 2023
2ab745a
refactor tldraw entity, factory and creation of indexes
davwas Dec 15, 2023
0077b02
Merge branch 'main' into BC-5736-redis-for-tldraw
davwas Dec 15, 2023
b79857a
add missing tests
davwas Dec 15, 2023
052fb37
add missing tests 2
davwas Dec 15, 2023
0e7df0a
Merge branch 'main' into BC-5736-redis-for-tldraw
davwas Dec 15, 2023
42ebc54
fix mongo connection error
davwas Dec 15, 2023
53d8d15
Merge branch 'main' into BC-5736-redis-for-tldraw
davwas Dec 15, 2023
8d1d8af
fix mongo error in tests
davwas Dec 15, 2023
10f25a8
add more coverage tests
davwas Dec 18, 2023
1ef4262
Merge branch 'main' into BC-5736-redis-for-tldraw
davwas Dec 18, 2023
fedd7c7
Merge branch 'main' into BC-5736-redis-for-tldraw
davwas Dec 18, 2023
668aeaf
add missing tests
davwas Dec 18, 2023
f46359a
fix test condition
davwas Dec 18, 2023
344dc2b
fix wrong rabbit module import
davwas Dec 20, 2023
67e7f8b
Merge branch 'main' into BC-5736-redis-for-tldraw
davwas Dec 20, 2023
eb50a5a
add tldraw test config
davwas Dec 20, 2023
7c3f6a1
Merge branch 'main' into BC-5736-redis-for-tldraw
davwas Dec 20, 2023
0b403e3
fix import
davwas Dec 20, 2023
66d613c
Merge branch 'main' into BC-5736-redis-for-tldraw
davwas Dec 28, 2023
39d8c61
clean up tldraw env vars
davwas Dec 28, 2023
3ee17c6
Merge branch 'main' into BC-5736-redis-for-tldraw
davwas Jan 9, 2024
5f28d42
fix additional conflicts
davwas Jan 9, 2024
77544e0
fix missing dependency
davwas Jan 9, 2024
862f2ef
update websocket packages
davwas Jan 9, 2024
0b0e05d
Merge branch 'main' into BC-5736-redis-for-tldraw
davwas Jan 10, 2024
64d2b4d
fix package conflicts
davwas Jan 10, 2024
0d14e90
solve merge conflicts
davwas Jan 15, 2024
f5986e4
Merge branch 'main' into BC-5736-redis-for-tldraw
davwas Jan 15, 2024
060d31b
fix issues after merge
davwas Jan 15, 2024
05278f5
fix import problems
davwas Jan 15, 2024
8fb2451
fix missing imports in tests
davwas Jan 15, 2024
a7f2c36
Merge branch 'main' into BC-5736-redis-for-tldraw
davwas Jan 15, 2024
9f86f19
fix other test issues
davwas Jan 15, 2024
a9ab05c
remove empty file
davwas Jan 15, 2024
fc44205
Merge branch 'main' into BC-5736-redis-for-tldraw
davwas Jan 15, 2024
880e087
fix comments
Jan 15, 2024
1408854
resolve comments
Jan 15, 2024
043a329
fix tests
Jan 15, 2024
e7002ed
add tldraw redis factory
Jan 16, 2024
f061629
fix tests
Jan 16, 2024
472ff24
fix tests
Jan 16, 2024
b7085fe
fix tests
Jan 16, 2024
930fe13
Merge branch 'main' into BC-5736-redis-for-tldraw
wiaderwek Jan 16, 2024
a043541
fix tests
Jan 16, 2024
7db1030
fix tests
Jan 16, 2024
41e98be
fix tests
Jan 16, 2024
75251c6
rerun
Jan 16, 2024
e8417cd
fix tests
Jan 16, 2024
803ef68
fix tests
Jan 16, 2024
683d9c2
fix tests
Jan 17, 2024
4a35e54
fix tests
Jan 17, 2024
a3af533
fix tests
Jan 17, 2024
7f1754d
Merge branch 'main' into BC-5736-redis-for-tldraw
Jan 17, 2024
4c0243e
fix tests
Jan 17, 2024
1e5fbcd
Merge branch 'main' into BC-5736-redis-for-tldraw
Jan 17, 2024
dc039d2
extend delay
Jan 17, 2024
92bb2d2
refactor tests
Jan 17, 2024
a981898
refactor tests
Jan 17, 2024
8d844bd
extend delay
Jan 17, 2024
ee8b497
extend delay
Jan 17, 2024
086eae1
extend delay
Jan 17, 2024
e12d193
fix tests
Jan 17, 2024
4128a4a
fix tests
Jan 17, 2024
a559a04
fix tests
Jan 17, 2024
8ff96ec
fix tests
Jan 18, 2024
e951ada
fix tests
Jan 18, 2024
3e9a6a6
add test
Jan 18, 2024
f3d9edd
fix test
Jan 18, 2024
ff5adde
fix test
Jan 18, 2024
11f67bb
extend timeout
Jan 18, 2024
8d0071b
add test
davwas Jan 18, 2024
1fd16f0
remove duplicated test
davwas Jan 19, 2024
c6c696f
fix imports
davwas Jan 19, 2024
5dd32b9
change delay
davwas Jan 19, 2024
d0fb99e
change redis subscribe method
davwas Jan 19, 2024
a320dd7
fix broken test
davwas Jan 19, 2024
64c9dc4
Revert "change redis subscribe method"
davwas Jan 19, 2024
ef9f42f
change redis subscribe method
davwas Jan 19, 2024
3fff2f1
change names
davwas Jan 19, 2024
8ab87a5
add temporary log
davwas Jan 19, 2024
eaef660
change promises to async await
davwas Jan 19, 2024
81eccdf
add diagnostic comments
davwas Jan 19, 2024
b51330a
fix tests
davwas Jan 19, 2024
4fd5200
change publish signature
davwas Jan 19, 2024
f635f8e
fix tests, error casting
davwas Jan 19, 2024
e46dac3
fix test
davwas Jan 20, 2024
485e7ff
add log
davwas Jan 20, 2024
919f662
remove async redis calls
davwas Jan 20, 2024
f0bdd77
fix test
davwas Jan 20, 2024
03877b0
add diagnostic log
davwas Jan 20, 2024
6d0b8cc
fix tests and refactor
davwas Jan 20, 2024
8b6c3b4
add diagnostic comment
davwas Jan 20, 2024
88e5d63
yet another refactor
davwas Jan 20, 2024
7d2f04a
fixes
davwas Jan 20, 2024
f390dfc
remove console logs
davwas Jan 20, 2024
0ff9dc3
add access modifier
davwas Jan 21, 2024
c26084e
Merge branch 'main' into BC-5736-redis-for-tldraw
wiaderwek Jan 22, 2024
5528da8
resolve comments
Jan 22, 2024
1710bc7
resolve comments
Jan 22, 2024
f1c137c
fix tests
Jan 22, 2024
ca7b607
fix tests
Jan 22, 2024
43fc03e
fix lint
Jan 22, 2024
3f9dbf7
resolve comments
Jan 23, 2024
565a02c
Merge branch 'main' into BC-5736-redis-for-tldraw
Jan 23, 2024
e6781a9
fix dependencies
Jan 23, 2024
35e5d38
add new test
Jan 23, 2024
0a2a508
rerun
Jan 23, 2024
8418ee7
fix tests
Jan 23, 2024
10d0a58
add test
Jan 23, 2024
4ecde56
add test
Jan 23, 2024
c90337c
add loggable
Jan 23, 2024
a79fa43
add test
Jan 24, 2024
a25b30b
fix test
Jan 24, 2024
ee70791
extend timeout
Jan 24, 2024
21b0b0d
fix dependencies
Jan 24, 2024
ecf7bb7
fix dependencies
Jan 24, 2024
686f248
Merge branch 'main' into BC-5736-redis-for-tldraw
wiaderwek Jan 24, 2024
1f22f84
Merge branch 'main' into BC-5736-redis-for-tldraw
wiaderwek Jan 24, 2024
4856615
extends delays
Jan 24, 2024
d5f8026
fix tests
Jan 24, 2024
fe7f7b5
fix tests
Jan 24, 2024
dd3f1e3
Proposal for outsource key creating code
CeEv Jan 24, 2024
f3039f9
fix typo
CeEv Jan 24, 2024
0335c47
Fix code style
CeEv Jan 24, 2024
634c3a6
Add factory tests.
CeEv Jan 24, 2024
5edb111
restructure test code
CeEv Jan 24, 2024
8f93b92
Rename factory
CeEv Jan 24, 2024
047decf
renames
CeEv Jan 24, 2024
a6daad6
linter
CeEv Jan 24, 2024
5770b49
linter again
CeEv Jan 24, 2024
4ba46fd
linter
CeEv Jan 25, 2024
fb7c431
resolve comments
Jan 25, 2024
cd5499b
add tests
Jan 25, 2024
563a6fe
extend delay
Jan 25, 2024
a7fea9a
extend delay
Jan 25, 2024
1c22a21
fix tests
Jan 25, 2024
7c2a8ec
Merge branch 'main' into BC-5736-redis-for-tldraw
davwas Jan 25, 2024
c14a101
fix bug where board was not being loaded correctly
davwas Jan 25, 2024
4b750cb
fix test
davwas Jan 25, 2024
977610a
fix lint
davwas Jan 25, 2024
dad583b
fix tests
davwas Jan 25, 2024
daa869c
fix tests
davwas Jan 25, 2024
c8d7acb
Merge branch 'main' into BC-5736-redis-for-tldraw
davwas Jan 25, 2024
b58d12e
Merge branch 'main' into BC-5736-redis-for-tldraw
wiaderwek Jan 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ jobs:
- name: 'Dependency Review'
uses: actions/dependency-review-action@v3
with:
allow-licenses: AGPL-3.0-only, LGPL-3.0, MIT, Apache-2.0, BSD-2-Clause, BSD-3-Clause, ISC, X11, 0BSD, GPL-3.0 AND BSD-3-Clause-Clear, Unlicense
allow-dependencies-licenses: 'pkg:npm/parse-mongo-url'
Metauriel marked this conversation as resolved.
Show resolved Hide resolved
allow-licenses: AGPL-3.0-only, LGPL-3.0, MIT, Apache-2.0, BSD-2-Clause, BSD-3-Clause, ISC, X11, 0BSD, GPL-3.0, Unlicense
# temporarily ignore dependency error for upgrade mongodb 4.9 to 4.11, remove when mikroORM is upgraded to 5.9
allow-ghsas: 'GHSA-vxvm-qww3-2fh7'
12 changes: 5 additions & 7 deletions apps/server/src/modules/tldraw/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,27 @@ import { Configuration } from '@hpi-schul-cloud/commons';
export interface TldrawConfig {
NEST_LOG_LEVEL: string;
INCOMING_REQUEST_TIMEOUT: number;
TLDRAW_DB_COLLECTION_NAME: string;
TLDRAW_DB_FLUSH_SIZE: string;
TLDRAW_DB_MULTIPLE_COLLECTIONS: boolean;
CONNECTION_STRING: string;
FEATURE_TLDRAW_ENABLED: boolean;
TLDRAW_PING_TIMEOUT: number;
TLDRAW_GC_ENABLED: number;
REDIS_URI: string;
API_HOST: number;
TLDRAW_MAX_DOCUMENT_SIZE: number;
}

const tldrawConnectionString: string = Configuration.get('TLDRAW_DB_URL') as string;

const tldrawConfig = {
NEST_LOG_LEVEL: Configuration.get('NEST_LOG_LEVEL') as string,
INCOMING_REQUEST_TIMEOUT: Configuration.get('INCOMING_REQUEST_TIMEOUT_API') as number,
TLDRAW_DB_COLLECTION_NAME: Configuration.get('TLDRAW__DB_COLLECTION_NAME') as string,
TLDRAW_DB_FLUSH_SIZE: Configuration.get('TLDRAW__DB_FLUSH_SIZE') as number,
TLDRAW_DB_MULTIPLE_COLLECTIONS: Configuration.get('TLDRAW__DB_MULTIPLE_COLLECTIONS') as boolean,
FEATURE_TLDRAW_ENABLED: Configuration.get('FEATURE_TLDRAW_ENABLED') as boolean,
CONNECTION_STRING: tldrawConnectionString,
CONNECTION_STRING: Configuration.get('TLDRAW_DB_URL') as string,
TLDRAW_PING_TIMEOUT: Configuration.get('TLDRAW__PING_TIMEOUT') as number,
TLDRAW_GC_ENABLED: Configuration.get('TLDRAW__GC_ENABLED') as boolean,
REDIS_URI: Configuration.has('REDIS_URI') ? (Configuration.get('REDIS_URI') as string) : null,
API_HOST: Configuration.get('API_HOST') as string,
TLDRAW_MAX_DOCUMENT_SIZE: Configuration.get('TLDRAW__MAX_DOCUMENT_SIZE') as number,
};

export const SOCKET_PORT = Configuration.get('TLDRAW__SOCKET_PORT') as number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Logger } from '@src/core/logger';
import { TldrawService } from '../../service';
import { TldrawController } from '..';
import { TldrawRepo } from '../../repo';
import { tldrawEntityFactory } from '../../factory';
import { tldrawEntityFactory } from '../../testing';

const baseRouteName = '/tldraw-document';
describe('tldraw controller (api)', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@ import { Test } from '@nestjs/testing';
import WebSocket from 'ws';
import { TextEncoder } from 'util';
import { INestApplication } from '@nestjs/common';
import { MongoMemoryDatabaseModule } from '@infra/database';
import { createConfigModuleOptions } from '@src/config';
import { Logger } from '@src/core/logger';
import { of, throwError } from 'rxjs';
import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { ConfigModule } from '@nestjs/config';
import { HttpService } from '@nestjs/axios';
import { AxiosError, AxiosHeaders, AxiosResponse } from 'axios';
import { axiosResponseFactory } from '@shared/testing';
import { WsCloseCodeEnum, WsCloseMessageEnum } from '../../types';
import { TldrawWsTestModule } from '../../tldraw-ws-test.module';
import { TldrawRedisFactory } from '../../redis';
import { TldrawDrawing } from '../../entities';
import { TldrawWsService } from '../../service';
import { TestConnection } from '../../testing/test-connection';
import { TldrawWs } from '../tldraw.ws';
import { TldrawBoardRepo, TldrawRepo, YMongodb } from '../../repo';
import { TestConnection, tldrawTestConfig } from '../../testing';
import { MetricsService } from '../../metrics';
import { TldrawWs } from '..';
import { WsCloseCodeEnum, WsCloseMessageEnum } from '../../types';

describe('WebSocketController (WsAdapter)', () => {
let app: INestApplication;
Expand All @@ -29,14 +36,32 @@ describe('WebSocketController (WsAdapter)', () => {

beforeAll(async () => {
const testingModule = await Test.createTestingModule({
imports: [TldrawWsTestModule],
imports: [
CeEv marked this conversation as resolved.
Show resolved Hide resolved
MongoMemoryDatabaseModule.forRoot({ entities: [TldrawDrawing] }),
ConfigModule.forRoot(createConfigModuleOptions(tldrawTestConfig)),
],
providers: [
TldrawWs,
TldrawWsService,
TldrawBoardRepo,
YMongodb,
MetricsService,
TldrawRedisFactory,
{
provide: TldrawRepo,
useValue: createMock<TldrawRepo>(),
},
{
provide: Logger,
useValue: createMock<Logger>(),
},
{
provide: HttpService,
useValue: createMock<HttpService>(),
},
],
}).compile();

gateway = testingModule.get(TldrawWs);
wsService = testingModule.get(TldrawWsService);
httpService = testingModule.get(HttpService);
Expand All @@ -49,10 +74,6 @@ describe('WebSocketController (WsAdapter)', () => {
await app.close();
});

beforeEach(() => {
jest.useFakeTimers({ advanceTimers: true, doNotFake: ['setInterval', 'clearInterval', 'setTimeout'] });
});

afterEach(() => {
jest.clearAllMocks();
});
Expand All @@ -63,14 +84,14 @@ describe('WebSocketController (WsAdapter)', () => {
jest.spyOn(Uint8Array.prototype, 'reduce').mockReturnValueOnce(1);

ws = await TestConnection.setupWs(wsUrl, 'TEST');

const { buffer } = getMessage();

return { handleConnectionSpy, buffer };
};

it(`should handle connection`, async () => {
const { handleConnectionSpy, buffer } = await setup();

ws.send(buffer, () => {});

expect(handleConnectionSpy).toHaveBeenCalledTimes(1);
Expand Down Expand Up @@ -110,10 +131,10 @@ describe('WebSocketController (WsAdapter)', () => {

it(`should handle 2 connections at same doc and data transfer`, async () => {
const { handleConnectionSpy, ws2, buffer } = await setup();

ws.send(buffer);
ws2.send(buffer);

expect(handleConnectionSpy).toHaveBeenCalled();
expect(handleConnectionSpy).toHaveBeenCalledTimes(2);

handleConnectionSpy.mockRestore();
Expand All @@ -140,7 +161,7 @@ describe('WebSocketController (WsAdapter)', () => {

expect(wsCloseSpy).toHaveBeenCalledWith(
WsCloseCodeEnum.WS_CLIENT_UNAUTHORISED_CONNECTION_CODE,
WsCloseMessageEnum.WS_CLIENT_UNAUTHORISED_CONNECTION_MESSAGE
Buffer.from(WsCloseMessageEnum.WS_CLIENT_UNAUTHORISED_CONNECTION_MESSAGE)
);

httpGetCallSpy.mockRestore();
Expand All @@ -157,7 +178,7 @@ describe('WebSocketController (WsAdapter)', () => {

expect(wsCloseSpy).toHaveBeenCalledWith(
WsCloseCodeEnum.WS_CLIENT_UNAUTHORISED_CONNECTION_CODE,
WsCloseMessageEnum.WS_CLIENT_UNAUTHORISED_CONNECTION_MESSAGE
Buffer.from(WsCloseMessageEnum.WS_CLIENT_UNAUTHORISED_CONNECTION_MESSAGE)
);

httpGetCallSpy.mockRestore();
Expand All @@ -170,10 +191,12 @@ describe('WebSocketController (WsAdapter)', () => {
const setup = () => {
const setupConnectionSpy = jest.spyOn(wsService, 'setupWSConnection');
const wsCloseSpy = jest.spyOn(WebSocket.prototype, 'close');
const closeConnSpy = jest.spyOn(wsService, 'closeConn').mockRejectedValue(new Error('error'));

return {
setupConnectionSpy,
wsCloseSpy,
closeConnSpy,
};
};

Expand All @@ -186,7 +209,7 @@ describe('WebSocketController (WsAdapter)', () => {

expect(wsCloseSpy).toHaveBeenCalledWith(
WsCloseCodeEnum.WS_CLIENT_BAD_REQUEST_CODE,
WsCloseMessageEnum.WS_CLIENT_BAD_REQUEST_MESSAGE
Buffer.from(WsCloseMessageEnum.WS_CLIENT_BAD_REQUEST_MESSAGE)
);

wsCloseSpy.mockRestore();
Expand All @@ -211,7 +234,7 @@ describe('WebSocketController (WsAdapter)', () => {

expect(wsCloseSpy).toHaveBeenCalledWith(
WsCloseCodeEnum.WS_CLIENT_NOT_FOUND_CODE,
WsCloseMessageEnum.WS_CLIENT_NOT_FOUND_MESSAGE
Buffer.from(WsCloseMessageEnum.WS_CLIENT_NOT_FOUND_MESSAGE)
);

wsCloseSpy.mockRestore();
Expand All @@ -232,7 +255,7 @@ describe('WebSocketController (WsAdapter)', () => {

expect(wsCloseSpy).toHaveBeenCalledWith(
WsCloseCodeEnum.WS_CLIENT_UNAUTHORISED_CONNECTION_CODE,
WsCloseMessageEnum.WS_CLIENT_UNAUTHORISED_CONNECTION_MESSAGE
Buffer.from(WsCloseMessageEnum.WS_CLIENT_UNAUTHORISED_CONNECTION_MESSAGE)
);

wsCloseSpy.mockRestore();
Expand Down Expand Up @@ -281,7 +304,7 @@ describe('WebSocketController (WsAdapter)', () => {
expect(setupConnectionSpy).toHaveBeenCalledWith(expect.anything(), 'TEST');
expect(wsCloseSpy).toHaveBeenCalledWith(
WsCloseCodeEnum.WS_CLIENT_FAILED_CONNECTION_CODE,
WsCloseMessageEnum.WS_CLIENT_FAILED_CONNECTION_MESSAGE
Buffer.from(WsCloseMessageEnum.WS_CLIENT_FAILED_CONNECTION_MESSAGE)
);

wsCloseSpy.mockRestore();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { Controller, Delete, ForbiddenException, HttpCode, NotFoundException, Param } from '@nestjs/common';
import { ApiValidationError } from '@shared/common';
import { TldrawService } from '../service/tldraw.service';
import { TldrawService } from '../service';
CeEv marked this conversation as resolved.
Show resolved Hide resolved
import { TldrawDeleteParams } from './tldraw.params';

@ApiTags('Tldraw Document')
Expand Down
17 changes: 4 additions & 13 deletions apps/server/src/modules/tldraw/controller/tldraw.ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Logger } from '@src/core/logger';
import { AxiosError } from 'axios';
import { firstValueFrom } from 'rxjs';
import { HttpService } from '@nestjs/axios';
import { WebsocketCloseErrorLoggable } from '../loggable/websocket-close-error.loggable';
import { WebsocketCloseErrorLoggable } from '../loggable';
import { TldrawConfig, SOCKET_PORT } from '../config';
import { WsCloseCodeEnum, WsCloseMessageEnum } from '../types';
import { TldrawWsService } from '../service';
Expand Down Expand Up @@ -68,7 +68,7 @@ export class TldrawWs implements OnGatewayInit, OnGatewayConnection {
}

try {
this.tldrawWsService.setupWSConnection(client, docName);
await this.tldrawWsService.setupWSConnection(client, docName);
} catch (err) {
this.closeClientAndLogError(
client,
Expand All @@ -79,17 +79,8 @@ export class TldrawWs implements OnGatewayInit, OnGatewayConnection {
}
}

public afterInit(): void {
this.tldrawWsService.setPersistence({
bindState: async (docName, ydoc) => {
await this.tldrawWsService.updateDocument(docName, ydoc);
},
writeState: async (docName) => {
// This is called when all connections to the document are closed.
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
await this.tldrawWsService.flushDocument(docName);
},
});
public async afterInit(): Promise<void> {
await this.tldrawWsService.createDbIndex();
CeEv marked this conversation as resolved.
Show resolved Hide resolved
}

private getDocNameFromRequest(request: Request): string {
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/modules/tldraw/domain/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './ws-shared-doc.do';
Loading
Loading