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

safe-global / safe-client-gateway / 20091945613

10 Dec 2025 08:19AM UTC coverage: 89.03% (-1.2%) from 90.212%
20091945613

push

github

web-flow
refactor(cache): change Zerion cache keys to be per address only (#2839)

* refactor(cache): change Zerion cache keys to be per address only

Remove chainId from Zerion cache keys for balances, collectibles, and positions.
This changes the caching strategy from per-chain-per-address to per-address only,
allowing data to be shared across chains for the same address.

Cache key changes:
- Before: {chainId}_zerion_balances_{safeAddress}
- After: zerion_balances_{safeAddress}

Similar changes applied to positions and collectibles cache keys.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

Prettier

* refactor: remove unused chainId parameter from clear methods

Remove chainId parameter from clearBalances and clearCollectibles methods
in IBalancesApi interface and implementations. After the refactoring to
per-address cache keys, chainId is no longer needed by the API methods:

- ZerionBalancesApi uses address-only cache keys
- SafeBalancesApi uses its instance chainId variable

The repositories still accept chainId (needed to select the correct API)
but no longer pass it to the clear methods.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* Fix tests: Separate unit tests from integration/e2e tests

- Renamed tests requiring real infrastructure (.spec.ts -> .integration.spec.ts or .e2e-spec.ts)
- Updated package.json Jest config to exclude integration and e2e tests from default 'yarn test' run
- Tests requiring Redis, Postgres, or full app bootstrap are now properly categorized
- All 308 unit test suites now pass without requiring external services

Renamed files:
- Redis cache service test -> integration test
- Postgres database module tests (v1 & v2) -> integration tests
- Postgres database service test -> integration test
- Auth decorator test -> e2e test
- Spaces-related controller tests -> e2e tests
- ... (continued)

2835 of 3551 branches covered (79.84%)

Branch coverage included in aggregate %.

4 of 8 new or added lines in 5 files covered. (50.0%)

199 existing lines in 34 files now uncovered.

13616 of 14927 relevant lines covered (91.22%)

564.15 hits per line

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

89.13
/src/__tests__/testing-module.ts
1
import { Test, type TestingModule } from '@nestjs/testing';
92✔
2
import { AppModule } from '@/app.module';
92✔
3
import configuration from '@/config/entities/__tests__/configuration';
92✔
4
import { CacheModule } from '@/datasources/cache/cache.module';
92✔
5
import { TestCacheModule } from '@/datasources/cache/__tests__/test.cache.module';
92✔
6
import { RequestScopedLoggingModule } from '@/logging/logging.module';
92✔
7
import { TestLoggingModule } from '@/logging/__tests__/test.logging.module';
92✔
8
import { NetworkModule } from '@/datasources/network/network.module';
92✔
9
import { TestNetworkModule } from '@/datasources/network/__tests__/test.network.module';
92✔
10
import { QueuesApiModule } from '@/modules/queues/datasources/queues-api.module';
92✔
11
import { TestQueuesApiModule } from '@/modules/queues/datasources/__tests__/test.queues-api.module';
92✔
12
import { PostgresDatabaseModule } from '@/datasources/db/v1/postgres-database.module';
92✔
13
import { TestPostgresDatabaseModule } from '@/datasources/db/__tests__/test.postgres-database.module';
92✔
14
import { PostgresDatabaseModuleV2 } from '@/datasources/db/v2/postgres-database.module';
92✔
15
import { TestPostgresDatabaseModuleV2 } from '@/datasources/db/v2/test.postgres-database.module';
92✔
16
import { TargetedMessagingDatasourceModule } from '@/modules/targeted-messaging/datasources/targeted-messaging.datasource.module';
92✔
17
import { TestTargetedMessagingDatasourceModule } from '@/modules/targeted-messaging/datasources/__tests__/test.targeted-messaging.datasource.module';
92✔
18
import type { ModuleDefinition } from '@nestjs/core/interfaces/module-definition.interface';
19
import { CacheKeyPrefix } from '@/datasources/cache/constants';
92✔
20
import type { Provider } from '@nestjs/common';
21
import { CsvExportModule } from '@/modules/csv-export/csv-export.module';
92✔
22
import { TestCsvExportModule } from '@/modules/csv-export/v1/__tests__/test.csv-export.module';
92✔
23

24
export interface CreateBaseTestModuleOptions {
25
  config?: typeof configuration;
26
  overridePostgresV2?: boolean;
27
  cacheKeyPrefix?: string;
28
  modules?: Array<ModuleOverride>;
29
  providers?: Array<Provider>;
30
  guards?: Array<GuardOverride>;
31
}
32

33
export interface ModuleOverride {
34
  originalModule: ModuleDefinition;
35
  testModule: ModuleDefinition;
36
}
37

38
export interface GuardOverride {
39
  originalGuard: unknown;
40
  testGuard: unknown;
41
}
42

43
export async function createTestModule(
92✔
44
  options: CreateBaseTestModuleOptions = {},
114✔
45
): Promise<TestingModule> {
46
  const {
47
    config,
48
    cacheKeyPrefix,
49
    overridePostgresV2,
50
    modules: additionalOverrides = [],
631✔
51
    guards: guards = [],
887✔
52
    providers = [],
792✔
53
  } = options;
1,774✔
54

55
  return createBaseTestModule({
1,774✔
56
    config,
57
    overridePostgresV2,
58
    cacheKeyPrefix,
59
    guards,
60
    providers,
61
    modules: [
62
      {
63
        originalModule: CacheModule,
64
        testModule: TestCacheModule,
65
      },
66
      {
67
        originalModule: RequestScopedLoggingModule,
68
        testModule: TestLoggingModule,
69
      },
70
      {
71
        originalModule: NetworkModule,
72
        testModule: TestNetworkModule,
73
      },
74
      ...additionalOverrides,
75
    ],
76
  });
77
}
78

79
export async function createBaseTestModule(
92✔
80
  options: CreateBaseTestModuleOptions = {},
×
81
): Promise<TestingModule> {
82
  const {
83
    config = configuration,
136✔
84
    overridePostgresV2 = true, // Enable Postgres V2 by default
887✔
85
    cacheKeyPrefix = crypto.randomUUID(),
887✔
86
    modules: additionalOverrides = [],
×
87
    guards: guards = [],
×
88
    providers = [],
×
89
  } = options;
1,774✔
90

91
  const moduleBuilder = Test.createTestingModule({
1,774✔
92
    imports: [AppModule.register(config)],
93
    providers: providers,
94
  })
95
    .overrideProvider(CacheKeyPrefix)
96
    .useValue(cacheKeyPrefix)
97
    .overrideModule(PostgresDatabaseModule)
98
    .useModule(TestPostgresDatabaseModule)
99
    .overrideModule(TargetedMessagingDatasourceModule)
100
    .useModule(TestTargetedMessagingDatasourceModule)
101
    .overrideModule(QueuesApiModule)
102
    .useModule(TestQueuesApiModule)
103
    .overrideModule(CsvExportModule)
104
    .useModule(TestCsvExportModule);
105

106
  if (overridePostgresV2) {
1,774✔
107
    moduleBuilder
1,774✔
108
      .overrideModule(PostgresDatabaseModuleV2)
109
      .useModule(TestPostgresDatabaseModuleV2);
110
  }
111

112
  for (const guard of guards) {
1,774✔
UNCOV
113
    moduleBuilder.overrideGuard(guard.originalGuard).useValue(guard.testGuard);
×
114
  }
115

116
  // Apply additional overrides
117
  for (const override of additionalOverrides) {
1,774✔
118
    moduleBuilder
6,562✔
119
      .overrideModule(override.originalModule)
120
      .useModule(override.testModule);
121
  }
122

123
  return moduleBuilder.compile();
1,774✔
124
}
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