diff --git a/packages/framework/tests/integration/file.spec.ts b/packages/framework/tests/integration/file.spec.ts deleted file mode 100644 index 9669fe6a8..000000000 --- a/packages/framework/tests/integration/file.spec.ts +++ /dev/null @@ -1,148 +0,0 @@ -// import { expect, test, beforeAll } from '@jest/globals'; -// import { EntityStorage, FS } from '@deepkit/fs'; -// import { appModuleForControllers, closeAllCreatedServers, createServerClientPair } from './util.js'; -// import { sleep } from '@deepkit/core'; -// import { Buffer } from 'buffer'; -// import { arrayBufferTo } from '@deepkit/type'; -// import ws from 'ws'; -// import { rpc } from '@deepkit/rpc'; -// -// // @ts-ignore -// global['WebSocket'] = ws; -// -// afterAll(async () => { -// await closeAllCreatedServers(); -// }); -// -// test('test file list', async () => { -// @rpc.controller('test') -// class TestController { -// constructor( -// private storage: EntityStorage, -// private fs: FS, -// ) { -// -// } -// -// @rpc.action() -// async init() { -// await this.fs.removeAll({}); -// -// await this.fs.write('test1.txt', 'Was geht?'); -// await this.fs.write('test2.txt', 'Nix'); -// await this.fs.write('test2-doppelt.txt', 'Nix'); -// } -// -// @rpc.action() -// async deleteTest2() { -// await this.fs.removeAll({ -// path: 'test2.txt' -// }); -// } -// -// @rpc.action() -// async content(path: string) { -// return await this.fs.subscribe(path, {}); -// } -// -// @rpc.action() -// async write(path: string, content: string) { -// await this.fs.write(path, content); -// } -// -// @rpc.action() -// async files() { -// return this.storage.collection(File).filter({ -// path: { $regex: /^test2/ } -// }).find(); -// } -// } -// -// const { client, close } = await createServerClientPair('test file list', appModuleForControllers([TestController])); -// const test = client.controller('test'); -// await test.init(); -// -// const files = await test.files(); -// -// expect(files.count()).toBe(2); -// -// test.deleteTest2(); -// await files.nextStateChange; -// expect(files.count()).toBe(1); -// -// const fileContent = await test.content('test1.txt'); -// expect(fileContent).toBeInstanceOf(StreamBehaviorSubject); -// expect(arrayBufferTo(fileContent.value!, 'utf8')).toBe('Was geht?'); -// -// test.write('test1.txt', 'updated'); -// await fileContent.nextStateChange; -// expect(arrayBufferTo(fileContent.value!, 'utf8')).toBe('updated'); -// -// await close(); -// }); -// -// test('test file stream', async () => { -// @rpc.controller('test') -// class TestController { -// constructor( -// private storage: EntityStorage, -// private fs: FS, -// ) { -// -// } -// -// @rpc.action() -// async init() { -// await this.fs.removeAll({}); -// } -// -// @rpc.action() -// async stream(path: string, content: string) { -// await this.fs.stream(path, Buffer.from(content, 'utf8')); -// } -// -// @rpc.action() -// async content(path: string) { -// return await this.fs.subscribe(path, {}); -// } -// } -// -// const { client, close } = await createServerClientPair('test file stream', appModuleForControllers([TestController])); -// const test = client.controller('test'); -// await test.init(); -// -// await test.stream('stream.txt', 'init'); -// -// const fileContent = await test.content('stream.txt'); -// fileContent.activateNextOnAppend(); -// -// expect(fileContent).toBeInstanceOf(StreamBehaviorSubject); -// expect(Buffer.from(fileContent.value!).toString('utf8')).toBe('init'); -// -// test.stream('stream.txt', '\nupdated'); -// await fileContent.nextStateChange; -// expect(Buffer.from(fileContent.value!).toString('utf8')).toBe('init\nupdated'); -// -// await fileContent.unsubscribe(); -// await test.stream('stream.txt', '\nnext'); -// -// await sleep(0.2); -// //content is still the same, since we unsubscribed -// expect(Buffer.from(fileContent.value!).toString('utf8')).toBe('init\nupdated'); -// -// const binaryContent = await test.content('stream.txt'); -// expect(binaryContent.value).toBeInstanceOf(Uint8Array); -// expect(Buffer.from(binaryContent.value!).toString('utf8')).toBe('init\nupdated\nnext'); -// binaryContent.unsubscribe(); -// -// const fileContentUtf = (await test.content('stream.txt')).toUTF8(); -// fileContentUtf.activateNextOnAppend(); -// expect(fileContentUtf.value).toBe('init\nupdated\nnext'); -// -// console.log('end stream'); -// test.stream('stream.txt', '\nend'); -// await fileContentUtf.nextStateChange; -// expect(fileContentUtf.value).toBe('init\nupdated\nnext\nend'); -// -// await close(); -// }); diff --git a/packages/framework/tests/integration/live-database.spec.ts b/packages/framework/tests/integration/live-database.spec.ts deleted file mode 100644 index 99d9c538f..000000000 --- a/packages/framework/tests/integration/live-database.spec.ts +++ /dev/null @@ -1,199 +0,0 @@ -// import { ClassType } from '@deepkit/core'; -// import { createTestingApp as createTestingAppOriginal, LiveDatabase, TestingFacade } from '@deepkit/framework'; -// import { App, AppModule, RootModuleDefinition } from '@deepkit/app'; -// import { Database, DatabaseRegistry } from '@deepkit/orm'; -// import { Collection, IdInterface, rpc } from '@deepkit/rpc'; -// import { SQLiteDatabaseAdapter } from '@deepkit/sqlite'; -// import { AutoIncrement, BackReference, entity, PrimaryKey, Reference, uuid, UUID } from '@deepkit/type'; -// import { expect, test } from '@jest/globals'; -// -// export function createTestingApp(options: O, entities?: (ClassType)[]): TestingFacade> { -// return createTestingAppOriginal(options, [], (module: AppModule) => { -// module.addProvider({ provide: Database, useValue: new Database(new SQLiteDatabaseAdapter('/tmp/live-database.sqlite'), entities) }) -// module.setupGlobalProvider(DatabaseRegistry).addDatabase(Database, { migrateOnStartup: true }, module); -// }) as any; -// } -// -// (global as any)['createTestingApp'] ||= createTestingApp; -// -// test('test entity collection reactive find', async () => { -// @entity.name.name('entitySyncTeam') -// class Team implements IdInterface { -// id: UUID & PrimaryKey = uuid(); -// -// version: number = 0; -// -// constructor(public name: string) { -// } -// } -// -// @entity.name('entitySyncUser') -// class User implements IdInterface { -// id: UUID & PrimaryKey = uuid(); -// -// version: number = 0; -// -// teams: Team[] & BackReference<{via: UserTeam}> = []; -// -// constructor(public name: string) { -// } -// } -// -// @entity.name('entitySyncUserTeam') -// class UserTeam { -// id: number & PrimaryKey & AutoIncrement = 0; -// -// version: number = 0; -// -// constructor( -// public team: Team & Reference, -// public user: User & Reference, -// ) { -// } -// } -// -// @rpc.controller('test') -// class TestController { -// constructor( -// private liveDatabase: LiveDatabase, -// private database: Database, -// ) { -// this.liveDatabase.enableChangeFeed(User, Team, UserTeam); -// } -// -// @rpc.action() -// async init() { -// await this.database.query(User).deleteMany(); -// await this.database.query(Team).deleteMany(); -// await this.database.query(UserTeam).deleteMany(); -// -// const teamA = new Team('Team a'); -// const teamB = new Team('Team b'); -// -// await this.database.persist(teamA); -// await this.database.persist(teamB); -// -// const addUser = async (name: string, team: Team) => { -// const user = new User(name); -// await this.database.persist(user); -// await this.database.persist(new UserTeam(team, user)); -// }; -// -// await addUser('Peter 1', teamA); -// await addUser('Peter 2', teamA); -// await addUser('Marc 1', teamA); -// -// await addUser('Marie', teamB); -// } -// -// @rpc.action() -// async unAssignUser(userName: string, teamName: string) { -// const user = await this.database.query(User).filter({ name: userName }).findOne(); -// const team = await this.database.query(Team).filter({ name: teamName }).findOne(); -// -// if (!user) throw new Error(`User ${userName} not found`); -// if (!team) throw new Error(`Team ${teamName} not found`); -// -// console.log('unassigned', user.name, 'from', team.name); -// await this.database.query(UserTeam).filter({ user: user, team: team }).deleteMany(); -// } -// -// @rpc.action() -// async getUserId(userName: string): Promise { -// const user = await this.database.query(User).filter({ name: userName }).findOne(); -// if (!user) throw new Error(`User ${userName} not found`); -// -// return user.id; -// } -// -// @rpc.action() -// async assignUser(userName: string, teamName: string) { -// console.log('assignUser', userName, teamName); -// const user = await this.database.query(User).filter({ name: userName }).findOne(); -// const team = await this.database.query(Team).filter({ name: teamName }).findOne(); -// -// if (!user) throw new Error(`User ${userName} not found`); -// if (!team) throw new Error(`Team ${teamName} not found`); -// -// await this.database.persist(new UserTeam(team, user)); -// } -// -// @rpc.action() -// async removeTeam(teamName: string) { -// const team = await this.database.query(Team).filter({ name: teamName }).findOne(); -// if (!team) throw new Error(`Team ${teamName} not found`); -// -// await this.database.query(Team).filter({ id: team.id }).deleteOne(); -// } -// -// @rpc.action() -// async find(teamName: string): Promise> { -// const collection = await this.liveDatabase.query(User) -// .useInnerJoin('teams') -// .filter({ name: { $parameter: 'teamName' } }) -// .end() -// .parameter('teamName', teamName) -// .find(); -// -// return collection; -// } -// } -// -// const testing = createTestingApp({ controllers: [TestController] }, [User, Team, UserTeam]); -// await testing.startServer(); -// const client = testing.createRpcClient(); -// const controller = client.controller('test'); -// -// await controller.init(); -// -// const marieId = await controller.getUserId('Marie'); -// -// // { -// // for (let i = 0; i < 50; i++) { -// // const teamMembers = await test.find('Team a'); -// // expect(teamMembers.count()).toBe(3); -// // await teamMembers.unsubscribe(); -// // } -// // } -// -// { -// const teamMembers = await controller.find('Team a'); -// expect(teamMembers.count()).toBe(3); -// console.log('members loaded'); -// -// console.log('apply Team B'); -// await teamMembers.setParameter('teamName', 'Team b').apply(); -// console.log('Team B loaded'); -// expect(teamMembers.count()).toBe(1); -// expect(teamMembers.all()[0].id).toBe(marieId); -// await teamMembers.unsubscribe(); -// } -// -// { -// const teamMembers = await controller.find('Team a'); -// console.log('members loaded'); -// expect(teamMembers.count()).toBe(3); -// expect(teamMembers.get(marieId)).toBeUndefined(); -// -// await controller.assignUser('Marie', 'Team a'); -// await teamMembers.nextStateChange; -// console.log('marie assigned', marieId, teamMembers.get(marieId)); -// expect(teamMembers.count()).toBe(4); -// expect(teamMembers.get(marieId)).toBeInstanceOf(User); -// expect(teamMembers.get(marieId)!.name).toBe('Marie'); -// -// console.log('marie unassign ...'); -// controller.unAssignUser('Marie', 'Team a'); -// await teamMembers.nextStateChange; -// console.log('marie unassigned'); -// expect(teamMembers.count()).toBe(3); -// expect(teamMembers.get(marieId)).toBeUndefined(); -// -// controller.removeTeam('Team a'); -// await teamMembers.nextStateChange; -// console.log('Team deleted'); -// expect(teamMembers.count()).toBe(0); -// expect(teamMembers.get(marieId)).toBeUndefined(); -// teamMembers.unsubscribe(); -// } -// }); diff --git a/packages/framework/tests/integration/peer2peer.spec.ts b/packages/framework/tests/integration/peer2peer.spec.ts deleted file mode 100644 index f4d748665..000000000 --- a/packages/framework/tests/integration/peer2peer.spec.ts +++ /dev/null @@ -1,265 +0,0 @@ -// import { afterAll, expect, test } from '@jest/globals'; -// import { Entity, f } from '@deepkit/type'; -// import { appModuleForControllers, closeAllCreatedServers, createServerClientPair } from './util.js'; -// import { createModule, DeepkitRpcSecurity } from '@deepkit/framework'; -// import { Observable } from 'rxjs'; -// import { sleep } from '@deepkit/core'; -// import { rpc, RpcKernelSecurity, } from '@deepkit/rpc'; -// import { fail } from 'assert'; -// import ws from 'ws'; -// -// // @ts-ignore -// global['WebSocket'] = ws; -// -// afterAll(async () => { -// await closeAllCreatedServers(); -// }); -// -// @Entity('peer2peer/user') -// class User { -// constructor(@f public name: string) { -// this.name = name; -// } -// } -// -// test('test peer2peer', async () => { -// @rpc.controller('test') -// class TestController { -// @rpc.action() -// @f.array(String) -// names(last: string): string[] { -// return ['a', 'b', 'c', last]; -// } -// -// @rpc.action() -// user(name: string): User { -// return new User(name); -// } -// -// @rpc.action() -// ob(): Observable { -// return new Observable((observer) => { -// console.log('lets go?'); -// observer.next('Hello!'); -// observer.complete(); -// }); -// } -// -// @rpc.action() -// throwError(): void { -// throw new Error('Errored.'); -// } -// } -// -// const AppModule = createModule({ -// controllers: [TestController], -// providers: [ -// { -// provide: DeepkitRpcSecurity, useValue: new class extends RpcKernelSecurity { -// async isAllowedToRegisterAsPeer(session: Session | undefined, peerId: string): Promise { -// if (peerId === 'forbiddenToRegister') return false; -// return true; -// } -// -// async isAllowedToSendToPeer(session: Session | undefined, peerId: string): Promise { -// if (peerId === 'forbiddenToSend') return false; -// return true; -// } -// } -// } -// ] -// }); -// -// const { client, server, createClient, close } = await createServerClientPair('test peer2peer', AppModule); -// -// await client.registerAsPeer('itsme'); -// client.registerController('test', TestController); -// -// const client2 = createClient(); -// const peerController = client2.peer('itsme').controller('test'); -// -// const result = await peerController.names('myName'); -// expect(result).toEqual(['a', 'b', 'c', 'myName']); -// -// const user = await peerController.user('Peter'); -// expect(user).toBeInstanceOf(User); -// expect(user.name).toBe('Peter'); -// -// const observable = await peerController.ob(); -// observable.subscribe((next) => { -// console.log('next', next); -// }, (error) => { -// console.log('error', error); -// }, () => { -// console.log('complete'); -// }); -// console.log('----'); -// const lastMessage = await observable.toPromise(); -// console.log('lastMessage', lastMessage); -// -// try { -// await peerController.throwError(); -// fail('should error'); -// } catch (error) { -// expect(error.message).toBe('Errored.'); -// } -// -// try { -// await (peerController as any).nothing(); -// fail('should error'); -// } catch (error) { -// expect(error.message).toBe('Peer action nothing does not exist.'); -// } -// -// try { -// await client.registerController('forbiddenToRegister', new TestController); -// fail('should error'); -// } catch (error) { -// expect(error.message).toBe('Access denied to register controller forbiddenToRegister'); -// } -// -// await client.registerController('forbiddenToSend', new TestController); -// try { -// const controller2 = client2.peerController('forbiddenToSend'); -// await controller2.names('asd'); -// fail('should error'); -// } catch (error) { -// expect(error.message).toBe('Access denied to peer controller forbiddenToSend'); -// } -// await close(); -// }); -// -// test('test peer2peer internal client', async () => { -// @rpc.controller('test') -// class TestController { -// @rpc.action() -// @f.array(String) -// names(last: string): string[] { -// return ['a', 'b', 'c', last]; -// } -// -// @rpc.action() -// user(name: string): User { -// return new User(name); -// } -// -// @rpc.action() -// ob(): Observable { -// return new Observable((observer) => { -// console.log('lets go?'); -// observer.next('Hello!'); -// observer.complete(); -// }); -// } -// -// @rpc.action() -// throwError(): void { -// throw new Error('Errored.'); -// } -// } -// -// const { client, server, app, close } = await createServerClientPair('test peer2peer internal client', appModuleForControllers([TestController])); -// -// await client.registerController('test', new TestController); -// -// const internalClient: InternalClient = app.get(InternalClient); -// const internalClientConnection = internalClient.create(); -// const internalPeerController = internalClientConnection.peerController('test'); -// -// { -// const result = await internalPeerController.names('myName'); -// expect(result).toEqual(['a', 'b', 'c', 'myName']); -// -// const user = await internalPeerController.user('Peter'); -// expect(user).toBeInstanceOf(User); -// expect(user.name).toBe('Peter'); -// -// try { -// await internalPeerController.throwError(); -// fail('should error'); -// } catch (error) { -// expect(error.message).toBe('Errored.'); -// } -// } -// -// internalClientConnection.destroy(); -// -// await close(); -// }); -// -// test('test peer2peer offline', async () => { -// @rpc.controller('test') -// class TestController { -// @rpc.action() -// ping(): Boolean { -// return true; -// } -// -// @rpc.action() -// async timeout(): Promise { -// await sleep(2); -// } -// } -// -// const { client, server, app, createClient, close } = await createServerClientPair('test peer2peer offline', appModuleForControllers([TestController])); -// -// const client2 = createClient(); -// -// const peerController = client2.peerController('test', 1); -// const internalClient: InternalClient = app.get(InternalClient); -// const internalClientConnection = internalClient.create(); -// -// const controller = client.controller('test', 1); -// -// try { -// const result = await controller.timeout(); -// fail('Should not work'); -// } catch (error) { -// expect(error).toContain('Server timed out'); -// } -// -// try { -// const result = await peerController.ping(); -// fail('Should not work'); -// } catch (error) { -// expect(error.message).toContain('Peer controller test not registered'); -// } -// -// try { -// const peerController = internalClientConnection.peerController('test'); -// const result = await peerController.ping(); -// fail('Should not work'); -// } catch (error) { -// expect(error.message).toContain('Peer controller test not registered'); -// } -// -// await client.registerController('test', new TestController); -// -// const result = await peerController.ping(); -// expect(result).toBe(true); -// -// try { -// const result = await peerController.timeout(); -// fail('Should not work'); -// } catch (error) { -// expect(error).toContain('Server timed out after'); -// } -// -// //todo, this fails, but only when we called "await peerController.timeout();" and it errors first -// // question is what could it be? -// { -// const peerController = internalClientConnection.peerController('test', 1); -// const result = await peerController.ping(); -// expect(result).toBe(true); -// } -// -// try { -// const peerController = internalClientConnection.peerController('test', 1); -// const result = await peerController.timeout(); -// fail('Should not work'); -// } catch (error) { -// expect(error).toContain('Timed out'); -// } -// -// await close(); -// });