Skip to content
Snippets Groups Projects
Commit 11f9925c authored by Yoan VALLET's avatar Yoan VALLET
Browse files

feat: review account service test

parent 88d7a004
Branches
Tags
1 merge request!139Features/unit tests
...@@ -63,31 +63,27 @@ describe('Account service', () => { ...@@ -63,31 +63,27 @@ describe('Account service', () => {
describe('getAccountByType method', () => { describe('getAccountByType method', () => {
it('should return account with account_type equals to eglgrandlyon', async () => { it('should return account with account_type equals to eglgrandlyon', async () => {
const mockType = 'eglgrandlyon'
const mockQueryResult: QueryResult<Account[]> = { const mockQueryResult: QueryResult<Account[]> = {
data: [mockAccounts[2]], data: [mockAccounts[2]],
bookmark: '', bookmark: '',
next: false, next: false,
skip: 0, skip: 0,
} }
mockClient.query.mockImplementation(() => mockClient.query.mockResolvedValueOnce(mockQueryResult)
Promise.resolve(mockQueryResult) const mockType = 'eglgrandlyon'
)
const result = await accountService.getAccountByType(mockType) const result = await accountService.getAccountByType(mockType)
expect(result).toEqual(mockAccounts[2]) expect(result).toEqual(mockAccounts[2])
}) })
it('should return null when no account find', async () => { it('should return null when no account find', async () => {
const mockType = 'eglgrandlyon'
const mockQueryResult: QueryResult<Account[]> = { const mockQueryResult: QueryResult<Account[]> = {
data: [], data: [],
bookmark: '', bookmark: '',
next: false, next: false,
skip: 0, skip: 0,
} }
mockClient.query.mockImplementation(() => mockClient.query.mockResolvedValueOnce(mockQueryResult)
Promise.resolve(mockQueryResult) const mockType = 'eglgrandlyon'
)
const result = await accountService.getAccountByType(mockType) const result = await accountService.getAccountByType(mockType)
expect(result).toBe(null) expect(result).toBe(null)
}) })
...@@ -128,10 +124,16 @@ describe('Account service', () => { ...@@ -128,10 +124,16 @@ describe('Account service', () => {
}) })
describe('createIndexAccount method', () => { describe('createIndexAccount method', () => {
it('should return empty value', async () => { it('should return empty array', async () => {
mockHavestLibAccounts.deleteAccount.mockResolvedValueOnce(mockAccounts[2]) const mockQueryResult: QueryResult<Account[]> = {
const result = await accountService.deleteAccount(mockAccounts[2]) data: [],
expect(result).toBe(true) bookmark: '',
next: false,
skip: 0,
}
mockClient.query.mockResolvedValueOnce(mockQueryResult)
const result = await accountService.createIndexAccount()
expect(result).toEqual([])
}) })
}) })
}) })
...@@ -85,6 +85,7 @@ export default class AccountService { ...@@ -85,6 +85,7 @@ export default class AccountService {
// eslint-disable-next-line @typescript-eslint/camelcase // eslint-disable-next-line @typescript-eslint/camelcase
.where({ account_type: 'index' }) .where({ account_type: 'index' })
.limitBy(1) .limitBy(1)
return await this._client.query(query) const { data: result } = await this._client.query(query)
return result
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment