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