@starci/hfs 4.7.16 → 4.7.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,60 @@
1
+ import { Test } from "@nestjs/testing"
2
+ import { mock } from "@starci/jest-preset"
3
+ import { Secret } from "@modules/platform/config"
4
+ import type { DatabaseConnectionOptions } from "./database.options"
5
+ import type { ConnectionOpener, ConnectionSource } from "./database.port"
6
+ import { migrateConnections } from "./migrate-connections.client"
7
+
8
+ const MIGRATE_CLIENT = Symbol("migrate-connections")
9
+
10
+ const setup = async () => {
11
+ const moduleRef = await Test.createTestingModule({
12
+ providers: [{ provide: MIGRATE_CLIENT, useFactory: () => ({ migrateConnections }) }],
13
+ }).compile()
14
+ return moduleRef.get<{ readonly migrateConnections: typeof migrateConnections }>(MIGRATE_CLIENT)
15
+ }
16
+
17
+ const connection = (name: string): DatabaseConnectionOptions => ({
18
+ name,
19
+ url: new Secret(`postgres://localhost:5432/${name}`),
20
+ entities: [],
21
+ migrations: [],
22
+ })
23
+
24
+ describe("migrateConnections", () => {
25
+ it("runs the pending migrations of each connection in order and answers their names by connection", async () => {
26
+ const client = await setup()
27
+ const primary = mock<ConnectionSource>()
28
+ primary.runMigrations.mockResolvedValue([{ id: 1, timestamp: 1, name: "Init1" }])
29
+ const archive = mock<ConnectionSource>()
30
+ archive.runMigrations.mockResolvedValue([])
31
+ const sources = new Map([
32
+ ["primary", primary],
33
+ ["archive", archive],
34
+ ])
35
+ const opener = mock<ConnectionOpener>()
36
+ opener.open.mockImplementation(
37
+ (target: DatabaseConnectionOptions) => sources.get(target.name) ?? mock<ConnectionSource>(),
38
+ )
39
+
40
+ const applied = await client.migrateConnections([connection("primary"), connection("archive")], opener)
41
+
42
+ expect(applied).toEqual({ primary: ["Init1"], archive: [] })
43
+ expect(primary.initialize).toHaveBeenCalledTimes(1)
44
+ expect(primary.destroy).toHaveBeenCalledTimes(1)
45
+ expect(archive.destroy).toHaveBeenCalledTimes(1)
46
+ })
47
+
48
+ it("destroys the data source of a connection whose migration fails, and fails", async () => {
49
+ const client = await setup()
50
+ const failing = mock<ConnectionSource>()
51
+ failing.runMigrations.mockRejectedValue(new TypeError("relation already exists"))
52
+ const opener = mock<ConnectionOpener>()
53
+ opener.open.mockReturnValue(failing)
54
+
55
+ await expect(client.migrateConnections([connection("primary")], opener)).rejects.toThrow(
56
+ "relation already exists",
57
+ )
58
+ expect(failing.destroy).toHaveBeenCalledTimes(1)
59
+ })
60
+ })
@@ -11,6 +11,6 @@ export const createRetryLink = () =>
11
11
  delay: { initial: RETRY_POLICY.initialDelayMs, max: RETRY_POLICY.maxDelayMs, jitter: true },
12
12
  attempts: {
13
13
  max: RETRY_POLICY.maxAttempts,
14
- retryIf: (error) => error !== undefined && !CombinedGraphQLErrors.is(error),
14
+ retryIf: (error) => !CombinedGraphQLErrors.is(error),
15
15
  },
16
16
  })
package/upgrade/index.mjs CHANGED
@@ -18,6 +18,7 @@ import { byCodeUnit } from "../report/order.mjs";
18
18
  import {
19
19
  TEMPLATES_DIR,
20
20
  appSource,
21
+ bundledPresets,
21
22
  checkTargets,
22
23
  imageFiles,
23
24
  loadHfs,
@@ -48,7 +49,7 @@ const FULL_DEPENDENCIES = Object.freeze(["nest-commander"]);
48
49
  // ruling lacks (a current lite app already has it, and the e2e world's @starci/test-world is what full adds). These are the preset's two
49
50
  // public sync inputs; once apply resolves the new dependency, normal full sync reads them from @starci/jest-preset again.
50
51
  export const UPGRADE_PRESETS = Object.freeze({
51
- sonarExclusions: "**/*.spec.ts,**/*.e2e-spec.ts,**/dist/**,**/coverage/**",
52
+ sonarExclusions: bundledPresets().sonarExclusions,
52
53
  coverageSources: Object.freeze([
53
54
  "src/**/*.service.ts",
54
55
  "src/features/cli/**/*.cli.ts",