From 4fd54195e97e32f6efdd7bd3196a56c6252bb456 Mon Sep 17 00:00:00 2001 From: gioelecerati Date: Thu, 17 Oct 2024 17:17:38 +0200 Subject: [PATCH 1/4] api: stream: allow name update --- packages/api/src/controllers/stream.ts | 2 ++ packages/api/src/schema/api-schema.yaml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/packages/api/src/controllers/stream.ts b/packages/api/src/controllers/stream.ts index 0bac9d52d..3bf42ba76 100644 --- a/packages/api/src/controllers/stream.ts +++ b/packages/api/src/controllers/stream.ts @@ -1961,6 +1961,7 @@ app.patch( creatorId, profiles, recordingSpec, + name, } = payload; if (record != undefined && stream.isActive && stream.record != record) { res.status(400); @@ -1977,6 +1978,7 @@ app.patch( let patch: StreamPatchPayload & Partial = { record, + name, profiles, suspended, creatorId: mapInputCreatorId(creatorId), diff --git a/packages/api/src/schema/api-schema.yaml b/packages/api/src/schema/api-schema.yaml index 435067a2b..5d715b0d4 100644 --- a/packages/api/src/schema/api-schema.yaml +++ b/packages/api/src/schema/api-schema.yaml @@ -768,6 +768,8 @@ components: $ref: "#/components/schemas/new-stream-payload/properties/recordingSpec" userTags: $ref: "#/components/schemas/stream/properties/userTags" + name: + $ref: "#/components/schemas/stream/properties/name" target-add-payload: type: object additionalProperties: false From 2dcfad98f0f31285af5993a948ac22bb99796de8 Mon Sep 17 00:00:00 2001 From: gioelecerati Date: Thu, 17 Oct 2024 17:19:30 +0200 Subject: [PATCH 2/4] tests --- packages/api/src/controllers/stream.test.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/api/src/controllers/stream.test.ts b/packages/api/src/controllers/stream.test.ts index 319c23f46..f411cbd4d 100644 --- a/packages/api/src/controllers/stream.test.ts +++ b/packages/api/src/controllers/stream.test.ts @@ -1240,6 +1240,13 @@ describe("controllers/stream", () => { }); }); + it("should allow patch of name", async () => { + const res = await client.patch(patchPath, { + name: "new name", + }); + expect(res.status).toBe(204); + }); + it("should allow patch of playbackPolicy", async () => { const res = await client.patch(patchPath, { playbackPolicy: { @@ -1257,15 +1264,6 @@ describe("controllers/stream", () => { expect(res.status).toBe(400); }); - it("should disallow additional fields", async () => { - const res = await client.patch(patchPath, { - name: "the stream name is immutable", - }); - expect(res.status).toBe(422); - const json = await res.json(); - expect(json.errors[0]).toContain("additionalProperties"); - }); - it("should disallow adding recordingSpec without record=true", async () => { const res = await client.patch(patchPath, { recordingSpec: { profiles: [{ bitrate: 1600000 }] }, From fe00d9e8edc1a9defc67deb84991cc87b79ef9a1 Mon Sep 17 00:00:00 2001 From: gioelecerati Date: Thu, 17 Oct 2024 17:21:54 +0200 Subject: [PATCH 3/4] add name to field type check --- packages/api/src/controllers/stream.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/api/src/controllers/stream.test.ts b/packages/api/src/controllers/stream.test.ts index f411cbd4d..68d09ca0f 100644 --- a/packages/api/src/controllers/stream.test.ts +++ b/packages/api/src/controllers/stream.test.ts @@ -1307,6 +1307,7 @@ describe("controllers/stream", () => { multistream: { targets: { profile: "a", id: "b" } }, }); await testTypeErr({ multistream: { targets: [{ profile: 123 }] } }); + await testTypeErr({ name: 123 }); }); it("should validate url format", async () => { From 9f88fff3ea688d01f255ade497196c4e9c93fc0f Mon Sep 17 00:00:00 2001 From: gioelecerati Date: Thu, 17 Oct 2024 19:26:07 +0200 Subject: [PATCH 4/4] update test --- packages/api/src/controllers/stream.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/api/src/controllers/stream.test.ts b/packages/api/src/controllers/stream.test.ts index 68d09ca0f..6ee2554ab 100644 --- a/packages/api/src/controllers/stream.test.ts +++ b/packages/api/src/controllers/stream.test.ts @@ -1245,6 +1245,8 @@ describe("controllers/stream", () => { name: "new name", }); expect(res.status).toBe(204); + let s = await db.stream.get(stream.id); + expect(s.name).toBe("new name"); }); it("should allow patch of playbackPolicy", async () => {