@chustasoft/cs-common
Version:
Common utilities for JavaScript projects equivalents to ChustaSoft CommonNET project
40 lines (26 loc) • 1.39 kB
text/typescript
import { suite, test } from '@testdeck/mocha';
import * as _chai from 'chai';
import { BasicAuthentication, JwtAuthentication } from '../src';
import { HttpHeadersBuilder } from '../src/helpers/http-headers.builder';
_chai.should();
class HttpHeadersBuilderUnitTest {
'SHOULD create bearer authentication WHEN JwtAuthentication sended'() {
var builderUnderTest: HttpHeadersBuilder = new HttpHeadersBuilder();
const token = "test-token";
const jwtAuth = new JwtAuthentication(token);
var result = builderUnderTest.setAuthentication(jwtAuth).build();
_chai.expect(result['Authorization']).to.equal(`Bearer ${token}`);
}
'SHOULD create basic authentication WHEN BasicAuthentication sended'() {
var builderUnderTest: HttpHeadersBuilder = new HttpHeadersBuilder();
const user = "usernname", pass = "pwd";
const basicAuth = new BasicAuthentication(user, pass);
var result = builderUnderTest.setAuthentication(basicAuth).build();
_chai.expect(result['Authorization']).to.equal(`Basic ${btoa(user + ':' + pass)}`);
}
'SHOULD create empty authentication WHEN BasicAuthentication sended'() {
var builderUnderTest: HttpHeadersBuilder = new HttpHeadersBuilder();
var result = builderUnderTest.setAuthentication(null).build();
_chai.expect(result['Authorization']).to.be.a('undefined');
}
}