Skip to content

Commit 136aad9

Browse files
authored
feat!: remove EventStream (#97)
* feat!: remove EventStream * fix: add uId to event add postCrashComment add postStackKeyComment Fixes #29 Fixes #96 BREAKING CHANGE: removes EventStream
1 parent 7f276db commit 136aad9

22 files changed

+426
-549
lines changed

spec/fakes/crash/crash-api-response.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import { GroupableThreadCollection, ProcessingStatus } from '@crash';
22
import { EventType } from '@events';
33
import { createFakeEvents } from '@spec/fakes/events/events';
4+
import { CrashDetailsRawResponse } from 'src/crash/crash-details/crash-details';
45

56
export const createFakeCrashApiResponse = () => ({
6-
processed: ProcessingStatus.Complete,
7+
processed: ProcessingStatus.Complete as number,
78
additionalFiles: ['1.txt', '2.png'],
89
appKey: 'ardvark',
910
appName: 'boregard',
1011
appVersion: '1.2.3.4',
1112
comments: 'blah blah blah',
12-
crashTime: '01:00 PM GMT',
13+
crashTime: '2023-02-04T17:58:15+0000Z',
1314
defectLabel: 'weee!',
1415
defectUrl: 'http://newayz.net',
1516
description: 'haa!',
@@ -25,9 +26,10 @@ export const createFakeCrashApiResponse = () => ({
2526
platform: 'NES',
2627
previousCrashId: 998,
2728
processor: 'Pentium 4',
29+
stackKeyComment: 'hello world!',
2830
stackKeyId: 117,
2931
stackKeyDefectLabel: 'idk',
3032
stackKeyDefectUrl: 'http://toppong.com',
3133
thread: new GroupableThreadCollection({ stackFrames: [], stackKeyId: 117 }),
3234
user: 'Fred'
33-
});
35+
} as CrashDetailsRawResponse);

spec/files/native/post-native-crash.ts

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
import { BugSplatApiClient } from '@common';
2+
import { CrashApiClient } from '@crash';
23
import { CrashPostClient, CrashType } from '@post';
34
import { VersionsApiClient } from '@versions';
45
import { firstValueFrom, timer } from 'rxjs';
6+
import { PostCrashResponse } from 'src/post/post-crash-response';
57
import { createUploadableFile } from '../create-bugsplat-file';
68

7-
export interface CrashInfo {
8-
crashId: number;
9-
stackKeyId: number;
10-
}
11-
129
export async function postNativeCrashAndSymbols(
1310
authenticatedClient: BugSplatApiClient,
1411
database: string,
1512
application: string,
1613
version: string
17-
): Promise<CrashInfo> {
14+
): Promise<PostCrashResponse> {
1815
const exeFile = createUploadableFile('./spec/files/native/myConsoleCrasher.exe');
1916
const pdbFile = createUploadableFile('./spec/files/native/myConsoleCrasher.pdb');
2017
const files = [exeFile, pdbFile];
@@ -33,7 +30,7 @@ export async function postNativeCrash(
3330
database: string,
3431
application: string,
3532
version: string
36-
): Promise<CrashInfo> {
33+
): Promise<PostCrashResponse> {
3734
const crashFile = createUploadableFile('./spec/files/native/myConsoleCrasher.zip');
3835
const crashPostClient = new CrashPostClient(database);
3936
await firstValueFrom(timer(2000)); // Prevent rate-limiting
@@ -44,5 +41,44 @@ export async function postNativeCrash(
4441
crashFile,
4542
'ebe24c1cd1a0912904658fa4fad2b539'
4643
);
47-
return postCrashResult.json() as Promise<CrashInfo>;
44+
return postCrashResult.json();
45+
}
46+
47+
export async function postNativeCrashAndWaitForCrashToProcess(
48+
bugsplat: BugSplatApiClient,
49+
crashClient: CrashApiClient,
50+
database: string,
51+
application: string,
52+
version: string
53+
): Promise<PostCrashResponse> {
54+
const result = await postNativeCrashAndSymbols(
55+
bugsplat,
56+
database,
57+
application,
58+
version
59+
);
60+
61+
const crashId = result.crashId;
62+
let stackKeyId = result.stackKeyId;
63+
64+
if (stackKeyId > 0) {
65+
return {
66+
crashId,
67+
stackKeyId
68+
};
69+
}
70+
71+
for (let i = 0; i < 60; i++) {
72+
const crash = await crashClient.getCrashById(database, crashId);
73+
stackKeyId = crash.stackKeyId as number;
74+
if (stackKeyId > 0) {
75+
break;
76+
}
77+
await firstValueFrom(timer(3000));
78+
}
79+
80+
return {
81+
crashId,
82+
stackKeyId
83+
};
4884
}

src/crash/crash-api-client/crash-api-client.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { CrashApiClient, CrashDetails } from '@crash';
1+
import { CrashApiClient } from '@crash';
22
import { createFakeBugSplatApiClient } from '@spec/fakes/common/bugsplat-api-client';
33
import { createFakeFormData } from '@spec/fakes/common/form-data';
44
import { createFakeResponseBody } from '@spec/fakes/common/response';
55
import { createFakeCrashApiResponse } from '@spec/fakes/crash/crash-api-response';
6+
import { createCrashDetails } from '../crash-details/crash-details';
67

78
describe('CrashApiClient', () => {
89
const database = 'fred';
@@ -49,7 +50,7 @@ describe('CrashApiClient', () => {
4950

5051
it('should return response json', () => {
5152
expect(result).toEqual(
52-
jasmine.objectContaining(new CrashDetails(fakeCrashApiResponse))
53+
jasmine.objectContaining(createCrashDetails(fakeCrashApiResponse))
5354
);
5455
});
5556

src/crash/crash-api-client/crash-api-client.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ApiClient } from '@common';
22
import { CrashDetails } from '@crash';
33
import ac from 'argument-contracts';
4-
import { CrashDetailsConstructorOptions } from '../crash-details/crash-details';
4+
import { CrashDetailsRawResponse, createCrashDetails } from '../crash-details/crash-details';
55

66
export class CrashApiClient {
77

@@ -33,7 +33,7 @@ export class CrashApiClient {
3333
throw new Error((json as Error).message);
3434
}
3535

36-
return new CrashDetails(json as CrashDetailsConstructorOptions);
36+
return createCrashDetails(json as CrashDetailsRawResponse);
3737
}
3838

3939
async reprocessCrash(database: string, crashId: number, force = false): Promise<SuccessResponse> {
@@ -42,7 +42,7 @@ export class CrashApiClient {
4242
if (crashId <= 0) {
4343
throw new Error(`Expected id to be a positive non-zero number. Value received: "${crashId}"`);
4444
}
45-
45+
4646
const formData = this._client.createFormData();
4747
formData.append('database', database);
4848
formData.append('id', crashId.toString());
@@ -62,12 +62,12 @@ export class CrashApiClient {
6262
if (response.status !== 202) {
6363
throw new Error((json as ErrorResponse).message);
6464
}
65-
65+
6666
return json as SuccessResponse;
6767
}
6868
}
6969

7070
type SuccessResponse = { success: boolean };
7171
type ErrorResponse = { message: string };
72-
type GetCrashByIdResponse = CrashDetailsConstructorOptions | ErrorResponse;
73-
type ReprocessCrashResponse = SuccessResponse | ErrorResponse;
72+
type GetCrashByIdResponse = CrashDetailsRawResponse | ErrorResponse;
73+
type ReprocessCrashResponse = SuccessResponse | ErrorResponse;

src/crash/crash-details/crash-details.spec.ts

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,20 @@
1-
import { CrashDetails, ProcessingStatus } from '@crash';
2-
import { EventStreamActionType } from '@events';
1+
import { AdditionalInfo, ProcessingStatus } from '@crash';
32
import { createFakeCrashApiResponse } from '@spec/fakes/crash/crash-api-response';
43
import ac from 'argument-contracts';
4+
import { createEvents } from '../../events/events-api-client/event';
55
import * as ThreadCollectionModule from '../thread-collection/thread-collection';
6+
import { createCrashDetails } from './crash-details';
67

7-
describe('Crash Details', () => {
8+
describe('createCrashDetails', () => {
89
it('should set all properties', () => {
9-
const options = createFakeCrashApiResponse();
10+
const options: any = createFakeCrashApiResponse();
1011

11-
const result = new CrashDetails(options);
12+
const result = createCrashDetails(options);
1213

13-
Object.keys(options).forEach(key => {
14-
if (key !== 'events') {
15-
expect(options[key]).toEqual(result[key]);
16-
} else {
17-
expect(result.events).toEqual(jasmine.arrayContaining([
18-
jasmine.objectContaining({
19-
action: EventStreamActionType.comment,
20-
createdDate: new Date(options.events[0].timestamp),
21-
subject: {
22-
initials: options.events[0].username.substring(0, 2),
23-
email: options.events[0].username,
24-
},
25-
message: options.events[0].message,
26-
})
27-
]));
28-
}
14+
expect(result).toEqual({
15+
...options,
16+
events: createEvents(options.events),
17+
additionalInfo: jasmine.any(AdditionalInfo),
2918
});
3019
});
3120

@@ -56,7 +45,7 @@ describe('Crash Details', () => {
5645
thread: (<any>{ stackFrames: [], stackKeyId: 0 })
5746
};
5847

59-
const result = new CrashDetails(<any>options);
48+
const result = createCrashDetails(<any>options);
6049

6150
expect(result.comments).toEqual('');
6251
expect(result.description).toEqual('');

0 commit comments

Comments
 (0)