-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
dccbd33
commit 8a1b523
Showing
2 changed files
with
111 additions
and
1 deletion.
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
50 changes: 50 additions & 0 deletions
50
packages/cli/src/databases/repositories/__tests__/credentials.repository.test.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,50 @@ | ||
import { mock } from 'jest-mock-extended'; | ||
import { Container } from 'typedi'; | ||
|
||
import { CredentialsEntity } from '@/databases/entities/credentials-entity'; | ||
import { mockEntityManager } from '@test/mocking'; | ||
|
||
import { CredentialsRepository } from '../credentials.repository'; | ||
|
||
const entityManager = mockEntityManager(CredentialsEntity); | ||
const repository = Container.get(CredentialsRepository); | ||
|
||
describe('findMany', () => { | ||
const credentialsId = 'cred_123'; | ||
const credential = mock<CredentialsEntity>({ id: credentialsId }); | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
test('return `data` property if `includeData:true` and select is using the record syntax', async () => { | ||
// ARRANGE | ||
entityManager.find.mockResolvedValueOnce([credential]); | ||
|
||
// ACT | ||
const credentials = await repository.findMany({ includeData: true, select: { id: true } }); | ||
|
||
// ASSERT | ||
expect(credentials).toHaveLength(1); | ||
expect(credentials[0]).toHaveProperty('data'); | ||
}); | ||
|
||
test('return `data` property if `includeData:true` and select is using the record syntax', async () => { | ||
// ARRANGE | ||
entityManager.find.mockResolvedValueOnce([credential]); | ||
|
||
// ACT | ||
const credentials = await repository.findMany({ | ||
includeData: true, | ||
//TODO: fix this | ||
// The function's type does not support this but this is what it | ||
// actually gets from the service because the middlewares are typed | ||
// loosely. | ||
select: ['id'] as never, | ||
}); | ||
|
||
// ASSERT | ||
expect(credentials).toHaveLength(1); | ||
expect(credentials[0]).toHaveProperty('data'); | ||
}); | ||
}); |