1 | import Account from "../lib/Account";
|
2 | import { expect, sinon, TestUtils } from "./NexmoTestUtils";
|
3 |
|
4 | describe("Account", function() {
|
5 | beforeEach(function() {
|
6 | this.httpClientStub = TestUtils.getHttpClient();
|
7 | sinon.stub(this.httpClientStub, "request");
|
8 | this.account = new Account(TestUtils.getCredentials(), {
|
9 | rest: this.httpClientStub,
|
10 | api: this.httpClientStub
|
11 | });
|
12 | });
|
13 |
|
14 | describe("checkBalance", function() {
|
15 | it("should call the correct endpoint", function() {
|
16 | return expect(this.account)
|
17 | .method("checkBalance")
|
18 | .to.get.url("/account/get-balance");
|
19 | });
|
20 | });
|
21 |
|
22 | describe("updatePassword", function() {
|
23 | it("should call the correct endpoint", function() {
|
24 | return expect(this.account)
|
25 | .method("updatePassword")
|
26 | .withParams("example_password")
|
27 | .to.post.to.url("/account/settings?newSecret=example_password");
|
28 | });
|
29 | });
|
30 |
|
31 | describe("updateSMSCallback", function() {
|
32 | it("should call the correct endpoint", function() {
|
33 | return expect(this.account)
|
34 | .method("updateSMSCallback")
|
35 | .withParams("http://example.com/sms_callback")
|
36 | .to.post.to.url(
|
37 | "/account/settings?moCallBackUrl=http%3A%2F%2Fexample.com%2Fsms_callback"
|
38 | );
|
39 | });
|
40 | });
|
41 |
|
42 | describe("updateDeliveryReceiptCallback", function() {
|
43 | it("should call the correct endpoint", function() {
|
44 | return expect(this.account)
|
45 | .method("updateDeliveryReceiptCallback")
|
46 | .withParams("http://example.com/dr_callback")
|
47 | .to.post.to.url(
|
48 | "/account/settings?drCallBackUrl=http%3A%2F%2Fexample.com%2Fdr_callback"
|
49 | );
|
50 | });
|
51 | });
|
52 |
|
53 | describe("topUp", function() {
|
54 | it("should call the correct endpoint", function() {
|
55 | return expect(this.account)
|
56 | .method("topUp")
|
57 | .withParams("ABC123")
|
58 | .to.post.to.url("/account/top-up?trx=ABC123");
|
59 | });
|
60 |
|
61 | it("returns data on a successful request", function(done) {
|
62 | const mockData = {
|
63 |
|
64 |
|
65 | success: true
|
66 | };
|
67 |
|
68 | this.httpClientStub.request.yields(null, mockData);
|
69 | this.account.topUp("trx-123", (err, data) => {
|
70 | expect(err).to.eql(null);
|
71 | expect(data).to.eql(mockData);
|
72 | done();
|
73 | });
|
74 | });
|
75 |
|
76 | it("returns an error on a failed request", function(done) {
|
77 | const mockData = {
|
78 |
|
79 |
|
80 | success: false
|
81 | };
|
82 |
|
83 | this.httpClientStub.request.yields(mockData, null);
|
84 | this.account.topUp("trx-123", (err, data) => {
|
85 | expect(err).to.eql(mockData);
|
86 | expect(data).to.eql(null);
|
87 | done();
|
88 | });
|
89 | });
|
90 | });
|
91 |
|
92 | describe("listSecrets", function() {
|
93 | it("should call the correct endpoint", function() {
|
94 | return expect(this.account)
|
95 | .method("listSecrets")
|
96 | .withParams("ABC123")
|
97 | .to.get.url("/accounts/ABC123/secrets");
|
98 | });
|
99 | });
|
100 |
|
101 | describe("getSecret", function() {
|
102 | it("should call the correct endpoint", function() {
|
103 | return expect(this.account)
|
104 | .method("getSecret")
|
105 | .withParams("ABC123", "123")
|
106 | .to.get.url("/accounts/ABC123/secrets/123");
|
107 | });
|
108 | });
|
109 |
|
110 | describe("createSecret", function() {
|
111 | it("should call the correct endpoint", function() {
|
112 | return expect(this.account)
|
113 | .method("createSecret")
|
114 | .withParams("ABC123", "123")
|
115 | .to.post.withJsonBody({ secret: "123" })
|
116 | .to.url("/accounts/ABC123/secrets/");
|
117 | });
|
118 | });
|
119 |
|
120 | describe("deleteSecret", function() {
|
121 | it("should call the correct endpoint", function() {
|
122 | return expect(this.account)
|
123 | .method("deleteSecret")
|
124 | .withParams("ABC123", "123")
|
125 | .to.delete.url("/accounts/ABC123/secrets/123");
|
126 | });
|
127 | });
|
128 | });
|