-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c4ee9e6
commit 583879d
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
apps/server/src/infra/tldraw-client/tldraw-client.adapter.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
}); | ||
}); |