1 | "use strict";
|
2 |
|
3 | var chai = require("chai");
|
4 | var assert = chai.assert;
|
5 | var should = chai.should();
|
6 | var expect = chai.expect;
|
7 | var Bex = require("../lib/bkmexpress");
|
8 | var fs = require("fs");
|
9 |
|
10 | describe("BKM Express SDK version 2", function () {
|
11 | var merchantSecretKey = fs.readFileSync("./test/" + process.env.merchantSecretKey).toString();
|
12 | var environment = Bex.Environment[process.env.environment];
|
13 | var merchantId = process.env.merchantId;
|
14 | var testString = "This is test string";
|
15 | var privateKey = fs.readFileSync("./test/privatePKCS8.pem").toString();
|
16 | var publicKey = fs.readFileSync("./test/public.pem").toString();
|
17 | var config;
|
18 | var token;
|
19 |
|
20 | describe("pre-requisites", function () {
|
21 | it("merchantSecretKey", function () {
|
22 | merchantSecretKey.should.be.a("string");
|
23 | });
|
24 | it("environment", function () {
|
25 | environment.should.be.equal(Bex.Environment.DEV);
|
26 | });
|
27 | it("merchantId", function () {
|
28 | merchantId.should.be.a("string").with.lengthOf(36);
|
29 | });
|
30 | it("BKM sdk version", function () {
|
31 | Bex.version.should.be.a("string");
|
32 | });
|
33 | });
|
34 |
|
35 | describe("Utilities", function () {
|
36 | var sample = [
|
37 | {k: 10004.788, v: "10004,79"},
|
38 | {k: 1000.78, v: "1000,78"},
|
39 | {k: 1000.7, v: "1000,70"},
|
40 | {k: 54.768, v: "54,77"},
|
41 | {k: 23.78, v: "23,78"},
|
42 | {k: 23.3, v: "23,30"},
|
43 | {k: 32, v: "32,00"},
|
44 | {k: 1, v: "1,00"},
|
45 | ];
|
46 | it("Float to TRY", function () {
|
47 | for (var i = 0; i < sample.length; i++) {
|
48 | var test = sample[i];
|
49 | Bex.MoneyUtils.toTRY(test.k).should.be.an.equal(test.v);
|
50 | }
|
51 | });
|
52 | it("TRY to Float", function () {
|
53 | for (var i = 0; i < sample.length; i++) {
|
54 | var test = sample[i];
|
55 | Bex.MoneyUtils.toNumber(test.v).should.be.an.equal(Math.round(test.k * 100) / 100);
|
56 | }
|
57 | });
|
58 | });
|
59 |
|
60 | describe("Encryption Utilities", function () {
|
61 | it("Base64 encode decode", function () {
|
62 | var encoded = Bex.EncryptionUtil.encode64(testString);
|
63 | var decoded = Bex.EncryptionUtil.decode64(encoded);
|
64 | decoded.should.be.equal(testString);
|
65 | });
|
66 | it("Sign and verify with keys", function () {
|
67 | var signature = Bex.EncryptionUtil.sign(privateKey, testString);
|
68 | signature.should.be.a("string");
|
69 | var verify = Bex.EncryptionUtil.verify(publicKey, testString, signature);
|
70 | verify.should.be.a("boolean").with.equal(true);
|
71 | });
|
72 | it("Encrypt and decrypt with keys", function () {
|
73 | var encrypted = Bex.EncryptionUtil.encrypt(publicKey, testString);
|
74 | encrypted.should.be.a("string");
|
75 | var dencrypted = Bex.EncryptionUtil.decrypt(privateKey, encrypted, true);
|
76 | dencrypted.should.be.a("string").with.equal(testString);
|
77 | });
|
78 | });
|
79 |
|
80 | config = Bex.BexPayment.startBexPayment(Bex.Environment.DEV, merchantId, privateKey);
|
81 |
|
82 |
|
83 | describe("Bex Config", function () {
|
84 | it("BexPayment configuration unknown environment", function () {
|
85 | try {
|
86 | new Bex.BexPayment(null, merchantId, merchantSecretKey);
|
87 | }
|
88 | catch (err) {
|
89 | err.should.be.instanceof(Error);
|
90 | }
|
91 | });
|
92 | it("BexPayment instanceof Configuration", function () {
|
93 | config.should.be.instanceof(Bex.Configuration);
|
94 | config.Environment.should.be.equal(environment);
|
95 | });
|
96 | it("BexPayment Properties", function () {
|
97 | config.should.have.property("Environment");
|
98 | config.should.have.property("BexApiConfiguration");
|
99 | config.should.have.property("MerchantId");
|
100 | config.should.have.property("MerchantPrivateKey");
|
101 | });
|
102 | it("BexPayment.BexApiConfiguration", function () {
|
103 | config.BexApiConfiguration.should.have.property("BaseUrl");
|
104 | config.BexApiConfiguration.should.have.property("BaseJs");
|
105 | config.BexApiConfiguration.BaseUrl.should.be.a("string");
|
106 | config.BexApiConfiguration.BaseJs.should.be.a("string");
|
107 | });
|
108 | });
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 | });
|