Skip to content

Commit

Permalink
chore: Add tests for validateServiceRegistration (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnjcsmith authored Dec 10, 2024
1 parent 2f10b83 commit f571c0f
Showing 1 changed file with 91 additions and 1 deletion.
92 changes: 91 additions & 1 deletion control-plane/src/modules/service-definitions.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { dereferenceSync, JSONSchema } from "dereference-json-schema";
import { InvalidJobArgumentsError } from "../utilities/errors";
import { InvalidJobArgumentsError, InvalidServiceRegistrationError } from "../utilities/errors";
import { packer } from "./packer";
import {
deserializeFunctionSchema,
embeddableServiceFunction,
parseJobArgs,
serviceFunctionEmbeddingId,
updateServiceEmbeddings,
validateServiceRegistration,
} from "./service-definitions";
import { createOwner } from "./test/util";
import { zodToJsonSchema } from "zod-to-json-schema";
import { z } from "zod";
describe("updateServiceEmbeddings", () => {
let owner: { clusterId: string };
beforeAll(async () => {
Expand Down Expand Up @@ -281,3 +283,91 @@ describe("deserializeFunctionSchema", () => {
});
});
});

describe("validateServiceRegistration", () => {
it("should reject invalid schema", () => {
expect(() => {
validateServiceRegistration({
service: "default",
definition: {
name: "default",
functions: [
{
name: "someFn",
schema: JSON.stringify({
type: "wrong_type",
})
},
],
},
});
}).toThrow(InvalidServiceRegistrationError);
})

it("should accept valid schema", () => {
expect(() => {
validateServiceRegistration({
service: "default",
definition: {
name: "default",
functions: [
{
name: "someFn",
description: "someFn",
schema: JSON.stringify(zodToJsonSchema(
z.object({
test: z.string(),
})
))
},
],
},
});
}).not.toThrow();
})

it("should reject incorrect handleCustomerAuth registration", () => {
expect(() => {
validateServiceRegistration({
service: "default",
definition: {
name: "default",
functions: [
{
name: "handleCustomerAuth",
description: "handleCustomerAuth",
schema: JSON.stringify(zodToJsonSchema(
z.object({
test: z.string(),
})
))
},
],
},
});
}).toThrow(InvalidServiceRegistrationError);
})

it("should accept valid handleCustomerAuth registration", () => {
expect(() => {
validateServiceRegistration({
service: "default",
definition: {
name: "default",
functions: [
{
name: "handleCustomerAuth",
description: "handleCustomerAuth",
schema: JSON.stringify(zodToJsonSchema(
z.object({
token: z.string(),
})
))
},
],
},
});
}).not.toThrow();
})

})

0 comments on commit f571c0f

Please sign in to comment.