Skip to content

Commit c21a3b1

Browse files
committed
Added some initial unit tests.
1 parent b6b0895 commit c21a3b1

File tree

3 files changed

+96
-37
lines changed

3 files changed

+96
-37
lines changed

src/exceptionless-spec.ts

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,73 @@
11
/// <reference path="bower_components/DefinitelyTyped/jasmine/jasmine.d.ts" />
22
/// <reference path="exceptionless.ts" />
33

4-
describe('ExceptionlessClient', function() {
5-
it('should apply the configuration', function () {
4+
module Exceptionless {
5+
describe('ExceptionlessClient', function () {
6+
it('disable the client with null api key', function () {
7+
var client = new ExceptionlessClient(null);
8+
expect(client.config).not.toBe(null);
9+
expect(client.config.apiKey).toBe(null);
10+
expect(client.config.enabled).toBe(false);
11+
});
12+
13+
it('should set the api key and enabled to true', function () {
14+
var client = new ExceptionlessClient('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw');
15+
expect(client.config).not.toBe(null);
16+
expect(client.config.apiKey).toBe('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw');
17+
expect(client.config.enabled).toBe(true);
18+
});
19+
20+
it('apply client configuration', function () {
21+
var client = new ExceptionlessClient(null);
22+
expect(client.config).not.toBe(null);
23+
expect(client.config.apiKey).toBe(null);
24+
expect(client.config.enabled).toBe(false);
25+
26+
client.config.setApiKey('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw');
27+
expect(client.config.apiKey).toBe('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw');
28+
expect(client.config.enabled).toBe(true);
29+
});
30+
});
31+
32+
describe('EventQueue', function () {
33+
it('should enqueue event', function () {
34+
var config = new Configuration('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw');
35+
});
36+
37+
it('should process queue', function () {
38+
var config = new Configuration('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw');
39+
});
40+
41+
it('should suspend processing', function () {
42+
var config = new Configuration('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw');
43+
});
44+
});
45+
46+
describe('SubmissionClient', function () {
47+
it('should submit events', function () {
48+
var config = new Configuration('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw');
49+
});
50+
51+
it('should submit user description', function () {
52+
var config = new Configuration('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw');
53+
});
54+
55+
it('should get project settings', function () {
56+
var config = new Configuration('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw');
57+
});
58+
});
59+
60+
describe('Storage', function () {
61+
it('should save events', function () {
62+
var config = new Configuration('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw');
63+
});
64+
65+
it('should get saved events', function () {
66+
var config = new Configuration('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw');
67+
});
68+
69+
it('should clear all events', function () {
70+
var config = new Configuration('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw');
671
});
772
});
73+
}

src/exceptionless.ts

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,24 @@
22

33
// TODO: We'll need a poly fill for promises.
44
module Exceptionless {
5-
class ExceptionlessClient {
6-
private _config:Configuration;
5+
export class ExceptionlessClient {
6+
public config:Configuration;
77

88
constructor(apiKey:string, serverUrl?:string) {
9-
this._config = new Configuration(apiKey, serverUrl);
10-
}
11-
12-
apply(config:Configuration) {
13-
for (var name in config || {}) {
14-
this._config[name] = config[name];
15-
}
9+
this.config = new Configuration(apiKey, serverUrl);
1610
}
1711

1812
submit(events:ExceptionlessEvent) {
19-
if (!this._config.enabled) {
20-
this._config.log.info('Event submission is currently disabled');
13+
if (!this.config.enabled) {
14+
this.config.log.info('Event submission is currently disabled');
2115
return;
2216
}
2317
}
2418
}
2519

26-
class Configuration {
20+
export class Configuration {
2721
apiKey:string;
28-
serverUrl = 'https://collector.exceptionless.io/api/v2';
22+
serverUrl:string;
2923
enabled = true;
3024

3125
log:ILog = new NullLog();
@@ -35,34 +29,34 @@ module Exceptionless {
3529
queue:IEventQueue;
3630

3731
constructor(apiKey:string, serverUrl?:string) {
32+
this.setApiKey(apiKey);
33+
this.serverUrl = serverUrl || 'https://collector.exceptionless.io/api/v2';
34+
this.queue = new EventQueue(this);
35+
}
36+
37+
public setApiKey(apiKey:string) {
3838
this.apiKey = apiKey;
3939
this.enabled = !!apiKey;
40-
41-
if(!!serverUrl) {
42-
this.serverUrl = serverUrl;
43-
}
44-
45-
this.queue = new EventQueue(this);
4640
}
4741

4842
public getQueueName(): string {
4943
return !!this.apiKey ? 'ex-' + this.apiKey.slice(0, 8) : null;
5044
}
5145
}
5246

53-
interface ILog {
47+
export interface ILog {
5448
info(message:string);
5549
warn(message:string);
5650
error(message:string);
5751
}
5852

59-
class NullLog implements ILog {
53+
export class NullLog implements ILog {
6054
public info(message) {}
6155
public warn(message) {}
6256
public error(message) {}
6357
}
6458

65-
class ConsoleLog implements ILog {
59+
export class ConsoleLog implements ILog {
6660
public info(message) {
6761
console.log('[INFO] Exceptionless:' + message)
6862
}
@@ -76,13 +70,13 @@ module Exceptionless {
7670
}
7771
}
7872

79-
interface IEventQueue {
73+
export interface IEventQueue {
8074
enqueue(event:ExceptionlessEvent);
8175
process();
8276
suspendProcessing(durationInMinutes?:number, discardFutureQueuedItems?:boolean, clearQueue?:boolean);
8377
}
8478

85-
class EventQueue implements IEventQueue {
79+
export class EventQueue implements IEventQueue {
8680
private _config:Configuration;
8781
private _areQueuedItemsDiscarded = false;
8882
private _suspendProcessingUntil:Date;
@@ -218,13 +212,13 @@ module Exceptionless {
218212
}
219213
}
220214

221-
interface ISubmissionClient {
215+
export interface ISubmissionClient {
222216
submitEvents(events:ExceptionlessEvent[], config:Configuration): Promise<SubmissionResponse>;
223217
submitUserDescription(referenceId:string, description:UserDescription, config:Configuration): Promise<SubmissionResponse>;
224218
getSettings(config:Configuration): Promise<SettingsResponse>;
225219
}
226220

227-
class SubmissionClient implements ISubmissionClient {
221+
export class SubmissionClient implements ISubmissionClient {
228222
public submitEvents(events:ExceptionlessEvent[], config:Configuration): Promise<SubmissionResponse> {
229223
var url = config.serverUrl + '/events?access_token=' + encodeURIComponent(config.apiKey);
230224
return this.sendRequest('POST', url, JSON.stringify(events)).then(
@@ -320,7 +314,7 @@ module Exceptionless {
320314
}
321315
}
322316

323-
class SubmissionResponse {
317+
export class SubmissionResponse {
324318
success = false;
325319
badRequest = false;
326320
serviceUnavailable = false;
@@ -345,7 +339,7 @@ module Exceptionless {
345339
}
346340
}
347341

348-
class SettingsResponse {
342+
export class SettingsResponse {
349343
success = false;
350344
settings:any;
351345
settingsVersion = -1;
@@ -361,13 +355,13 @@ module Exceptionless {
361355
}
362356
}
363357

364-
interface IStorage<T>{
358+
export interface IStorage<T>{
365359
save<T>(path:string, value:T): boolean;
366360
get(searchPattern?:string, limit?:number): T[];
367361
clear(searchPattern?:string);
368362
}
369363

370-
class InMemoryStorage<T> implements IStorage<T> {
364+
export class InMemoryStorage<T> implements IStorage<T> {
371365
public save<T>(path:string, value:T): boolean {
372366
return false;
373367
}
@@ -381,7 +375,7 @@ module Exceptionless {
381375
}
382376
}
383377

384-
class ExceptionlessEvent {}
378+
export class ExceptionlessEvent {}
385379

386-
class UserDescription {}
380+
export class UserDescription {}
387381
}

src/karma.conf.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ module.exports = function (config) {
1010
'bower_components/es6-shim/es6-shim.js',
1111
'bower_components/DefinitelyTyped/es6-promise/es6-promise.d.ts',
1212
'bower_components/DefinitelyTyped/jasmine/jasmine.d.ts',
13-
'*.ts'
13+
'**/*.ts'
1414
],
1515
exclude: [],
1616
preprocessors: {
17-
'exceptionless.ts': ['typescript'],
18-
'exceptionless-spec.ts': ['typescript']
17+
'**/*.ts': ['typescript']
1918
},
2019
reporters: ['progress'],
2120
port: 9876,

0 commit comments

Comments
 (0)