Skip to content

Commit

Permalink
BC-6831 - remove authentication module from tldraw.module (#4824)
Browse files Browse the repository at this point in the history
* remove authentication module from tldraw.module

---------

Co-authored-by: Tomasz Wiaderek <[email protected]>
  • Loading branch information
2 people authored and virgilchiriac committed Mar 21, 2024
1 parent 1a76702 commit b2ba7d9
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { INestApplication } from '@nestjs/common';
import { EntityManager } from '@mikro-orm/mongodb';
import { courseFactory, TestXApiKeyClient, UserAndAccountTestFactory } from '@shared/testing';
import { Test, TestingModule } from '@nestjs/testing';
import { ServerTestModule } from '@modules/server';
import { Logger } from '@src/core/logger';
import { TldrawService } from '../../service';
import { TldrawController } from '..';
import { TldrawRepo } from '../../repo';
import { tldrawEntityFactory } from '../../testing';

const baseRouteName = '/tldraw-document';
describe('tldraw controller (api)', () => {
let app: INestApplication;
let em: EntityManager;
let testXApiKeyClient: TestXApiKeyClient;
const API_KEY = '7ccd4e11-c6f6-48b0-81eb-cccf7922e7a4';

beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [ServerTestModule],
controllers: [TldrawController],
providers: [Logger, TldrawService, TldrawRepo],
}).compile();

app = module.createNestApplication();
await app.init();
em = module.get(EntityManager);
testXApiKeyClient = new TestXApiKeyClient(app, baseRouteName, API_KEY);
});

afterAll(async () => {
await app.close();
});

describe('when request does not contain token', () => {
const setup = async () => {
const { teacherAccount, teacherUser } = UserAndAccountTestFactory.buildTeacher();
const course = courseFactory.build({ teachers: [teacherUser] });
await em.persistAndFlush([teacherAccount, teacherUser, course]);

const drawingItemData = tldrawEntityFactory.build();

await em.persistAndFlush([drawingItemData]);
em.clear();

return { teacherUser, drawingItemData };
};

it('should return status 401 for delete', async () => {
const { drawingItemData } = await setup();

const response = await testXApiKeyClient.delete(`${drawingItemData.docName}`);

expect(response.status).toEqual(401);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ export class TldrawWsService {
this.unsubscribeFromRedisChannels(doc);
await this.tldrawBoardRepo.compressDocument(doc.name);

if (this.configService.get<number>('TLDRAW_ASSETS_SYNC_ENABLED')) {
if (this.configService.get('TLDRAW_ASSETS_SYNC_ENABLED') === true) {
const usedAssets = this.syncDocumentAssetsWithShapes(doc);
void this.filesStorageTldrawAdapterService.deleteUnusedFilesForDocument(doc.name, usedAssets).catch((err) => {
this.logger.warning(new FileStorageErrorLoggable(doc.name, err));
Expand Down
6 changes: 3 additions & 3 deletions apps/server/src/modules/tldraw/tldraw.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import { ConfigModule } from '@nestjs/config';
import { createConfigModuleOptions, DB_PASSWORD, DB_USERNAME } from '@src/config';
import { LoggerModule } from '@src/core/logger';
import { MikroOrmModule, MikroOrmModuleSyncOptions } from '@mikro-orm/nestjs';
import { AuthenticationModule } from '@src/modules/authentication/authentication.module';
import { Dictionary, IPrimaryKey } from '@mikro-orm/core';
import { CoreModule } from '@src/core';
import { config, TLDRAW_DB_URL } from './config';
import { TldrawDrawing } from './entities';
import { TldrawController } from './controller';
import { TldrawService } from './service';
import { TldrawBoardRepo, TldrawRepo, YMongodb } from './repo';
// TODO must be fixed, direct import of a file from another module in not allowed
import { XApiKeyStrategy } from '../authentication/strategy/x-api-key.strategy';

const defaultMikroOrmOptions: MikroOrmModuleSyncOptions = {
findOneOrFailHandler: (entityName: string, where: Dictionary | IPrimaryKey) =>
Expand All @@ -21,7 +22,6 @@ const defaultMikroOrmOptions: MikroOrmModuleSyncOptions = {
@Module({
imports: [
LoggerModule,
AuthenticationModule,
CoreModule,
MikroOrmModule.forRoot({
...defaultMikroOrmOptions,
Expand All @@ -33,7 +33,7 @@ const defaultMikroOrmOptions: MikroOrmModuleSyncOptions = {
}),
ConfigModule.forRoot(createConfigModuleOptions(config)),
],
providers: [TldrawService, TldrawBoardRepo, TldrawRepo, YMongodb],
providers: [TldrawService, TldrawBoardRepo, TldrawRepo, YMongodb, XApiKeyStrategy],
controllers: [TldrawController],
})
export class TldrawModule {}

0 comments on commit b2ba7d9

Please sign in to comment.