Skip to content

Commit

Permalink
api: stream: allow name update (#2323)
Browse files Browse the repository at this point in the history
* api: stream: allow name update

* tests

* add name to field type check

* update test
  • Loading branch information
gioelecerati authored Oct 17, 2024
1 parent 40cc7d3 commit 49ac859
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
19 changes: 10 additions & 9 deletions packages/api/src/controllers/stream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,15 @@ describe("controllers/stream", () => {
});
});

it("should allow patch of name", async () => {
const res = await client.patch(patchPath, {
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 () => {
const res = await client.patch(patchPath, {
playbackPolicy: {
Expand All @@ -1257,15 +1266,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 }] },
Expand Down Expand Up @@ -1309,6 +1309,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 () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/api/src/controllers/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1961,6 +1961,7 @@ app.patch(
creatorId,
profiles,
recordingSpec,
name,
} = payload;
if (record != undefined && stream.isActive && stream.record != record) {
res.status(400);
Expand All @@ -1977,6 +1978,7 @@ app.patch(

let patch: StreamPatchPayload & Partial<DBStream> = {
record,
name,
profiles,
suspended,
creatorId: mapInputCreatorId(creatorId),
Expand Down
2 changes: 2 additions & 0 deletions packages/api/src/schema/api-schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 49ac859

Please sign in to comment.