Skip to content

Commit fa55bef

Browse files
committed
update tests
1 parent e0aece5 commit fa55bef

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Unit tests for: serializeResponse
2+
3+
import { GetObjectResponse } from "@aserto/node-directory/src/gen/cjs/aserto/directory/reader/v3/reader_pb";
4+
5+
import { DsRegistry } from "../../../lib/directory/v3/serializer";
6+
import { InvalidSchemaError } from "../../../lib/errors";
7+
8+
// Mock types
9+
type MockGenMessage = {
10+
$typeName: string;
11+
};
12+
13+
describe("DsRegistry.serializeResponse()", () => {
14+
let dsRegistry: DsRegistry;
15+
16+
beforeEach(() => {
17+
dsRegistry = new DsRegistry();
18+
});
19+
20+
it("serializes a valid response successfully", () => {
21+
const mockResponse: GetObjectResponse = {
22+
$typeName: "aserto.directory.reader.v3.GetObjectResponse",
23+
result: {
24+
$typeName: "aserto.directory.common.v3.Object",
25+
type: "user",
26+
id: "123",
27+
displayName: "",
28+
etag: "1234",
29+
},
30+
relations: [],
31+
};
32+
33+
const result = dsRegistry.serializeResponse(mockResponse);
34+
35+
expect(result).toEqual({
36+
relations: [],
37+
result: {
38+
id: "123",
39+
type: "user",
40+
displayName: "",
41+
etag: "1234",
42+
},
43+
});
44+
});
45+
46+
it("throws InvalidSchemaError if schema is not registered", () => {
47+
const mockResponse: MockGenMessage = {
48+
$typeName: "invalid.type.name",
49+
};
50+
51+
expect(() => dsRegistry.serializeResponse(mockResponse)).toThrow(
52+
new InvalidSchemaError(
53+
"schema not registered for type: [invalid.type.name]",
54+
),
55+
);
56+
});
57+
});

0 commit comments

Comments
 (0)