1 | const EdgeCDN = require('../src/edge/edgecdn')
|
2 | const expect = require('expect.js');
|
3 |
|
4 | describe('EdgeCDN Core', function () {
|
5 |
|
6 | describe('EdgeCDN input test', function () {
|
7 | it('should pass into "config"', function () {
|
8 | expect(function () {
|
9 | new EdgeCDN();
|
10 | }).to.throwException('must pass "config"');
|
11 | })
|
12 |
|
13 | it('should pass into "config.accessKeyId"', function () {
|
14 | expect(function () {
|
15 | new EdgeCDN({});
|
16 | }).to.throwException('must pass "config.accessKeyId"');
|
17 | })
|
18 |
|
19 | it('should pass into "config.accessKeySecret"', function () {
|
20 | expect(function () {
|
21 | new EdgeCDN({
|
22 | accessKeyId: 'accessKeyId'
|
23 | });
|
24 | }).to.throwException('must pass "config.accessKeySecret"');
|
25 | })
|
26 |
|
27 | it('should pass into "config.endpoint"', function () {
|
28 | expect(function () {
|
29 | new EdgeCDN({
|
30 | accessKeyId: 'accessKeyId',
|
31 | accessKeySecret: 'accessKeySecret'
|
32 | });
|
33 | }).to.throwException('must pass "config.endpoint"');
|
34 | })
|
35 |
|
36 | it('should pass into "config.domainName"', function () {
|
37 | expect(function () {
|
38 | new EdgeCDN({
|
39 | accessKeyId: 'accessKeyId',
|
40 | accessKeySecret: 'accessKeySecret',
|
41 | endpoint: 'http://www.test.com'
|
42 | });
|
43 | }).to.throwException('must pass "config.domainName"');
|
44 | })
|
45 |
|
46 | it('should ok new EdgeCDN', function () {
|
47 | const edgecdn = new EdgeCDN({
|
48 | accessKeyId: 'accessKeyId',
|
49 | accessKeySecret: 'accessKeySecret',
|
50 | endpoint: 'http://www.mochatest.com',
|
51 | domainName: "www.mocha.com"
|
52 | });
|
53 | expect(edgecdn.endpoint).to.be('http://www.mochatest.com');
|
54 | expect(edgecdn.domainName).to.be('www.mocha.com');
|
55 | })
|
56 | })
|
57 |
|
58 | describe('_encode test', function () {
|
59 | it('_encode is Function ok', function () {
|
60 | let edgecdn = new EdgeCDN({
|
61 | accessKeyId: 'accessKeyId',
|
62 | accessKeySecret: 'accessKeySecret',
|
63 | endpoint: 'http://www.mochatest.com',
|
64 | domainName: "www.mocha.com"
|
65 | });
|
66 | expect(edgecdn._encode).to.be.an("function");
|
67 | })
|
68 |
|
69 | it('_encode input test ok', function () {
|
70 | let edgecdn = new EdgeCDN({
|
71 | accessKeyId: 'accessKeyId',
|
72 | accessKeySecret: 'accessKeySecret',
|
73 | endpoint: 'http://www.mochatest.com',
|
74 | domainName: "www.mocha.com"
|
75 | });
|
76 | expect(edgecdn._encode()).to.be('undefined');
|
77 | })
|
78 |
|
79 | it('_encode output test ok', function () {
|
80 | let edgecdn = new EdgeCDN({
|
81 | accessKeyId: 'accessKeyId',
|
82 | accessKeySecret: 'accessKeySecret',
|
83 | endpoint: 'http://www.mochatest.com',
|
84 | domainName: "www.mocha.com"
|
85 | });
|
86 | expect(edgecdn._encode('!()')).to.equal('%21%28%29');
|
87 | })
|
88 | })
|
89 |
|
90 |
|
91 | describe("_flatParams Test", function () {
|
92 | it('_flatParams is funtion ok', function () {
|
93 | let edgecdn = new EdgeCDN({
|
94 | accessKeyId: 'accessKeyId',
|
95 | accessKeySecret: 'accessKeySecret',
|
96 | endpoint: 'http://www.mochatest.com',
|
97 | domainName: "www.mocha.com"
|
98 | });
|
99 | expect(edgecdn._flatParams).to.be.an("function");
|
100 | })
|
101 |
|
102 | it('_flatParams input test ok', function () {
|
103 | let edgecdn = new EdgeCDN({
|
104 | accessKeyId: 'accessKeyId',
|
105 | accessKeySecret: 'accessKeySecret',
|
106 | endpoint: 'http://www.mochatest.com',
|
107 | domainName: "www.mocha.com"
|
108 | });
|
109 | expect(function () {
|
110 | edgecdn._flatParams();
|
111 | }).to.throwException('must pass "params"');
|
112 | })
|
113 |
|
114 | it('_flatParams output test ok', function () {
|
115 | let edgecdn = new EdgeCDN({
|
116 | accessKeyId: 'accessKeyId',
|
117 | accessKeySecret: 'accessKeySecret',
|
118 | endpoint: 'http://www.mochatest.com',
|
119 | domainName: "www.mocha.com"
|
120 | });
|
121 | expect(edgecdn._flatParams({})).to.be.empty();
|
122 | expect(edgecdn._flatParams({ 'moack': 'test' })).to.have.key('moack')
|
123 | })
|
124 | })
|
125 |
|
126 | describe('_buildParams Test', function () {
|
127 | it('_buildParams test ok', function () {
|
128 | const edgecdn = new EdgeCDN({
|
129 | accessKeyId: 'accessKeyId',
|
130 | accessKeySecret: 'accessKeySecret',
|
131 | endpoint: 'http://www.mochatest.com',
|
132 | domainName: "www.mocha.com"
|
133 | });
|
134 | const result = edgecdn._buildParams();
|
135 | expect(result).to.only.have.keys('Format', 'SignatureMethod',
|
136 | 'SignatureNonce', 'SignatureVersion', 'Timestamp', 'AccessKeyId',
|
137 | 'Version');
|
138 | })
|
139 | })
|
140 |
|
141 | describe('DescribeCdnService Test', function () {
|
142 | it("DescribeCdnService test ok", function () {
|
143 | const edgecdn = new EdgeCDN({
|
144 | accessKeyId: 'accessKeyId',
|
145 | accessKeySecret: 'accessKeySecret',
|
146 | endpoint: 'http://www.mochatest.com',
|
147 | domainName: "www.mocha.com"
|
148 | });
|
149 | const result = edgecdn.DescribeCdnService();
|
150 | expect(result).to.only.have.keys('url', 'headers');
|
151 | expect(result.url).to.not.be.empty();
|
152 | expect(result.headers).to.only.have.keys('x-sdk-client', 'user-agent');
|
153 | })
|
154 | })
|
155 | })
|