1 | import chai, { expect } from "chai";
|
2 | import path from "path";
|
3 | import sinon from "sinon";
|
4 | import sinonChai from "sinon-chai";
|
5 |
|
6 | import ResourceTestHelper from "./ResourceTestHelper";
|
7 |
|
8 | import FilesResource from "../lib/FilesResource";
|
9 | import HttpClient from "../lib/HttpClient";
|
10 | import Credentials from "../lib/Credentials";
|
11 |
|
12 | chai.use(sinonChai);
|
13 |
|
14 | var creds = Credentials.parse({
|
15 | applicationId: "some-id",
|
16 | privateKey: path.join(__dirname, "private-test.key")
|
17 | });
|
18 | var emptyCallback = () => {};
|
19 |
|
20 | describe("FileResource", () => {
|
21 | var httpClientStub = null;
|
22 | var files = null;
|
23 |
|
24 | beforeEach(() => {
|
25 | httpClientStub = sinon.createStubInstance(HttpClient);
|
26 | var options = {
|
27 | httpClient: httpClientStub
|
28 | };
|
29 | files = new FilesResource(creds, options);
|
30 | });
|
31 |
|
32 | it("should get a single file using a file ID", () => {
|
33 | const fileId = "2342342-lkjhlkjh-32423";
|
34 | files.get(fileId, emptyCallback);
|
35 |
|
36 | var expectedRequestArgs = ResourceTestHelper.requestArgsMatch(null, {
|
37 | method: "GET",
|
38 | body: undefined,
|
39 | path: `${FilesResource.PATH}/${fileId}`,
|
40 | headers: {
|
41 | "Content-Type": "application/octet-stream",
|
42 | Authorization: "Bearer "
|
43 | }
|
44 | });
|
45 |
|
46 | expect(httpClientStub.request).to.have.been.calledWith(
|
47 | sinon.match(expectedRequestArgs),
|
48 | emptyCallback
|
49 | );
|
50 | });
|
51 |
|
52 | it("should get a single file using a file URL", () => {
|
53 | const fileId = "2342342-lkjhlkjh-32423";
|
54 | const fileUrl = `https://rest.nexmo.com/api/v1/files/${fileId}`;
|
55 | files.get(fileUrl, emptyCallback);
|
56 |
|
57 | var expectedRequestArgs = ResourceTestHelper.requestArgsMatch(null, {
|
58 | method: "GET",
|
59 | body: undefined,
|
60 | path: `${FilesResource.PATH}/${fileId}`,
|
61 | headers: {
|
62 | "Content-Type": "application/octet-stream",
|
63 | Authorization: "Bearer "
|
64 | }
|
65 | });
|
66 |
|
67 | expect(httpClientStub.request).to.have.been.calledWith(
|
68 | sinon.match(expectedRequestArgs),
|
69 | emptyCallback
|
70 | );
|
71 | });
|
72 | });
|