jec-sandcat
Version:
JEC Sandcat - The default RESTful web services framework for GlassCat applications.
110 lines (99 loc) • 3.27 kB
text/typescript
// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
//
// Copyright 2016-2018 Pascal ECHEMANN.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import { TestSuite, Test, BeforeAll, Async } from "jec-juta";
import { expect, assert } from "chai";
import { RouteDescriptorUtil } from "../../../../../src/com/onsoft/sandcat/utils/RouteDescriptorUtil";
import { RouteDescriptor } from "../../../../../src/com/onsoft/sandcat/reflect/RouteDescriptor";
// Utilities:
import * as utils from "../../../../../utils/test-utils/utilities/RouteDescriptorUtilTestUtils";
import { HttpMethod } from "jec-commons";
export class RouteDescriptorUtilTest {
public descriptorUtil:RouteDescriptorUtil = null;
public descriptor:RouteDescriptor = null;
public initTest():void {
this.descriptorUtil = new RouteDescriptorUtil();
this.descriptor = new RouteDescriptor(
utils.PATTERN, "getMethod", HttpMethod.GET
);
}
public matchOkTest( done:Function):void {
this.descriptorUtil.match(
this.descriptor,
utils.VALID_PATH,
(result:any)=> {
expect(result.id).to.equal('10');
done();
},
()=> {
assert.fail(null, utils.VALID_PATH, "Test should not fail");
}
);
}
public matchKoTest( done:Function):void {
this.descriptorUtil.match(
this.descriptor,
utils.INVALID_PATH,
(result:any)=> {
assert.fail(null, result, "Test should fail");
},
()=> {
done();
}
);
}
public testOkTest():void {
expect(
this.descriptorUtil.test(this.descriptor, utils.VALID_PATH)
).to.be.true;
}
public testKoTest():void {
expect(
this.descriptorUtil.test(this.descriptor, utils.INVALID_PATH)
).to.be.false;
}
public execOkTest():void {
const result:any =
this.descriptorUtil.exec(this.descriptor, utils.VALID_PATH);
expect(result.id).to.equal('10');
}
public execKoTest():void {
expect(
this.descriptorUtil.exec(this.descriptor, utils.INVALID_PATH)
).to.be.null;
}
}