UNPKG

1.73 kBJavaScriptView Raw
1import chai, { expect } from "chai";
2
3import path from "path";
4import sinon from "sinon";
5import sinonChai from "sinon-chai";
6
7import ResourceTestHelper from "./ResourceTestHelper";
8
9import TalkResource from "../lib/TalkResource";
10import HttpClient from "../lib/HttpClient";
11import Credentials from "../lib/Credentials";
12
13chai.use(sinonChai);
14var creds = Credentials.parse({
15 applicationId: "some-id",
16 privateKey: path.join(__dirname, "private-test.key")
17});
18var emptyCallback = () => {};
19
20describe("TalkResource", () => {
21 var httpClientStub = null;
22 var talk = null;
23
24 beforeEach(() => {
25 httpClientStub = sinon.createStubInstance(HttpClient);
26 var options = {
27 httpClient: httpClientStub
28 };
29 talk = new TalkResource(creds, options);
30 });
31
32 it("should be able to start a talk", () => {
33 const callId = "2342342-lkjhlkjh-32423";
34 var params = {
35 text: "Hello!"
36 };
37 talk.start(callId, params, emptyCallback);
38
39 var expectedRequestArgs = ResourceTestHelper.requestArgsMatch(params, {
40 path: TalkResource.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 an ongoing talk", () => {
50 const callId = "2342342-lkjhlkjh-32423";
51 talk.stop(callId, emptyCallback);
52
53 var expectedRequestArgs = ResourceTestHelper.requestArgsMatch(null, {
54 method: "DELETE",
55 body: undefined,
56 path: TalkResource.PATH.replace("{call_uuid}", callId)
57 });
58
59 expect(httpClientStub.request).to.have.been.calledWith(
60 sinon.match(expectedRequestArgs),
61 emptyCallback
62 );
63 });
64});