-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathrust-codegen.test.ts
More file actions
43 lines (38 loc) · 1.51 KB
/
Copy pathrust-codegen.test.ts
File metadata and controls
43 lines (38 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import type { ApiSchema } from "../../scripts/codegen/utils.ts";
import { describe, expect, it } from "vitest";
import { generateApiTypesCode } from "../../scripts/codegen/rust.ts";
describe("Rust API type codegen", () => {
it("distinguishes a protocol-defined unknown value from the forward-compatible fallback", () => {
const code = generateApiTypesCode({
definitions: {
CatalogTrustEligibility: {
type: "string",
enum: ["default", "expanded", "hidden", "unknown"],
},
},
} as ApiSchema);
expect(code).toContain(`#[serde(rename = "unknown")]
UnknownValue,
/// Unknown variant for forward compatibility.
#[default]
#[serde(other)]
Unknown,`);
});
it("publicly re-exports API types moved into the shared session-events schema", () => {
const code = generateApiTypesCode({
definitions: {
PermissionDecision: {
type: "object",
required: ["source"],
properties: {
source: {
$ref: "session-events.schema.json#/definitions/PermissionDecisionSource",
},
},
},
},
} as ApiSchema);
expect(code).toContain("pub use super::session_events::{PermissionDecisionSource};");
expect(code).toContain("use crate::types::{RequestId, SessionId};");
});
});