1 | import chai, { expect } from "chai";
|
2 |
|
3 | import path from "path";
|
4 | import sinon from "sinon";
|
5 | import sinonChai from "sinon-chai";
|
6 |
|
7 | import ResourceTestHelper from "./ResourceTestHelper";
|
8 |
|
9 | import TalkResource from "../lib/TalkResource";
|
10 | import HttpClient from "../lib/HttpClient";
|
11 | import Credentials from "../lib/Credentials";
|
12 |
|
13 | chai.use(sinonChai);
|
14 | var creds = Credentials.parse({
|
15 | applicationId: "some-id",
|
16 | privateKey: path.join(__dirname, "private-test.key")
|
17 | });
|
18 | var emptyCallback = () => {};
|
19 |
|
20 | describe("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 | headers: {
|
43 | "Content-Type": "application/json",
|
44 | "Content-Length": 17
|
45 | }
|
46 | });
|
47 | expect(httpClientStub.request).to.have.been.calledWith(
|
48 | sinon.match(expectedRequestArgs),
|
49 | emptyCallback
|
50 | );
|
51 | });
|
52 |
|
53 | it("should be able to start a talk with unicode characters", () => {
|
54 | const callId = "2342342-lkjhlkjh-32423";
|
55 | var params = {
|
56 | text: "Alô 😊!"
|
57 | };
|
58 | talk.start(callId, params, emptyCallback);
|
59 |
|
60 | var expectedRequestArgs = ResourceTestHelper.requestArgsMatch(params, {
|
61 | path: TalkResource.PATH.replace("{call_uuid}", callId),
|
62 | method: "PUT",
|
63 | headers: {
|
64 | "Content-Type": "application/json",
|
65 | "Content-Length": 21
|
66 | }
|
67 | });
|
68 | expect(httpClientStub.request).to.have.been.calledWith(
|
69 | sinon.match(expectedRequestArgs),
|
70 | emptyCallback
|
71 | );
|
72 | });
|
73 |
|
74 | it("should be possible to stop an ongoing talk", () => {
|
75 | const callId = "2342342-lkjhlkjh-32423";
|
76 | talk.stop(callId, emptyCallback);
|
77 |
|
78 | var expectedRequestArgs = ResourceTestHelper.requestArgsMatch(null, {
|
79 | method: "DELETE",
|
80 | body: undefined,
|
81 | path: TalkResource.PATH.replace("{call_uuid}", callId)
|
82 | });
|
83 |
|
84 | expect(httpClientStub.request).to.have.been.calledWith(
|
85 | sinon.match(expectedRequestArgs),
|
86 | emptyCallback
|
87 | );
|
88 | });
|
89 | });
|