Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fixed double key in shipping_address and billing_address - Add throw in several credentials function - Update unit test
- Loading branch information
Showing
9 changed files
with
304 additions
and
40 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
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
This file was deleted.
Oops, something went wrong.
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,34 @@ | ||
var assert = require('assert'); | ||
var Base64 = require('../src/base64.js'); | ||
var MidTrans = require('../src/midtrans.js'); | ||
|
||
var config = { | ||
client_key: "xxx", //don't change this | ||
server_key: "xxx", //don't change this | ||
mode: "" | ||
}; | ||
|
||
describe('Base64 String test', function(){ | ||
var base64 = new Base64(); | ||
it('encode',function(){ | ||
var result = base64.encode('abcdefghijklmnopqrstuvwxyz'); | ||
assert.equal(result,'YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXo='); | ||
}); | ||
|
||
it('decode',function(){ | ||
var result = base64.decode('YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXo='); | ||
assert.equal(result,'abcdefghijklmnopqrstuvwxyz'); | ||
}); | ||
|
||
it('decode format buffer will return buffer',function(){ | ||
var base64 = new Base64('buffer'); | ||
var result = base64.decode('YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXo='); | ||
assert.equal(true,Buffer.isBuffer(result)); | ||
}); | ||
|
||
it('base64 authorization', function(){ | ||
var mdt = new MidTrans(config); | ||
assert.equal(mdt.encode(mdt.server_key+':'),'eHh4Og=='); | ||
}); | ||
|
||
}); |
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
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,69 @@ | ||
var assert = require('assert'); | ||
var MidTrans = require('../src/midtrans.js'); | ||
|
||
var config = { | ||
client_key: "xxx", //don't change this | ||
server_key: "xxx", //don't change this | ||
mode: "" | ||
}; | ||
|
||
describe('MidTrans configuration test', function(){ | ||
|
||
it('configuration must be object type',function(){ | ||
var result = false; | ||
for(var key in config) { | ||
if(config.hasOwnProperty(key)) { | ||
result = true; | ||
} | ||
} | ||
assert.equal(result, true); | ||
}); | ||
|
||
it('configuration must be hasOwnProperty',function(){ | ||
const config = Object.create({name: 'inherited'}) | ||
var mdt = new MidTrans(config); | ||
assert.equal(mdt.server_key,undefined); | ||
assert.equal(mdt.client_key,undefined); | ||
assert.equal(mdt.mode,'sandbox'); | ||
}); | ||
|
||
it('configuration with array object will throw an error',function(){ | ||
assert.throws(function(){new MidTrans([])},Error,'Error thrown'); | ||
}); | ||
|
||
it('configuration with string object will throw an error',function(){ | ||
assert.throws(function(){new MidTrans("")},Error,'Error thrown'); | ||
}); | ||
|
||
it('configuration undefined will throw an error',function(){ | ||
assert.throws(function(){new MidTrans(undefined)},Error,'Error thrown'); | ||
}); | ||
|
||
it('configuration null will throw an error',function(){ | ||
assert.throws(function(){new MidTrans(null)},Error,'Error thrown'); | ||
}); | ||
|
||
it('complete configuration',function(){ | ||
var mdt = new MidTrans(config); | ||
assert.equal(mdt.client_key,'xxx'); | ||
assert.equal(mdt.server_key,'xxx'); | ||
assert.equal(mdt.mode,'sandbox'); | ||
}); | ||
|
||
it('configuration without mode then mode value will be as \'sandbox\'',function(){ | ||
delete config.mode; | ||
var mdt = new MidTrans(config); | ||
assert.equal(mdt.client_key,'xxx'); | ||
assert.equal(mdt.server_key,'xxx'); | ||
assert.equal(mdt.mode,'sandbox'); | ||
}); | ||
|
||
it('configuration for production',function(){ | ||
config.mode = 'production'; | ||
var mdt = new MidTrans(config); | ||
assert.equal(mdt.client_key,'xxx'); | ||
assert.equal(mdt.server_key,'xxx'); | ||
assert.equal(mdt.mode,'production'); | ||
}); | ||
|
||
}); |
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
Oops, something went wrong.