forked from eversign/eversign-node-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Tests for Datefield, Checkbox and Documents
- Loading branch information
1 parent
ad495bc
commit fbf8acc
Showing
3 changed files
with
305 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
'use strict'; | ||
|
||
var chai = require('chai'); | ||
var Promise = require('bluebird'); | ||
var should = chai.should(); | ||
var expect = chai.expect; | ||
var Client = require('../lib/Client'); | ||
var File = require('../lib/File'); | ||
var Signer = require('../lib/Signer'); | ||
var Document = require('../lib/Document'); | ||
var CheckboxField = require('../lib/CheckboxField'); | ||
var path = require('path'); | ||
|
||
var hash = "MYHASH"; | ||
var businessId = 1234; | ||
|
||
|
||
describe("CheckboxField", function () { | ||
|
||
it('should get added to a Document without a problem', function(done){ | ||
|
||
var document = new Document(); | ||
document.setDocumentHash("My Document"); | ||
document.setTitle("Tile goes here"); | ||
document.setRequesterEmail("[email protected]"); | ||
document.setIsDraft(false); | ||
|
||
var file = new File({ | ||
name: 'My File', | ||
filePath: path.join(__dirname, 'raw.pdf'), | ||
}); | ||
document.appendFile(file); | ||
|
||
var checkbox = new CheckboxField(); | ||
checkbox.setName("Checkbox 1"); | ||
checkbox.setValue("1"); | ||
checkbox.setX(30); | ||
checkbox.setY(30); | ||
checkbox.setPage(1); | ||
checkbox.setSigner("1"); | ||
document.appendFormField(checkbox); | ||
|
||
expect(document.toObject()).to.have.property('fields').and.have.length(1); // Success | ||
done(); | ||
}); | ||
|
||
it('should fail without a File', function(done){ | ||
|
||
var document = new Document(); | ||
document.setDocumentHash("My Document"); | ||
document.setTitle("Title goes here"); | ||
document.setRequesterEmail("[email protected]"); | ||
document.setIsDraft(false); | ||
|
||
var checkbox = new CheckboxField(); | ||
checkbox.setName("Checkbox 1"); | ||
checkbox.setValue("1"); | ||
checkbox.setX(30); | ||
checkbox.setY(30); | ||
|
||
expect(function () { document.appendFormField(checkbox); }).to.throw(); | ||
done(); | ||
}); | ||
|
||
it('should fail without setting all required fields', function(done){ | ||
|
||
var document = new Document(); | ||
document.setDocumentHash("My Document"); | ||
document.setTitle("Title goes here"); | ||
document.setRequesterEmail("[email protected]"); | ||
document.setIsDraft(false); | ||
|
||
var file = new File({ | ||
name: 'My File', | ||
filePath: path.join(__dirname, 'raw.pdf'), | ||
}); | ||
document.appendFile(file); | ||
|
||
var checkbox = new CheckboxField(); | ||
checkbox.setName("Checkbox 1"); | ||
checkbox.setValue("1"); | ||
|
||
expect(function () { document.appendFormField(checkbox); }).to.throw(); | ||
done(); | ||
}); | ||
|
||
it('should get uploaded without an error', function(done){ | ||
this.timeout(10000); | ||
|
||
var document = new Document(); | ||
document.setDocumentHash("My Document"); | ||
document.setTitle("Title goes here"); | ||
document.setRequesterEmail("[email protected]"); | ||
document.setIsDraft(true); | ||
|
||
var signer = new Signer(); | ||
signer.setName('Tester Test'); | ||
signer.setEmail('[email protected]') | ||
document.appendSigner(signer); | ||
|
||
var file = new File({ | ||
name: 'My File', | ||
filePath: path.join(__dirname, 'raw.pdf'), | ||
}); | ||
document.appendFile(file); | ||
|
||
var checkbox = new CheckboxField(); | ||
checkbox.setName("Checkbox 1"); | ||
checkbox.setValue("1"); | ||
checkbox.setX(30); | ||
checkbox.setY(30); | ||
|
||
var client = new Client(hash, businessId); | ||
|
||
client.createDocument(document).then(function(doc) { | ||
expect( doc.toObject() ).to.be.an.instanceof(Document); | ||
done(); | ||
}) | ||
.catch(function(err) { | ||
done(error) | ||
}); | ||
|
||
}); | ||
|
||
|
||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
'use strict'; | ||
|
||
var chai = require('chai'); | ||
var Promise = require('bluebird'); | ||
var should = chai.should(); | ||
var expect = chai.expect; | ||
var Client = require('../lib/Client'); | ||
var File = require('../lib/File'); | ||
var Signer = require('../lib/Signer'); | ||
var Document = require('../lib/Document'); | ||
var DateSignedField = require('../lib/DateSignedField'); | ||
var path = require('path'); | ||
|
||
var hash = "MYHASH"; | ||
var businessId = 1234; | ||
|
||
|
||
describe("DateSignedField", function () { | ||
|
||
it('should get added to a Document without a problem', function(done){ | ||
|
||
var document = new Document(); | ||
document.setDocumentHash("My Document"); | ||
document.setTitle("Tile goes here"); | ||
document.setRequesterEmail("[email protected]"); | ||
document.setIsDraft(false); | ||
|
||
var file = new File({ | ||
name: 'My File', | ||
filePath: path.join(__dirname, 'raw.pdf'), | ||
}); | ||
document.appendFile(file); | ||
|
||
var datefield = new DateSignedField(); | ||
datefield.setIdentifier("date_sign_1"); | ||
datefield.setX(30); | ||
datefield.setY(30); | ||
datefield.setTextStyle("BUI"); | ||
datefield.setTextSize(20); | ||
datefield.setWidth(200); | ||
datefield.setHeight(50); | ||
datefield.setTextColor("#FFBB00"); | ||
datefield.setPage(1); | ||
datefield.setSigner("1"); | ||
document.appendFormField(datefield); | ||
|
||
expect(document.toObject()).to.have.property('fields').and.have.length(1); // Success | ||
done(); | ||
}); | ||
|
||
|
||
it('should fail without setting all required fields', function(done){ | ||
|
||
var document = new Document(); | ||
document.setDocumentHash("My Document"); | ||
document.setTitle("Title goes here"); | ||
document.setRequesterEmail("[email protected]"); | ||
document.setIsDraft(false); | ||
|
||
var file = new File({ | ||
name: 'My File', | ||
filePath: path.join(__dirname, 'raw.pdf'), | ||
}); | ||
document.appendFile(file); | ||
|
||
var datefield = new DateSignedField(); | ||
datefield.setIdentifier("date_sign_1"); | ||
datefield.setPage(1); | ||
datefield.setSigner("1"); | ||
|
||
expect(function () { document.appendFormField(datefield); }).to.throw(); | ||
done(); | ||
}); | ||
|
||
|
||
it('should get uploaded without an error', function(done){ | ||
this.timeout(10000); | ||
|
||
var document = new Document(); | ||
document.setDocumentHash("My Document"); | ||
document.setTitle("Title goes here"); | ||
document.setRequesterEmail("[email protected]"); | ||
document.setIsDraft(true); | ||
|
||
var signer = new Signer(); | ||
signer.setName('Tester Test'); | ||
signer.setEmail('[email protected]') | ||
document.appendSigner(signer); | ||
|
||
var file = new File({ | ||
name: 'My File', | ||
filePath: path.join(__dirname, 'raw.pdf'), | ||
}); | ||
document.appendFile(file); | ||
|
||
var datefield = new DateSignedField(); | ||
datefield.setX(30); | ||
datefield.setY(30); | ||
datefield.setTextStyle("BUI"); | ||
datefield.setTextSize(20); | ||
datefield.setWidth(200); | ||
datefield.setHeight(50); | ||
datefield.setTextColor("#FFBB00"); | ||
datefield.setPage(1); | ||
datefield.setSigner("1"); | ||
document.appendFormField(datefield); | ||
|
||
var client = new Client(hash, businessId); | ||
|
||
client.createDocument(document).then(function(doc) { | ||
expect( doc.toObject() ).to.be.an.instanceof(Document); | ||
done(); | ||
}) | ||
.catch(function(err) { | ||
done(error) | ||
}); | ||
|
||
}); | ||
|
||
|
||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,35 +4,48 @@ var chai = require('chai'); | |
var Promise = require('bluebird'); | ||
var should = chai.should(); | ||
var expect = chai.expect; | ||
var Client = require('../index'); | ||
var Client = require('../lib/Client'); | ||
var Recipient = require('../lib/Recipient'); | ||
var File = require('../lib/File'); | ||
var Signer = require('../lib/Signer'); | ||
var Document = require('../lib/Document'); | ||
var path = require('path'); | ||
|
||
var hash = "MYHASH"; | ||
var businessId = 1234; | ||
|
||
|
||
describe("Client.getAllDocuments", function () { | ||
|
||
this.timeout(5000); | ||
|
||
it('should give an array of documents', function(done){ | ||
var client = new Client("MY_HASH", 1234567); | ||
client.getAllDocuments().then(function (data) { | ||
data.should.be.an('array'); | ||
|
||
var client = new Client(hash, businessId); | ||
|
||
client.getAllDocuments().then(function (documents) { | ||
documents.should.be.an('array'); | ||
done(); | ||
}).catch(function (error) { | ||
done(error); | ||
}); | ||
|
||
}); | ||
|
||
it('should not resolve with wrong crerdentials', function(done){ | ||
var client = new Client("MY_HASH", 1234567); | ||
it('should not resolve with wrong credentials', function(done){ | ||
var client = new Client("wrongcredentialshere", 1234567); | ||
|
||
client.getAllDocuments().then(function (data) { | ||
done(data); | ||
done(); | ||
}).catch(function (error) { | ||
error.should.not.be.a('null'); | ||
error.should.have.property("code", 101); | ||
done(); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
|
||
describe('Recipient.toObject()' , function functionName() { | ||
|
||
it("should return an instance of Recipient with property 'name' having value 'Tester Test'", function () { | ||
|
@@ -48,14 +61,14 @@ describe('Recipient.toObject()' , function functionName() { | |
|
||
describe('Signer.toObject()' , function functionName() { | ||
|
||
it("should return an instance of Signer with property 'pin' having value '1231'", function () { | ||
it("should return an instance of Signer with property 'pin' having value '1234'", function () { | ||
var signer = new Signer(); | ||
signer.setId(1); | ||
signer.setOrder(2); | ||
signer.setPin("1231"); | ||
signer.setPin("1234"); | ||
signer.setSigned(false); | ||
expect( signer.toObject() ).to.be.an.instanceof(Signer) | ||
.and.to.have.property("pin", "1231"); | ||
.and.to.have.property("pin", "1234"); | ||
}); | ||
|
||
}); | ||
|
@@ -65,7 +78,7 @@ describe('Document' , function functionName() { | |
it("should get created without a problem", function () { | ||
var document = new Document(); | ||
document.setDocumentHash("My Document"); | ||
document.setTitle("Tile goes here"); | ||
document.setTitle("Title goes here"); | ||
document.setRequesterEmail("[email protected]"); | ||
document.setIsDraft(false); | ||
|
||
|
@@ -80,15 +93,43 @@ describe('Document' , function functionName() { | |
signer.setEmail('[email protected]') | ||
document.appendSigner(signer.toObject()); | ||
|
||
var client = new Client("MY_HASH", 1234567); | ||
var client = new Client(hash, businessId); | ||
client.createDocument(document) | ||
.then(function (response) { | ||
done(); | ||
expect( document.toObject() ).to.be.an.instanceof(Document); | ||
}) | ||
.catch(function (error) { | ||
done(error) | ||
}); | ||
|
||
}); | ||
|
||
it("should upload a file without a problem", function () { | ||
var document = new Document(); | ||
document.setDocumentHash("My Document"); | ||
document.setTitle("Title goes here"); | ||
document.setRequesterEmail("[email protected]"); | ||
document.setIsDraft(false); | ||
|
||
var signer = new Signer(); | ||
signer.setName('Tester Test'); | ||
signer.setEmail('[email protected]') | ||
document.appendSigner(signer.toObject()); | ||
|
||
var file = new File({ | ||
name: 'My File', | ||
filePath: path.join(__dirname, 'raw.pdf'), | ||
}); | ||
document.appendFile(file); | ||
|
||
var client = new Client(hash, businessId); | ||
client.createDocument(document) | ||
.then(function (response) { | ||
expect( document.toObject() ).to.be.an.instanceof(Document); | ||
expect( document.toObject().files ).to.be.an('array') | ||
}) | ||
.catch(function (error) { | ||
done(error) | ||
}); | ||
}); | ||
|
||
}); |