|
| 1 | +var lib = require("../"); |
| 2 | +var helper = require("./helper"); |
| 3 | +var nock = require("nock"); |
| 4 | +var CsrOrder = lib.CsrOrder; |
| 5 | + |
| 6 | +describe("Csr", function(){ |
| 7 | + before(function(){ |
| 8 | + nock.disableNetConnect(); |
| 9 | + helper.setupGlobalOptions(); |
| 10 | + }); |
| 11 | + after(function(){ |
| 12 | + nock.cleanAll(); |
| 13 | + nock.enableNetConnect(); |
| 14 | + }); |
| 15 | + // Coming Soon |
| 16 | + // describe("#list", function(){ |
| 17 | + // it("should return a list of Csrs ", function(done){ |
| 18 | + // helper.nock().get("/accounts/FakeAccountId/csrs").reply(200, helper.xml.csrOrders, {"Content-Type":"application/xml"}); |
| 19 | + // CsrOrder.list(helper.createClient(), {}, function(err,list){ |
| 20 | + // if(err){ |
| 21 | + // return done(err); |
| 22 | + // } |
| 23 | + // list.should.be.ok; |
| 24 | + // done(); |
| 25 | + // }); |
| 26 | + // }); |
| 27 | + // }); |
| 28 | + describe("#get", function(){ |
| 29 | + it("should get Csr successfully", function(done){ |
| 30 | + helper.nock().get("/accounts/FakeAccountId/csrs/1").reply(200, helper.xml.csrOrder, {"Content-Type": "application/xml"}); |
| 31 | + CsrOrder.get(helper.createClient(), "1", function(err, csrOrder){ |
| 32 | + if(err){ |
| 33 | + return done(err); |
| 34 | + } |
| 35 | + csrOrder.should.be.ok; |
| 36 | + csrOrder.csrData.serviceAddress.unparsedAddress.should.eql("1234 Main ST Durham NC 27707"); |
| 37 | + csrOrder.csrData.workingTelephoneNumber.should.eql("9198675309"); |
| 38 | + done(); |
| 39 | + }); |
| 40 | + }); |
| 41 | + }); |
| 42 | + describe("#create", function(){ |
| 43 | + it("should create Csr successfully", function(done){ |
| 44 | + var data = { |
| 45 | + customerOrderId: "MyId5", |
| 46 | + WorkingOrBillingTelephoneNumber:"9198675309", |
| 47 | + accountNumber:"123463", |
| 48 | + endUserPIN:"1231" |
| 49 | + }; |
| 50 | + helper.nock().post("/accounts/FakeAccountId/csrs", helper.buildXml({Csr: data})).reply(201, helper.xml.csrResponse, {"Location": "/accounts/FakeAccountId/csrs/1"}); |
| 51 | + CsrOrder.create(helper.createClient(), data, function(err, csrOrder){ |
| 52 | + if(err){ |
| 53 | + return done(err); |
| 54 | + } |
| 55 | + csrOrder.should.be.ok; |
| 56 | + csrOrder.orderId.should.eql("218a295f-4f8a-4d1a-ba55-3e0aac6207cb"); |
| 57 | + done(); |
| 58 | + }); |
| 59 | + }); |
| 60 | + }); |
| 61 | + describe("#update", function(){ |
| 62 | + it("should update successfully", function(done){ |
| 63 | + var data = {endUserPIN:"1234"}; |
| 64 | + helper.nock().put("/accounts/FakeAccountId/csrs/1", helper.buildXml({Csr: data})).reply(200); |
| 65 | + var order = new CsrOrder(); |
| 66 | + order.id = "1"; |
| 67 | + order.client = helper.createClient(); |
| 68 | + order.endUserPIN = "1234"; |
| 69 | + order.update(data,done); |
| 70 | + }) |
| 71 | + }); |
| 72 | + describe("#getNotes", function(){ |
| 73 | + it("should return notes", function(done){ |
| 74 | + helper.nock().get("/accounts/FakeAccountId/csrs/1/notes").reply(200, helper.xml.notes, {"Content-Type": "application/xml"}); |
| 75 | + var order = new CsrOrder(); |
| 76 | + order.id = 1; |
| 77 | + order.client = helper.createClient(); |
| 78 | + order.getNotes(function(err, notes){ |
| 79 | + if(err){ |
| 80 | + return done(err); |
| 81 | + } |
| 82 | + notes.length.should.equal(2); |
| 83 | + notes[0].id.should.equal(11299); |
| 84 | + notes[0].userId.should.equal("customer"); |
| 85 | + notes[0].description.should.equal("Test"); |
| 86 | + done(); |
| 87 | + }); |
| 88 | + }); |
| 89 | + it("should fail for error status code", function(done){ |
| 90 | + helper.nock().get("/accounts/FakeAccountId/orders/1/notes").reply(400); |
| 91 | + var order = new CsrOrder(); |
| 92 | + order.id = 1; |
| 93 | + order.client = helper.createClient(); |
| 94 | + order.getNotes(function(err, notes){ |
| 95 | + if(err){ |
| 96 | + return done(); |
| 97 | + } |
| 98 | + done(new Error("An error is estimated")); |
| 99 | + }); |
| 100 | + }); |
| 101 | + }); |
| 102 | + describe("#addNote", function(){ |
| 103 | + it("should add new note", function(done){ |
| 104 | + var data = {userId: "customer", description: "Test"}; |
| 105 | + helper.nock().post("/accounts/FakeAccountId/csrs/1/notes", helper.buildXml({note: data})).reply(200, "", {"Location": "/accounts/FakeAccountId/csrs/1/notes/11299"}); |
| 106 | + helper.nock().get("/accounts/FakeAccountId/csrs/1/notes").reply(200, helper.xml.notes, {"Content-Type": "application/xml"}); |
| 107 | + var order = new CsrOrder(); |
| 108 | + order.id = 1; |
| 109 | + order.client = helper.createClient(); |
| 110 | + order.addNote(data, function(err, note){ |
| 111 | + if(err){ |
| 112 | + return done(err); |
| 113 | + } |
| 114 | + note.id.should.equal(11299); |
| 115 | + note.userId.should.equal("customer"); |
| 116 | + note.description.should.equal("Test"); |
| 117 | + done(); |
| 118 | + }); |
| 119 | + }); |
| 120 | + }); |
| 121 | +}); |
0 commit comments