UNPKG

1.84 kBJavaScriptView Raw
1import chai, { expect } from "chai";
2import path from "path";
3import sinon from "sinon";
4import sinonChai from "sinon-chai";
5
6import ResourceTestHelper from "./ResourceTestHelper";
7
8import StreamResource from "../lib/StreamResource";
9import HttpClient from "../lib/HttpClient";
10import Credentials from "../lib/Credentials";
11
12chai.use(sinonChai);
13
14var creds = Credentials.parse({
15 applicationId: "some-id",
16 privateKey: path.join(__dirname, "private-test.key")
17});
18var emptyCallback = () => {};
19
20describe("StreamResource", () => {
21 var httpClientStub = null;
22 var stream = null;
23
24 beforeEach(() => {
25 httpClientStub = sinon.createStubInstance(HttpClient);
26 var options = {
27 httpClient: httpClientStub
28 };
29 stream = new StreamResource(creds, options);
30 });
31
32 it("should allow a stream to be started", () => {
33 const callId = "2342342-lkjhlkjh-32423";
34 var params = {
35 stream_url: "https://example.com/test.mp3" // eslint-disable-line camelcase
36 }; // eslint-disable-line camelcase
37 stream.start(callId, params, emptyCallback);
38
39 var expectedRequestArgs = ResourceTestHelper.requestArgsMatch(params, {
40 path: StreamResource.PATH.replace("{call_uuid}", callId),
41 method: "PUT"
42 });
43 expect(httpClientStub.request).to.have.been.calledWith(
44 sinon.match(expectedRequestArgs),
45 emptyCallback
46 );
47 });
48
49 it("should be possible to stop a stream", () => {
50 const callId = "2342342-lkjhlkjh-32423";
51 stream.stop(callId, emptyCallback);
52
53 var expectedRequestArgs = ResourceTestHelper.requestArgsMatch(null, {
54 method: "DELETE",
55 body: undefined,
56 path: StreamResource.PATH.replace("{call_uuid}", callId)
57 });
58
59 expect(httpClientStub.request).to.have.been.calledWith(
60 sinon.match(expectedRequestArgs),
61 emptyCallback
62 );
63 });
64});