From c58d594a1e83f4eb0cdd249a68e97a36831bba0b Mon Sep 17 00:00:00 2001 From: Siddhant Date: Sat, 16 Sep 2023 17:18:43 -0500 Subject: [PATCH] improve(logs): allow logs without a message --- src/endpoints/logs.ts | 2 +- tests/logs.test.ts | 39 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/endpoints/logs.ts b/src/endpoints/logs.ts index 08168ed..f147437 100644 --- a/src/endpoints/logs.ts +++ b/src/endpoints/logs.ts @@ -19,7 +19,7 @@ export const LogSchema = z.object({ }), // Text content of the log - message: z.string(), + message: z.string().optional(), // Metadata specific to this log line kv: LogKVSchema.optional(), diff --git a/tests/logs.test.ts b/tests/logs.test.ts index e7e194f..d5bba71 100644 --- a/tests/logs.test.ts +++ b/tests/logs.test.ts @@ -285,7 +285,7 @@ test("with both kv", async () => { }); }); -test('with undefined kv values', async () => { +test("with undefined kv values", async () => { const res = await logs .ship( { @@ -320,7 +320,42 @@ test('with undefined kv values', async () => { }, ], }); -}) +}); + +test("with no message", async () => { + const res = await logs + .ship( + { + success: true, + data: { + service: "blob-city", + environment: "production", + kv: { common: undefined }, + logs: [ + { + level: "info", + timestamp: { p: "ns", v: "001" }, + }, + ], + }, + }, + env, + ) + .then((r) => r.json()); + + expect(res).toStrictEqual({ + streams: [ + { + stream: { + environment: "production", + service: "blob-city", + level: "info", + }, + values: [["001", ""]], + }, + ], + }); +}); test("multiple logs", async () => { const res = await logs