Skip to content

Commit 031dc2f

Browse files
committed
More test updates for new submission impl
1 parent 270a9e0 commit 031dc2f

10 files changed

+122
-190
lines changed

packages/core/src/submission/SubmissionClientBase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export abstract class SubmissionClientBase implements ISubmissionClient {
2626
public async submitEvents(events: IEvent[]): Promise<Response<void>> {
2727
const url = `${this.config.serverUrl}/api/v2/events`;
2828
const response = await this.fetch<void>(url, {
29-
method: 'GET',
29+
method: 'POST',
3030
body: JSON.stringify(events)
3131
});
3232

packages/core/test/ExceptionlessClient.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22

33
import { Configuration } from "../src/configuration/Configuration.js";
44
import { ExceptionlessClient } from "../src/ExceptionlessClient.js";
5-
import { EventPluginContext } from "../src/plugins/EventPluginContext.js";
6-
import { InMemorySubmissionAdapter } from "./submission/InMemorySubmissionAdapter.js";
75

86
describe('ExceptionlessClient', () => {
97
beforeEach(() => {
108
Configuration.defaults.updateSettingsWhenIdleInterval = -1;
11-
Configuration.defaults.submissionAdapter = new InMemorySubmissionAdapter();
129
});
1310

1411
test('should use event reference ids', async () => {

packages/core/test/plugins/EventPluginManager.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ describe('EventPluginManager', () => {
9090
expect(context.cancelled).toBe(true);
9191
});
9292

93-
test('should cancel via timeout.', async done => {
93+
test('should cancel via timeout.', async () => {
9494
const client = new ExceptionlessClient({
9595
apiKey: 'LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw',
9696
serverUrl: 'http://localhost:5000'

packages/core/test/plugins/default/DuplicateCheckerPlugin.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ExceptionlessClient } from "../../../src/ExceptionlessClient.js";
33
import { EventPluginContext } from "../../../src/plugins/EventPluginContext.js";
44
import { IInnerError } from "../../../src/models/IInnerError.js";
55
import { IStackFrame } from "../../../src/models/IStackFrame.js";
6+
import { delay } from "../../../src/Utils.js";
67

78
const Exception1StackTrace = [
89
{
@@ -48,7 +49,7 @@ describe('DuplicateCheckerPlugin', () => {
4849
plugin = new DuplicateCheckerPlugin(() => now, 50);
4950
});
5051

51-
function run(stackTrace?: IStackFrame[]) {
52+
function run(stackTrace?: IStackFrame[]): Promise<EventPluginContext> {
5253
// TODO: Generate unique stack traces based on test data.
5354
const context = new EventPluginContext(client, {
5455
type: 'error',
@@ -61,19 +62,19 @@ describe('DuplicateCheckerPlugin', () => {
6162
}
6263
});
6364

64-
plugin.run(context);
65+
await plugin.run(context);
6566
return context;
6667
}
6768

68-
test('should ignore duplicate within window', done => {
69+
test('should ignore duplicate within window', async () => {
6970
run(Exception1StackTrace);
7071

7172
const contextOfSecondRun = run(Exception1StackTrace);
7273
expect(contextOfSecondRun.cancelled).toBe(true);
74+
await delay(100);
7375
setTimeout(() => {
7476
expect(contextOfSecondRun.event.count).toBe(1);
7577

76-
done();
7778
}, 100);
7879
});
7980

packages/core/test/queue/DefaultEventQueue.test.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import { Configuration } from "../../src/configuration/Configuration.js";
22
import { IEvent } from "../../src/models/IEvent.js";
3-
4-
import { InMemorySubmissionAdapter } from "../submission/InMemorySubmissionAdapter.js";
3+
import { delay } from "../../src/Utils.js";
54

65
describe('DefaultEventQueue', () => {
76
let config: Configuration;
87

98
beforeEach(() => {
109
config = new Configuration({
1110
apiKey: 'LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw',
12-
serverUrl: 'http://localhost:5000',
13-
submissionAdapter: new InMemorySubmissionAdapter()
11+
serverUrl: 'http://localhost:5000'
1412
});
1513

1614
expect(config.storage.queue.get().length).toBe(0);
@@ -48,21 +46,18 @@ describe('DefaultEventQueue', () => {
4846
expect(config.storage.queue.get().length).toBe(0);
4947
});
5048

51-
test('should suspend processing', done => {
49+
test('should suspend processing', async () => {
5250
config.queue.suspendProcessing(.0001);
5351

5452
const event: IEvent = { type: 'log', reference_id: '123454321' };
5553
config.queue.enqueue(event);
5654
expect(config.storage.queue.get().length).toBe(1);
5755

58-
setTimeout(() => {
59-
if (!(config.queue as any)._suspendProcessingUntil) {
60-
expect(config.storage.queue.get().length).toBe(0);
61-
} else {
62-
expect(config.storage.queue.get().length).toBe(1);
63-
}
64-
65-
done();
66-
}, 25);
56+
await delay(25);
57+
if (!(config.queue as any)._suspendProcessingUntil) {
58+
expect(config.storage.queue.get().length).toBe(0);
59+
} else {
60+
expect(config.storage.queue.get().length).toBe(1);
61+
}
6762
});
6863
});

packages/core/test/submission/DefaultSubmissionClient.test.ts

Lines changed: 0 additions & 93 deletions
This file was deleted.

packages/core/test/submission/InMemorySubmissionAdapter.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

packages/core/test/submission/TestSubmissionAdapter.ts

Lines changed: 0 additions & 48 deletions
This file was deleted.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import { Configuration } from "../../src/configuration/Configuration.js";
2+
import { ClientSettings } from "../../src/configuration/SettingsManager.js";
3+
import { IEvent } from "../../src/models/IEvent.js";
4+
import { IUserDescription } from "../../src/models/IUserDescription.js";
5+
import { Response } from "../../src/submission/Response.js";
6+
import { TestSubmissionClient } from "./TestSubmissionClient.js"
7+
8+
describe('TestSubmissionClient', () => {
9+
const config: Configuration = new Configuration({
10+
apiKey: 'LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw',
11+
serverUrl: 'http://server.localhost:5000',
12+
configServerUrl: 'http://config.localhost:5000',
13+
heartbeatServerUrl: 'http://heartbeat.localhost:5000',
14+
});
15+
16+
test('should submit events', async () => {
17+
const fetchMock = TestSubmissionClient.prototype.fetch = jest.fn()
18+
.mockReturnValueOnce(new Response<void>(202, '', -1, undefined));
19+
20+
const events = [{ type: 'log', message: 'From js client', reference_id: '123454321' }];
21+
const client = new TestSubmissionClient(config);
22+
await client.submitEvents(events);
23+
expect(fetchMock).toHaveBeenCalledTimes(1);
24+
expect(fetchMock.mock.calls[0][0]).toBe(`${config.serverUrl}/api/v2/events`);
25+
expect(fetchMock.mock.calls[0][1]).toEqual({
26+
method: 'POST',
27+
body: JSON.stringify(events)
28+
});
29+
});
30+
31+
test('should submit invalid object data', async () => {
32+
const fetchMock = TestSubmissionClient.prototype.fetch = jest.fn()
33+
.mockReturnValueOnce(new Response<void>(202, '', -1, undefined));
34+
35+
const events: IEvent[] = [{
36+
type: 'log', message: 'From js client', reference_id: '123454321', data: {
37+
name: 'blake',
38+
age: () => { throw new Error('Test'); }
39+
}
40+
}];
41+
42+
const client = new TestSubmissionClient(config);
43+
await client.submitEvents(events);
44+
expect(fetchMock).toHaveBeenCalledTimes(1);
45+
expect(fetchMock.mock.calls[0][0]).toBe(`${config.serverUrl}/api/v2/events`);
46+
expect(fetchMock.mock.calls[0][1]).toEqual({
47+
method: 'POST',
48+
body: JSON.stringify(events)
49+
});
50+
});
51+
52+
test('should submit user description', async () => {
53+
const fetchMock = TestSubmissionClient.prototype.fetch = jest.fn()
54+
.mockReturnValueOnce(new Response<void>(202, '', -1, undefined));
55+
56+
const description: IUserDescription = {
57+
email_address: 'norply@exceptionless.io',
58+
description: 'unit test'
59+
};
60+
61+
const client = new TestSubmissionClient(config);
62+
await client.submitUserDescription("123454321", description);
63+
expect(fetchMock).toHaveBeenCalledTimes(1);
64+
expect(fetchMock.mock.calls[0][0]).toBe(`${config.serverUrl}/api/v2/events/by-ref/123454321/user-description`);
65+
expect(fetchMock.mock.calls[0][1]).toEqual({
66+
method: 'POST',
67+
body: JSON.stringify(description)
68+
});
69+
});
70+
71+
test('should submit heartbeat', async () => {
72+
const fetchMock = TestSubmissionClient.prototype.fetch = jest.fn()
73+
.mockReturnValueOnce(new Response<void>(200, '', 1, undefined))
74+
.mockReturnValueOnce(new Response<ClientSettings>(200, '', 1, new ClientSettings({}, 1)));
75+
76+
const client = config.submissionClient = new TestSubmissionClient(config);
77+
await client.submitHeartbeat('sessionId', true);
78+
expect(fetchMock).toHaveBeenCalledTimes(2);
79+
expect(fetchMock.mock.calls[0][0]).toBe(`${config.heartbeatServerUrl}/api/v2/events/session/heartbeat?id=sessionId&close=true`);
80+
expect(fetchMock.mock.calls[0][1]).toEqual({ method: 'GET' });
81+
expect(fetchMock.mock.calls[1][0]).toBe(`${config.serverUrl}/api/v2/projects/config?v=0`);
82+
expect(fetchMock.mock.calls[1][1]).toEqual({ method: 'GET' });
83+
});
84+
85+
test('should get project settings', async () => {
86+
const fetchMock = TestSubmissionClient.prototype.fetch = jest.fn()
87+
.mockReturnValueOnce(new Response<ClientSettings>(200, '', undefined, new ClientSettings({}, 1)));
88+
89+
const client = new TestSubmissionClient(config);
90+
await client.getSettings(0);
91+
expect(fetchMock).toHaveBeenCalledTimes(1);
92+
expect(fetchMock.mock.calls[0][0]).toBe(`${config.serverUrl}/api/v2/projects/config?v=0`);
93+
expect(fetchMock.mock.calls[0][1]).toEqual({ method: 'GET' });
94+
});
95+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Response } from "../../src/submission/Response.js";
2+
import {
3+
FetchOptions,
4+
SubmissionClientBase
5+
} from "../../src/submission/SubmissionClientBase.js";
6+
7+
export class TestSubmissionClient extends SubmissionClientBase {
8+
public fetch<T>(url: string, options: FetchOptions): Promise<Response<T>> {
9+
throw new Error("Missing mock");
10+
}
11+
}

0 commit comments

Comments
 (0)