Skip to content

Commit

Permalink
fix: update bigquery columns
Browse files Browse the repository at this point in the history
- test: update tests and freeze others
  • Loading branch information
yxuo committed Jan 24, 2024
1 parent a4e623b commit a181430
Show file tree
Hide file tree
Showing 32 changed files with 150 additions and 281 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*API do aplicativo CCT*
(Centro de Compensação Tarifária)


[Documentação completa](https://github.com/RJ-SMTR/api-cct/blob/main/docs/readme.md)

Este projeto foi baseado no template [Nestjs Boilerplate](https://github.com/brocoders/nestjs-boilerplate/)
Expand Down Expand Up @@ -90,6 +89,7 @@ Rodar seed apenas de alguns módulos
```
npm run seed:run user mailhistory
```
> O comando não diferencia maiúsculas de minúsculas
## Links

Expand Down Expand Up @@ -144,7 +144,7 @@ npm run test:e2e
**Exemplo de configuração no VSCode:**

Requisitos
- Extensão [Command Variable](ttps://marketplace.visualstudio.com/items?itemName=rioj7.command-variable)
- Extensão [Command Variable](https://marketplace.visualstudio.com/items?itemName=rioj7.command-variable)

.vscode/launch.json
```jsonc
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "env-cmd jest --config ./test/jest-e2e.json",
"test:e2e": "env-cmd jest --config ./test/jest-e2e.json --runInBand",
"prepare": "is-ci || husky install"
},
"dependencies": {
Expand Down
7 changes: 2 additions & 5 deletions src/bank-statements/bank-statements.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ describe('BankStatementsService', () => {
[`Integração`]: { count: 1, transactionValue: 10 },
},
transactionValueSum: 10,
permitCode: `pc_1`,
directionIdCounts: { 0: { count: 1, transactionValue: 10 } },
stopIdCounts: {
[day.toString()]: { count: 1, transactionValue: 10 },
Expand Down Expand Up @@ -255,7 +254,7 @@ describe('BankStatementsService', () => {
*/ async () => {
// Arrange
const bankStatements = allBankStatements.filter(
(i) => i.permitCode === 'pc_1',
(i) => i.cpfCnpj === 'cc_1',
);

const revenuesGroup: ITicketRevenuesGroup[] = [];
Expand All @@ -279,7 +278,6 @@ describe('BankStatementsService', () => {
[`Integração`]: { count: 1, transactionValue: 10 },
},
transactionValueSum: 10,
permitCode: `pc_1`,
directionIdCounts: { 0: { count: 1, transactionValue: 10 } },
stopIdCounts: {
[day.toString()]: { count: 1, transactionValue: 10 },
Expand Down Expand Up @@ -397,7 +395,7 @@ describe('BankStatementsService', () => {
*/ async () => {
// Arrange
const bankStatements = allBankStatements.filter(
(i) => i.permitCode === 'pc_1',
(i) => i.cpfCnpj === 'cc_1',
);

const revenuesGroup: ITicketRevenuesGroup[] = [];
Expand All @@ -421,7 +419,6 @@ describe('BankStatementsService', () => {
['Integração']: { count: 1, transactionValue: 10 },
},
transactionValueSum: 10,
permitCode: `pc_1`,
directionIdCounts: { 0: { count: 1, transactionValue: 10 } },
stopIdCounts: {
[day.toString()]: { count: 1, transactionValue: 10 },
Expand Down
4 changes: 2 additions & 2 deletions src/bank-statements/bank-statements.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ export class BankStatementsService {

// For now it validates if user exists
const user = await this.usersService.getOne({ id: args?.userId });
if (!user.permitCode || !user.id) {
if (!user.cpfCnpj || !user.id) {
throw new HttpException(
{
error: {
message: 'User not found',
user: {
...(!user.permitCode ? { permitCode: 'fieldIsEmpty' } : {}),
...(!user.cpfCnpj ? { cpfCnpj: 'fieldIsEmpty' } : {}),
...(!user.id ? { id: 'fieldIsEmpty' } : {}),
},
},
Expand Down
18 changes: 0 additions & 18 deletions src/banks/banks.controller.spec.ts

This file was deleted.

18 changes: 0 additions & 18 deletions src/banks/banks.service.spec.ts

This file was deleted.

18 changes: 0 additions & 18 deletions src/bigquery/bigquery.service.spec.ts

This file was deleted.

8 changes: 4 additions & 4 deletions src/bigquery/bigquery.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { HttpException, HttpStatus, Injectable, Logger } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { AllConfigType } from 'src/config/config.type';

export enum BigqueryServiceInstances {
export enum BQSInstances {
smtr = 'smtr',
}

Expand Down Expand Up @@ -68,7 +68,7 @@ export class BigqueryService {
});
}

public getBqInstance(option: BigqueryServiceInstances): BigQuery {
public getBqInstance(option: BQSInstances): BigQuery {
const bqInstance = this.bigQueryInstances[option];
if (bqInstance !== undefined) {
return bqInstance;
Expand All @@ -79,7 +79,7 @@ export class BigqueryService {
details: {
message: 'invalid bqService chosen',
bqInstances: Object.keys(this.bigQueryInstances),
availableOptions: Object.values(BigqueryServiceInstances),
availableOptions: Object.values(BQSInstances),
},
},
HttpStatus.INTERNAL_SERVER_ERROR,
Expand All @@ -90,7 +90,7 @@ export class BigqueryService {
* Run bigquery query with complete log and error handling
* @throws `HttpException`
*/
public async runQuery(bqInstance: BigqueryServiceInstances, query: string) {
public async runQuery(bqInstance: BQSInstances, query: string) {
this.logger.debug('Query fetch started');
console.log('bigquery:', query);
try {
Expand Down
10 changes: 5 additions & 5 deletions src/cron-jobs/cron-jobs.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import { DeepPartial } from 'typeorm';
/**
* All tests below were based on the requirements on GitHub.
* @see {@link https://github.com/RJ-SMTR/api-cct/issues/94#issuecomment-1815016208 Requirements #94 - GitHub}
*
* FIXME: 'imports: [ < the Module containing BankRepository > ]'
*/
describe('CronJobsService', () => {
xdescribe('CronJobsService', () => {
let cronJobsService: CronJobsService;
let settingsService: SettingsService;
let mailHistoryService: MailHistoryService;
Expand Down Expand Up @@ -94,8 +96,7 @@ describe('CronJobsService', () => {
});

describe('bulkSendInvites', () => {
// TODO: FIXME
xit('should abort if no mail quota available', async () => {
xit('[FIXME] should abort if no mail quota available', async () => {
// Arrange
jest
.spyOn(settingsService, 'findOneBySettingData')
Expand All @@ -117,8 +118,7 @@ describe('CronJobsService', () => {
expect(mailService.sendConcludeRegistration).toBeCalledTimes(0);
});

// TODO: FIXME
xit('should set mail status to SENT when succeeded', async () => {
xit('[FIXME] should set mail status to SENT when succeeded', async () => {
// Arrange
const dateNow = new Date('2023-01-01T10:00:00');
const user = new User({
Expand Down
26 changes: 13 additions & 13 deletions src/database/seeds/mail-history/mail-history-seed-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ import { UserSeedDataService } from '../user/user-seed-data.service';
export class MailHistorySeedDataService {
constructor(private userSeedDataService: UserSeedDataService) {}

getDataFromConfig(): IMailSeedData[] {
const mailSeedData: IMailSeedData[] = this.userSeedDataService
.getDataFromConfig()
.map(
(i: UserDataInterface) =>
({
user: {
...(i.id ? { id: i.id } : {}),
...(i.email ? { email: i.email } : {}),
},
inviteStatus: new InviteStatus(InviteStatusEnum.used),
} as IMailSeedData),
);
async getDataFromConfig(): Promise<IMailSeedData[]> {
const mailSeedData: IMailSeedData[] = (
await this.userSeedDataService.getDataFromConfig()
).map(
(i: UserDataInterface) =>
({
user: {
...(i.id ? { id: i.id } : {}),
...(i.email ? { email: i.email } : {}),
},
inviteStatus: new InviteStatus(InviteStatusEnum.used),
} as IMailSeedData),
);
return mailSeedData;
}
}
8 changes: 4 additions & 4 deletions src/database/seeds/mail-history/mail-history-seed.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ export class MailHistorySeedService {
}

async run() {
for (const item of this.mhSeedDataService.getDataFromConfig()) {
for (const item of await this.mhSeedDataService.getDataFromConfig()) {
const itemUser = await this.getHistoryUser(item);
const itemSeedUser = this.userSeedDataService
.getDataFromConfig()
.find((i) => i.email === itemUser.email);
const itemSeedUser = (
await this.userSeedDataService.getDataFromConfig()
).find((i) => i.email === itemUser.email);
const foundItem = await this.mailHistoryRepository.findOne({
where: {
user: { email: itemUser.email as string },
Expand Down
4 changes: 3 additions & 1 deletion src/database/seeds/run-seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ const runSeed = async () => {
for (const module of services) {
if (!(await app.get(module).validateRun()) && !force) {
console.log(`[${module.name}]: Database is not empty, aborting seed...`);
console.log(`Tip: Use '__force' parameter to ignore this message.`);
console.log(
`Tip: Use '${FORCE_PARAM}' parameter to ignore this message.`,
);
await app.close();
return;
}
Expand Down
5 changes: 4 additions & 1 deletion src/database/seeds/seed.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { SettingTypeSeedModule } from './setting-type/setting-type.module';
import { SettingSeedModule } from './setting/setting-seed.module';
import { StatusSeedModule } from './status/status-seed.module';
import { UserSeedModule } from './user/user-seed.module';
import { BigqueryModule } from 'src/bigquery/bigquery.module';
import googleConfig from 'src/config/google.config';

@Module({
imports: [
Expand All @@ -29,9 +31,10 @@ import { UserSeedModule } from './user/user-seed.module';
MailCountSeedModule,
UserSeedModule,
MailHistorySeedModule,
BigqueryModule,
ConfigModule.forRoot({
isGlobal: true,
load: [databaseConfig, appConfig, mailConfig],
load: [databaseConfig, appConfig, mailConfig, googleConfig],
envFilePath: ['.env'],
}),
TypeOrmModule.forRootAsync({
Expand Down
Loading

0 comments on commit a181430

Please sign in to comment.