• 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

80.0
/src/datasources/network/network.module.ts
1
import { Global, Module } from '@nestjs/common';
18✔
2
import { IConfigurationService } from '@/config/configuration.service.interface';
18✔
3
import { FetchNetworkService } from '@/datasources/network/fetch.network.service';
18✔
4
import { NetworkService } from '@/datasources/network/network.service.interface';
18✔
5
import { NetworkResponse } from '@/datasources/network/entities/network.response.entity';
6
import {
18✔
7
  NetworkRequestError,
8
  NetworkResponseError,
9
} from '@/datasources/network/entities/network.error.entity';
10

11
export type FetchClient = <T>(
12
  url: string,
13
  options: RequestInit,
14
) => Promise<NetworkResponse<T>>;
15

16
/**
17
 * Use this factory to create a {@link FetchClient} instance
18
 * that can be used to make HTTP requests.
19
 */
20
function fetchClientFactory(
21
  configurationService: IConfigurationService,
22
): FetchClient {
23
  const requestTimeout = configurationService.getOrThrow<number>(
18✔
24
    'httpClient.requestTimeout',
25
  );
26

27
  return async <T>(
18✔
28
    url: string,
29
    options: RequestInit,
30
  ): Promise<NetworkResponse<T>> => {
31
    let urlObject: URL | null = null;
32✔
32
    let response: Response | null = null;
32✔
33

34
    try {
32✔
35
      urlObject = new URL(url);
32✔
36
      response = await fetch(url, {
32✔
37
        ...options,
38
        signal: AbortSignal.timeout(requestTimeout),
39
        keepalive: true,
40
      });
41
    } catch (error) {
UNCOV
42
      throw new NetworkRequestError(urlObject, error);
×
43
    }
44

45
    // We validate data so don't need worry about casting `null` response
46
    const data = (await response.json().catch(() => null)) as T;
32✔
47

48
    if (!response.ok) {
32!
UNCOV
49
      throw new NetworkResponseError(urlObject, response, data);
×
50
    }
51

52
    return {
32✔
53
      status: response.status,
54
      data,
55
    };
56
  };
57
}
58

59
/**
60
 * A {@link Global} Module which provides HTTP support via {@link NetworkService}
61
 * Feature Modules don't need to import this module directly in order to inject
62
 * the {@link NetworkService}.
63
 *
64
 * This module should be included in the "root" application module
65
 */
66
@Global()
67
@Module({
68
  providers: [
69
    {
70
      provide: 'FetchClient',
71
      useFactory: fetchClientFactory,
72
      inject: [IConfigurationService],
73
    },
74
    { provide: NetworkService, useClass: FetchNetworkService },
75
  ],
76
  exports: [NetworkService],
77
})
78
export class NetworkModule {}
18✔
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