Skip to content

Commit

Permalink
added Token class
Browse files Browse the repository at this point in the history
  • Loading branch information
HNeukermans committed Oct 4, 2016
1 parent 132ec1b commit 48d6a6a
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 6 deletions.
12 changes: 6 additions & 6 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ module.exports = function (config) {
frameworks: ["jasmine"],
// list of files / patterns to load in the browser
files: [
{pattern: 'angular2-jwt.spec.ts', watched: false}
{pattern: '*.spec.ts', watched: false}
],

// list of files / patterns to exclude
exclude: [],

preprocessors: {
'angular2-jwt.spec.ts': [ 'webpack', 'sourcemap']
'*.spec.ts': [ 'webpack', 'sourcemap']
},


Expand All @@ -35,18 +35,18 @@ module.exports = function (config) {
logLevel: config.LOG_INFO,

// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,
autoWatch: true,

browsers: [
//"Firefox",
//"Chrome",
"Chrome",
//"IE",
"PhantomJS"
//"PhantomJS"
],

// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: true,
singleRun: false,

reporters: ['progress'],

Expand Down
52 changes: 52 additions & 0 deletions token.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Token } from "./token";

describe("Token", () => {

'use strict';

it("constructor should set value", () => {
const value = 'dGVzdA==';
let token = new Token(value);
expect(token.value).toBe(value);
});

it("constructor with null should default to empty string", () => {
let token = new Token(null);
expect(token.value).toBe('');
});

it("token with same value are equal", () => {
let token1 = new Token('AA==');
let token2 = new Token('AA==');
expect(token1.equals(token2)).toBe(true);
});

it("token with different value are not equal", () => {
let token1 = new Token('AA==');
let token2 = new Token('ZZ==');
expect(token1.equals(token2)).toBe(false);
});

it("token with null value equals to empty token", () => {
let token1 = new Token(null);
expect(token1.equals(Token.Empty)).toBe(true);
});

it("token with blank value equals to empty token", () => {
let token1 = new Token('');
expect(token1.equals(Token.Empty)).toBe(true);
});



});

describe("Empty Token", () => {

'use strict';

it("should have empty value", () => {
expect(Token.Empty.value).toBe('');
});

});
21 changes: 21 additions & 0 deletions token.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export class Token {

private _value: string = null;

This comment has been minimized.

Copy link
@escardin

escardin Oct 4, 2016

Contributor

don't assign it here.


public get value(): string {
return this._value;
}
constructor(value: string) {
this._value = value;

This comment has been minimized.

Copy link
@escardin

escardin Oct 4, 2016

Contributor

this._value=value||''

This comment has been minimized.

Copy link
@HNeukermans

HNeukermans Oct 5, 2016

Author

good one

if (this._value == null) this._value = '';
}

public static get Empty(): Token {

This comment has been minimized.

Copy link
@escardin

escardin Oct 4, 2016

Contributor

could be a constant

return new Token('');
}

public equals(token: Token): boolean {
if(token.value === this.value) return true;

This comment has been minimized.

Copy link
@escardin

escardin Oct 4, 2016

Contributor

return token.value===this.value

return false;
}
}
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"files": [
"angular2-jwt.ts",
"angular2-jwt.spec.ts",
"token.ts",
"token.spec.ts",
"custom.d.ts"
],
"exclude": [
Expand Down

0 comments on commit 48d6a6a

Please sign in to comment.