UNPKG

2.61 kBJavaScriptView Raw
1const expect = require('expect.js');
2const { buildRules } = require('../src/commands/build');
3const config = require('../src/templates/config/config');
4
5describe('BuildRules Test', function () {
6 describe('BuildRules input test', function () {
7 it('buildRules is Function', function () {
8 expect(buildRules).to.be.a('function');
9 })
10
11 it('should pass "config"', function () {
12 expect(function () {
13 buildRules();
14 }).to.throwException('must pass "config"');
15 })
16
17 it('should pass "params"', function () {
18 expect(function () {
19 buildRules(config);
20 }).to.throwException('must pass "params"');
21 })
22
23 it('should pass "edgejsCode"', function () {
24 let params = {
25 'RegionId': 'cn-hangzhou',
26 'DomainName': config.domain,
27 };
28 expect(function () {
29 buildRules(config, params);
30 }).to.throwException('must pass "edgejsCode"');
31 })
32 })
33
34 describe('BuildRusle output test', function () {
35 it('should ok the first', function () {
36 config.domain = 'www.mocoktest.com'
37 let params = {
38 'RegionId': 'cn-hangzhou',
39 'DomainName': config.domain,
40 };
41 let ossjsCode = undefined;
42 let edgejsCode = `function handleRequest(request) { console.log(request)}`;
43 let result = buildRules(config, params, edgejsCode, ossjsCode);
44 expect(result).to.only.have.keys('RegionId', 'DomainName', 'Functions');
45 expect(result.RegionId).to.be('cn-hangzhou');
46 expect(result.DomainName).to.be('www.mocoktest.com');
47 expect(JSON.parse(result.Functions)).to.be.an('array');
48 })
49
50 it('should ok the seconed', function () {
51 config.domain = 'www.mocoktest.com'
52 let params = {
53 'RegionId': 'cn-hangzhou',
54 'DomainName': config.domain,
55 };
56 let edgejsCode = `function handleRequest(request) {console.log(request)}`;
57 let ossjsCode = 'function handle(request){ console.log(request)}';
58 let result = buildRules(config, params, edgejsCode, ossjsCode);
59 expect(result).to.only.have.keys('RegionId', 'DomainName', 'Functions');
60 expect(result.RegionId).to.be('cn-hangzhou');
61 expect(result.DomainName).to.be('www.mocoktest.com');
62 expect(JSON.parse(result.Functions)).to.be.an('array');
63 })
64 })
65})
\No newline at end of file