Skip to content

Commit

Permalink
Add tldraw client adapter test
Browse files Browse the repository at this point in the history
  • Loading branch information
bischofmax committed Dec 11, 2024
1 parent c4ee9e6 commit 583879d
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions apps/server/src/infra/tldraw-client/tldraw-client.adapter.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { createMock, DeepMocked } from '@golevelup/ts-jest';
import { Test, TestingModule } from '@nestjs/testing';
import { TldrawDocumentApi } from './generated';
import { TldrawClientAdapter } from './tldraw-client.adapter';

describe('TldrawClientAdapter', () => {
describe('deleteDrawingBinData', () => {
let module: TestingModule;
let service: TldrawClientAdapter;
let tldrawDocumentApi: DeepMocked<TldrawDocumentApi>;

beforeAll(async () => {
module = await Test.createTestingModule({
providers: [
TldrawClientAdapter,
{
provide: TldrawDocumentApi,
useValue: createMock<TldrawDocumentApi>(),
},
],
}).compile();

service = module.get(TldrawClientAdapter);
tldrawDocumentApi = module.get(TldrawDocumentApi);
});

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

beforeEach(() => {
jest.resetAllMocks();
});

describe('when deleteByDocName resolves', () => {
it('should call deleteDrawingBinData', async () => {
const drawingId = 'drawingId';

await service.deleteDrawingBinData(drawingId);

expect(tldrawDocumentApi.deleteByDocName).toHaveBeenCalledWith(drawingId);
});
});

describe('when deleteByDocName rejects', () => {
it('should throw an error', async () => {
const drawingId = 'drawingId';
const error = new Error('deleteByDocName error');

tldrawDocumentApi.deleteByDocName.mockRejectedValue(error);

await expect(service.deleteDrawingBinData(drawingId)).rejects.toThrowError(error);
});
});
});
});

0 comments on commit 583879d

Please sign in to comment.