1 | import Media from "../lib/Media";
|
2 | import { expect, sinon, TestUtils } from "./NexmoTestUtils";
|
3 |
|
4 | describe("Media", function() {
|
5 | beforeEach(function() {
|
6 | this.httpClientStub = TestUtils.getHttpClient();
|
7 | sinon.stub(this.httpClientStub, "request");
|
8 | sinon.stub(this.httpClientStub.requestLib, "post");
|
9 | this.media = new Media(TestUtils.getCredentials(), {
|
10 | api: this.httpClientStub
|
11 | });
|
12 | });
|
13 |
|
14 | afterEach(function() {
|
15 | this.httpClientStub.request.restore();
|
16 | this.httpClientStub.requestLib.post.restore();
|
17 | });
|
18 |
|
19 | describe("#search", function() {
|
20 | it("should default to no parameters", function() {
|
21 | return expect(this.media)
|
22 | .method("search")
|
23 | .to.get.url(Media.PATH);
|
24 | });
|
25 |
|
26 | it("should pass through supplied parameters", function() {
|
27 | return expect(this.media)
|
28 | .method("search")
|
29 | .withParams({ order: "ascending", page_size: 11 })
|
30 | .to.get.url(`${Media.PATH}?order=ascending&page_size=11`);
|
31 | });
|
32 | });
|
33 |
|
34 | describe("#download", function() {
|
35 | it("should call the correct URL", function() {
|
36 | return expect(this.media)
|
37 | .method("download")
|
38 | .withParams("ABC123")
|
39 | .to.get.url(`${Media.PATH}/ABC123`);
|
40 | });
|
41 | });
|
42 |
|
43 | describe("#get", function() {
|
44 | it("should call the correct URL", function() {
|
45 | return expect(this.media)
|
46 | .method("get")
|
47 | .withParams("ABC123")
|
48 | .to.get.url(`${Media.PATH}/ABC123/info`);
|
49 | });
|
50 | });
|
51 |
|
52 | describe("#delete", function() {
|
53 | it("should call the correct URL", function() {
|
54 | return expect(this.media)
|
55 | .method("delete")
|
56 | .withParams("ABC123")
|
57 | .to.delete.url(`${Media.PATH}/ABC123`);
|
58 | });
|
59 | });
|
60 |
|
61 | describe("#upload", function() {
|
62 |
|
63 |
|
64 | it("should call the correct URL (file provided)", function() {
|
65 | return expect(this.media)
|
66 | .method("upload")
|
67 | .withParams({ file: "/dev/null" })
|
68 | .to.postFile.to.url("/v3/media");
|
69 | });
|
70 |
|
71 | it("should call the correct URL (url provided)", function() {
|
72 | return expect(this.media)
|
73 | .method("upload")
|
74 | .withParams({ url: "http://example.com" })
|
75 | .to.postFile.to.url("/v3/media");
|
76 | });
|
77 | });
|
78 |
|
79 | describe("#update", function() {
|
80 | it("should call the correct URL", function() {
|
81 | return expect(this.media)
|
82 | .method("update")
|
83 | .withParams("ABC123", { public_item: true })
|
84 | .to.put.to.url("/v3/media/ABC123/info");
|
85 | });
|
86 | });
|
87 | });
|