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 | });
|
11 | });
|
12 |
|
13 | describe("checkBalance", function() {
|
14 | it("should call the correct endpoint", function() {
|
15 | return expect(this.account)
|
16 | .method("checkBalance")
|
17 | .to.get.url("/account/get-balance");
|
18 | });
|
19 | });
|
20 |
|
21 | describe("updatePassword", function() {
|
22 | it("should call the correct endpoint", function() {
|
23 | return expect(this.account)
|
24 | .method("updatePassword")
|
25 | .withParams("example_password")
|
26 | .to.post.to.url("/account/settings?newSecret=example_password");
|
27 | });
|
28 | });
|
29 |
|
30 | describe("updateSMSCallback", function() {
|
31 | it("should call the correct endpoint", function() {
|
32 | return expect(this.account)
|
33 | .method("updateSMSCallback")
|
34 | .withParams("http://example.com/sms_callback")
|
35 | .to.post.to.url(
|
36 | "/account/settings?moCallBackUrl=http%3A%2F%2Fexample.com%2Fsms_callback"
|
37 | );
|
38 | });
|
39 | });
|
40 |
|
41 | describe("updateDeliveryReceiptCallback", function() {
|
42 | it("should call the correct endpoint", function() {
|
43 | return expect(this.account)
|
44 | .method("updateDeliveryReceiptCallback")
|
45 | .withParams("http://example.com/dr_callback")
|
46 | .to.post.to.url(
|
47 | "/account/settings?drCallBackUrl=http%3A%2F%2Fexample.com%2Fdr_callback"
|
48 | );
|
49 | });
|
50 | });
|
51 |
|
52 | describe("topUp", function() {
|
53 | it("should call the correct endpoint", function() {
|
54 | return expect(this.account)
|
55 | .method("topUp")
|
56 | .withParams("ABC123")
|
57 | .to.post.to.url("/account/top-up?trx=ABC123");
|
58 | });
|
59 |
|
60 | it("returns data on a successful request", function(done) {
|
61 | const mockData = {
|
62 |
|
63 |
|
64 | success: true
|
65 | };
|
66 |
|
67 | this.httpClientStub.request.yields(null, mockData);
|
68 | this.account.topUp("trx-123", (err, data) => {
|
69 | expect(err).to.eql(null);
|
70 | expect(data).to.eql(mockData);
|
71 | done();
|
72 | });
|
73 | });
|
74 |
|
75 | it("returns an error on a failed request", function(done) {
|
76 | const mockData = {
|
77 |
|
78 |
|
79 | success: false
|
80 | };
|
81 |
|
82 | this.httpClientStub.request.yields(mockData, null);
|
83 | this.account.topUp("trx-123", (err, data) => {
|
84 | expect(err).to.eql(mockData);
|
85 | expect(data).to.eql(null);
|
86 | done();
|
87 | });
|
88 | });
|
89 | });
|
90 | });
|