|
21 | 21 | * per-endpoint fix has nothing to read. |
22 | 22 | */ |
23 | 23 | import { describe, expect, test } from "vitest"; |
| 24 | +import { readFile } from "node:fs/promises"; |
24 | 25 | import { join } from "node:path"; |
25 | 26 | import { FIXTURES_DIR } from "../../scripts/helpers/root.helper.js"; |
26 | 27 | import { defaultOrchestrator } from "../../packages/frameworks/index.js"; |
27 | 28 | import { generateCollections } from "../../packages/core/discovery/generation.pipeline.js"; |
28 | 29 | import type { IGenerationOptions } from "../../packages/contracts/interfaces/core/discovery.interface.js"; |
| 30 | +import type { IOperation } from "../../packages/contracts/interfaces/core/operation.interface.js"; |
29 | 31 | import type { PostmanItem } from "../../packages/contracts/interfaces/core/postman.interface"; |
| 32 | +import type { IServiceDescriptor } from "../../packages/contracts/interfaces/core/service.interface.js"; |
| 33 | +import { combineServices } from "../../packages/core/merge/combine-services.service.js"; |
30 | 34 |
|
31 | 35 | const PROJECT = join(FIXTURES_DIR, "multi-service"); |
32 | 36 |
|
@@ -73,7 +77,57 @@ function asPostmanItem(value: unknown): PostmanItem | null { |
73 | 77 | return value as PostmanItem; |
74 | 78 | } |
75 | 79 |
|
| 80 | +function operation(serviceId: string, id: string): IOperation { |
| 81 | + return { |
| 82 | + id: { kind: "operation", value: id }, |
| 83 | + serviceId, |
| 84 | + transport: { kind: "http", method: "GET", path: "/" }, |
| 85 | + serverRef: { id: { kind: "server", value: "legacy" }, url: "http://legacy" }, |
| 86 | + authRef: { id: { kind: "auth", value: "legacy" }, type: "none" }, |
| 87 | + request: {}, |
| 88 | + responses: [], |
| 89 | + provenance: { sourceFile: "fixture-metadata" }, |
| 90 | + }; |
| 91 | +} |
| 92 | + |
76 | 93 | describe("c00010 S3 — multi-service monorepo (NestJS users-api + FastAPI billing-api)", () => { |
| 94 | + test("carga metadata declarativa real y conserva serviceId, serverRef y authRef", async () => { |
| 95 | + const usersManifest = JSON.parse(await readFile(join(PROJECT, "apps/users-api/package.json"), "utf8")) as { |
| 96 | + tanit: { serviceId: string; baseUrl: string; auth: IServiceDescriptor["auth"] }; |
| 97 | + }; |
| 98 | + const billingManifest = await readFile(join(PROJECT, "apps/billing-api/pyproject.toml"), "utf8"); |
| 99 | + expect(billingManifest).toContain('service_id = "billing"'); |
| 100 | + expect(billingManifest).toContain('base_url = "https://billing.example.com"'); |
| 101 | + expect(billingManifest).toContain('auth_kind = "apiKey"'); |
| 102 | + |
| 103 | + const result = combineServices([ |
| 104 | + { |
| 105 | + id: usersManifest.tanit.serviceId, |
| 106 | + baseUrl: usersManifest.tanit.baseUrl, |
| 107 | + auth: usersManifest.tanit.auth, |
| 108 | + variables: [], |
| 109 | + transport: { kind: "http", method: "GET", path: "/users" }, |
| 110 | + endpoints: [operation("users", "users-list")], |
| 111 | + }, |
| 112 | + { |
| 113 | + id: "billing", |
| 114 | + baseUrl: "https://billing.example.com", |
| 115 | + auth: { kind: "scheme", scheme: "apiKey" }, |
| 116 | + variables: [], |
| 117 | + transport: { kind: "http", method: "GET", path: "/invoices" }, |
| 118 | + endpoints: [operation("billing", "billing-list")], |
| 119 | + }, |
| 120 | + ]); |
| 121 | + expect(result.operations.map((item) => ({ |
| 122 | + serviceId: item.serviceId, |
| 123 | + server: item.serverRef, |
| 124 | + auth: item.authRef.type, |
| 125 | + }))).toEqual([ |
| 126 | + { serviceId: "users", server: { id: { kind: "server", value: "users" }, url: "https://users.example.com" }, auth: "oauth2" }, |
| 127 | + { serviceId: "billing", server: { id: { kind: "server", value: "billing" }, url: "https://billing.example.com" }, auth: "apiKey" }, |
| 128 | + ]); |
| 129 | + }); |
| 130 | + |
77 | 131 | test("el detector descubre ambos workspaces (users + invoices)", async () => { |
78 | 132 | const options: IGenerationOptions = { |
79 | 133 | combineServices: false, |
|
0 commit comments