Skip to content

Commit ee54102

Browse files
committed
Added plugin support to the client.
1 parent 92c26b1 commit ee54102

File tree

2 files changed

+225
-108
lines changed

2 files changed

+225
-108
lines changed

src/exceptionless-spec.ts

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,57 @@
33

44
//import { Configuration, ExceptionlessClient } from 'Exceptionless';
55
module Exceptionless {
6-
describe('ExceptionlessClient', () => {
7-
it('disable the client with null api key', () => {
8-
var client = new ExceptionlessClient(null);
9-
expect(client.config).not.toBe(null);
10-
expect(client.config.apiKey).toBe(null);
11-
expect(client.config.enabled).toBe(false);
6+
describe('Configuration', () => {
7+
it('should set the api key to null and enabled to false', () => {
8+
var config = new Configuration(null);
9+
expect(config.apiKey).toBe(null);
10+
expect(config.enabled).toBe(false);
1211
});
1312

1413
it('should set the api key and enabled to true', () => {
15-
var client = new ExceptionlessClient('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', 'http://localhost:50000');
16-
expect(client.config).not.toBe(null);
17-
expect(client.config.apiKey).toBe('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw');
18-
expect(client.config.enabled).toBe(true);
14+
var config = new Configuration('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw', 'http://localhost:50000');
15+
expect(config).not.toBe(null);
16+
expect(config.apiKey).toBe('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw');
17+
expect(config.enabled).toBe(true);
1918
});
2019

2120
it('apply client configuration', () => {
22-
var client = new ExceptionlessClient(null);
23-
expect(client.config).not.toBe(null);
24-
expect(client.config.apiKey).toBe(null);
25-
expect(client.config.enabled).toBe(false);
26-
27-
client.config.setApiKey('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw');
28-
expect(client.config.apiKey).toBe('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw');
29-
expect(client.config.enabled).toBe(true);
21+
var config = new Configuration(null);
22+
expect(config.apiKey).toBe(null);
23+
expect(config.enabled).toBe(false);
24+
25+
config.apiKey = 'LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw';
26+
expect(config.apiKey).toBe('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw');
27+
expect(config.enabled).toBe(true);
28+
});
29+
30+
it('should not add duplicate plugin', () => {
31+
var config = new Configuration('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw');
32+
expect(config.plugins).not.toBe(null);
33+
config.addPlugin('test', 20, (context:EventPluginContext) => {});
34+
config.addPlugin('test', 20, (context:EventPluginContext) => {});
35+
expect(config.plugins.length).toBe(1);
36+
});
37+
38+
it('should generate plugin name and priority', () => {
39+
var config = new Configuration('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw');
40+
expect(config.plugins).not.toBe(null);
41+
config.addPlugin(null, null, (context:EventPluginContext) => {});
42+
expect(config.plugins.length).toBe(1);
43+
expect(config.plugins[0].name).not.toBe(null);
44+
expect(config.plugins[0].priority).toBe(0);
45+
});
46+
47+
it('should sort plugins by priority', () => {
48+
var config = new Configuration('LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw');
49+
expect(config.plugins).not.toBe(null);
50+
config.addPlugin('3', 3, (context:EventPluginContext) => {});
51+
config.addPlugin('1', 1, (context:EventPluginContext) => {});
52+
config.addPlugin('2', 2, (context:EventPluginContext) => {});
53+
expect(config.plugins.length).toBe(3);
54+
expect(config.plugins[0].priority).toBe(1);
55+
expect(config.plugins[1].priority).toBe(2);
56+
expect(config.plugins[2].priority).toBe(3);
3057
});
3158
});
3259

0 commit comments

Comments
 (0)