• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

safe-global / safe-client-gateway / 9546514333

17 Jun 2024 11:01AM UTC coverage: 49.473% (-42.8%) from 92.296%
9546514333

push

github

web-flow
Add `PostgresDatabaseMigrator` for (testing) migration (#1655)

Adds a new `PostgresDatabaseMigrator` that has the core logic of `postgres-shift`, as well as a testing method. The `migrate` method mirrors `postgres-shift` and the `test` method reuses part of it, executing each migration in a separate transaction. It allows us to interact with the database _before_ and _after_ a migration has executed, stopping after the desired migration:

- Create `PostgresDatabaseMigrator` and inject it
- Remove `postgres-shift` and associated definition/patch, replacing usage with the above
- Add appropriate test coverage

394 of 2367 branches covered (16.65%)

Branch coverage included in aggregate %.

10 of 62 new or added lines in 3 files covered. (16.13%)

2191 existing lines in 221 files now uncovered.

3969 of 6452 relevant lines covered (61.52%)

12.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

65.38
/src/routes/cache-hooks/cache-hooks.controller.ts
1
import {
16✔
2
  Body,
3
  Controller,
4
  HttpCode,
5
  Inject,
6
  Post,
7
  UseFilters,
8
  UseGuards,
9
} from '@nestjs/common';
10
import { ApiExcludeController } from '@nestjs/swagger';
16✔
11
import { CacheHooksService } from '@/routes/cache-hooks/cache-hooks.service';
16✔
12
import { ValidationPipe } from '@/validation/pipes/validation.pipe';
16✔
13
import { BasicAuthGuard } from '@/routes/common/auth/basic-auth.guard';
16✔
14
import { Event } from '@/routes/cache-hooks/entities/event.entity';
15
import { WebHookSchema } from '@/routes/cache-hooks/entities/schemas/web-hook.schema';
16✔
16
import { ILoggingService, LoggingService } from '@/logging/logging.interface';
16✔
17
import { IConfigurationService } from '@/config/configuration.service.interface';
16✔
18
import { EventProtocolChangedError } from '@/routes/cache-hooks/errors/event-protocol-changed.error';
16✔
19
import { EventProtocolChangedFilter } from '@/routes/cache-hooks/filters/event-protocol-changed.filter';
16✔
20
import { EventType } from '@/routes/cache-hooks/entities/event-type.entity';
21

22
@Controller({
23
  path: '',
24
  version: '1',
25
})
26
@ApiExcludeController()
27
export class CacheHooksController {
16✔
28
  private readonly isEventsQueueEnabled: boolean;
29
  private readonly configServiceEventTypes = [
16✔
30
    EventType.CHAIN_UPDATE,
31
    EventType.SAFE_APPS_UPDATE,
32
  ];
33

34
  constructor(
35
    private readonly service: CacheHooksService,
16✔
36
    @Inject(LoggingService) private readonly loggingService: ILoggingService,
16✔
37
    @Inject(IConfigurationService)
38
    private readonly configurationService: IConfigurationService,
16✔
39
  ) {
40
    this.isEventsQueueEnabled = this.configurationService.getOrThrow<boolean>(
16✔
41
      'features.eventsQueue',
42
    );
43
  }
44

45
  @UseGuards(BasicAuthGuard)
46
  @Post('/hooks/events')
47
  @UseFilters(EventProtocolChangedFilter)
48
  @HttpCode(202)
49
  postEvent(@Body(new ValidationPipe(WebHookSchema)) event: Event): void {
16✔
UNCOV
50
    if (!this.isEventsQueueEnabled || this.isHttpEvent(event)) {
×
UNCOV
51
      this.service.onEvent(event).catch((error) => {
×
52
        this.loggingService.error(error);
×
53
      });
54
    } else {
UNCOV
55
      throw new EventProtocolChangedError();
×
56
    }
57
  }
58

59
  private isHttpEvent(event: Event): boolean {
UNCOV
60
    return this.configServiceEventTypes.includes(event.type);
×
61
  }
62
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc