-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
3 changed files
with
36 additions
and
3 deletions.
There are no files selected for viewing
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
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
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,33 @@ | ||
import { fromPartial } from '@total-typescript/shoehorn'; | ||
import type { EntityManager } from 'typeorm'; | ||
import type { Server } from '../../app/entities/Server'; | ||
import { ServersService } from '../../app/servers/ServersService.server'; | ||
|
||
describe('ServersService', () => { | ||
const findOneBy = vi.fn(); | ||
let em: EntityManager; | ||
let service: ServersService; | ||
|
||
beforeEach(() => { | ||
em = fromPartial<EntityManager>({ findOneBy }); | ||
service = new ServersService(em); | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
describe('getByPublicId', () => { | ||
it('throws error if server is not found', async () => { | ||
await expect(() => service.getByPublicId('123')).rejects.toEqual( | ||
new Error('Server with public ID 123 not found'), | ||
); | ||
}); | ||
|
||
it('returns server when found', async () => { | ||
const server = fromPartial<Server>({}); | ||
findOneBy.mockResolvedValue(server); | ||
|
||
const result = await service.getByPublicId('123'); | ||
|
||
expect(result).toEqual(server); | ||
}); | ||
}); | ||
}); |