-
Notifications
You must be signed in to change notification settings - Fork 0
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
5 changed files
with
129 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
89 changes: 89 additions & 0 deletions
89
src/bigquery/repositories/bq-transacao.repository.service.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,89 @@ | ||
import { Provider } from '@nestjs/common'; | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { BigqueryService } from 'src/bigquery/bigquery.service'; | ||
import { SettingsService } from 'src/settings/settings.service'; | ||
import { BqTransacaoRepositoryService } from './bq-transacao.repository.service'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import { resolve } from 'path'; | ||
import { config } from 'dotenv'; | ||
import { BigqueryEnvironment } from 'src/settings/enums/bigquery-env.enum'; | ||
import { SettingEntity } from 'src/settings/entities/setting.entity'; | ||
|
||
describe('BqTransacaoRepositoryService', () => { | ||
let settingsService: SettingsService; | ||
let bqTransacaoRepository: BqTransacaoRepositoryService; | ||
const mockBqGoogleCredentials = () => ({ | ||
'google.clientApiType': process.env.GOOGLE_CLIENT_API_TYPE, | ||
'google.clientApiProjectId': process.env.GOOGLE_CLIENT_API_PROJECT_ID, | ||
'google.clientApiPrivateKeyId': | ||
process.env.GOOGLE_CLIENT_API_PRIVATE_KEY_ID, | ||
'google.clientApiPrivateKey': process.env.GOOGLE_CLIENT_API_PRIVATE_KEY, | ||
'google.clientApiClientEmail': process.env.GOOGLE_CLIENT_API_CLIENT_EMAIL, | ||
'google.clientApiClientId': process.env.GOOGLE_CLIENT_API_CLIENT_ID, | ||
'google.clientApiAuthUri': process.env.GOOGLE_CLIENT_API_AUTH_URI, | ||
'google.clientApiTokenUri': process.env.GOOGLE_CLIENT_API_TOKEN_URI, | ||
'google.clientApiAuthProviderX509CertUrl': | ||
process.env.GOOGLE_CLIENT_API_AUTH_PROVIDER_X509_CERT_URL, | ||
'google.clientApiClientX509CertUrl': | ||
process.env.GOOGLE_CLIENT_API_CLIENT_X509_CERT_URL, | ||
'google.clientApiUniverseDomain': | ||
process.env.GOOGLE_CLIENT_API_UNIVERSE_DOMAIN, | ||
}); | ||
|
||
beforeAll(() => { | ||
const envPath = resolve(__dirname, '../../../.env'); | ||
config({ path: envPath }); | ||
}); | ||
|
||
beforeEach(async () => { | ||
const settingsServiceMock = { | ||
provide: SettingsService, | ||
useValue: { | ||
getOneBySettingData: jest.fn(), | ||
}, | ||
} as Provider; | ||
const configServiceMock = { | ||
provide: ConfigService, | ||
useValue: { | ||
getOrThrow: jest.fn((key: string) => mockBqGoogleCredentials()[key]), | ||
}, | ||
} as Provider; | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [ | ||
BigqueryService, | ||
BqTransacaoRepositoryService, | ||
settingsServiceMock, | ||
configServiceMock, | ||
], | ||
}).compile(); | ||
|
||
settingsService = module.get(SettingsService); | ||
bqTransacaoRepository = module.get(BqTransacaoRepositoryService); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(settingsService).toBeDefined(); | ||
}); | ||
|
||
describe('findTransacaoBy', () => { | ||
it('should return some data', async () => { | ||
// Arrange | ||
jest.spyOn(settingsService, 'getOneBySettingData').mockResolvedValueOnce({ | ||
getValueAsString: () => BigqueryEnvironment.Development, | ||
} as SettingEntity); | ||
|
||
// Act | ||
const result = await bqTransacaoRepository.findTransacaoBy({ | ||
startDate: new Date('2023-06-01'), | ||
endDate: new Date('2024-06-01'), | ||
}); | ||
|
||
// Assert | ||
expect(result.length).toBeGreaterThan(0); | ||
}); | ||
}); | ||
}); |
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