Skip to content

Commit dab3bd9

Browse files
committed
fix: update to new notes API
1 parent c922bf1 commit dab3bd9

File tree

2 files changed

+81
-92
lines changed

2 files changed

+81
-92
lines changed

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

Lines changed: 76 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -5,95 +5,95 @@ import { createFakeResponseBody } from '@spec/fakes/common/response';
55
import * as TableDataClientModule from '../../common/data/table-data/table-data-client/table-data-client';
66

77
describe('CrashesApiClient', () => {
8-
let sut: CrashesApiClient;
8+
let sut: CrashesApiClient;
99

10-
let apiClient;
11-
let apiClientResponse;
12-
let database;
13-
let fakeFormData;
14-
let id;
15-
let pageData;
16-
let rows;
17-
let tableDataClient;
18-
let tableDataClientResponse;
19-
let Comments;
20-
let IpAddress;
10+
let apiClient;
11+
let apiClientResponse;
12+
let database;
13+
let fakeFormData;
14+
let id;
15+
let pageData;
16+
let rows;
17+
let tableDataClient;
18+
let tableDataClientResponse;
19+
let Comments;
20+
let IpAddress;
2121

22-
beforeEach(() => {
23-
fakeFormData = createFakeFormData();
24-
apiClientResponse = createFakeResponseBody(200);
25-
apiClient = createFakeBugSplatApiClient(fakeFormData, apiClientResponse);
22+
beforeEach(() => {
23+
fakeFormData = createFakeFormData();
24+
apiClientResponse = createFakeResponseBody(200);
25+
apiClient = createFakeBugSplatApiClient(fakeFormData, apiClientResponse);
2626

27-
id = 9001;
28-
database = '☕️';
29-
Comments = 'it\'s over 9000!';
30-
IpAddress = '🏡';
31-
pageData = { coffee: 'black rifle' };
32-
rows = [{ id, Comments, IpAddress }];
33-
tableDataClientResponse = createFakeResponseBody(200, { pageData, rows });
34-
tableDataClient = jasmine.createSpyObj('TableDataClient', ['postGetData']);
35-
tableDataClient.postGetData.and.resolveTo(tableDataClientResponse);
36-
spyOn(TableDataClientModule, 'TableDataClient').and.returnValue(tableDataClient);
27+
id = 9001;
28+
database = '☕️';
29+
Comments = 'it\'s over 9000!';
30+
IpAddress = '🏡';
31+
pageData = { coffee: 'black rifle' };
32+
rows = [{ id, Comments, IpAddress }];
33+
tableDataClientResponse = createFakeResponseBody(200, { pageData, rows });
34+
tableDataClient = jasmine.createSpyObj('TableDataClient', ['postGetData']);
35+
tableDataClient.postGetData.and.resolveTo(tableDataClientResponse);
36+
spyOn(TableDataClientModule, 'TableDataClient').and.returnValue(tableDataClient);
3737

38-
sut = new CrashesApiClient(apiClient);
39-
});
38+
sut = new CrashesApiClient(apiClient);
39+
});
4040

41-
describe('getCrashes', () => {
42-
let result;
43-
let request;
41+
describe('getCrashes', () => {
42+
let result;
43+
let request;
4444

45-
beforeEach(async () => {
46-
request = { database };
47-
result = await sut.getCrashes(request);
48-
});
45+
beforeEach(async () => {
46+
request = { database };
47+
result = await sut.getCrashes(request);
48+
});
4949

50-
it('should call postGetData with request', () => {
51-
expect(tableDataClient.postGetData).toHaveBeenCalledWith(request);
52-
});
50+
it('should call postGetData with request', () => {
51+
expect(tableDataClient.postGetData).toHaveBeenCalledWith(request);
52+
});
5353

54-
it('should return value with Comments and IpAddress values mapped to lower-case', () => {
55-
expect(result.pageData).toEqual(pageData);
56-
expect(result.rows[0].id).toEqual(id);
57-
expect(result.rows[0].comments).toEqual(Comments);
58-
expect(result.rows[0].ipAddress).toEqual(IpAddress);
59-
});
54+
it('should return value with Comments and IpAddress values mapped to lower-case', () => {
55+
expect(result.pageData).toEqual(pageData);
56+
expect(result.rows[0].id).toEqual(id);
57+
expect(result.rows[0].comments).toEqual(Comments);
58+
expect(result.rows[0].ipAddress).toEqual(IpAddress);
6059
});
60+
});
6161

62-
describe('postNotes', () => {
63-
let result;
64-
let notes;
62+
describe('postNotes', () => {
63+
let result;
64+
let notes;
6565

66-
beforeEach(async () => {
67-
notes = 'bulletproof coffee';
68-
result = await sut.postNotes(database, id, notes);
69-
});
66+
beforeEach(async () => {
67+
notes = 'bulletproof coffee';
68+
result = await sut.postNotes(database, id, notes);
69+
});
7070

71-
it('should append, update true, database, id, and Comments to formData', () => {
72-
expect(fakeFormData.append).toHaveBeenCalledWith('update', 'true');
73-
expect(fakeFormData.append).toHaveBeenCalledWith('database', database);
74-
expect(fakeFormData.append).toHaveBeenCalledWith('id', `${id}`);
75-
expect(fakeFormData.append).toHaveBeenCalledWith('Comments', notes);
76-
});
71+
it('should append, update true, database, id, and Comments to formData', () => {
72+
expect(fakeFormData.append).toHaveBeenCalledWith('update', 'true');
73+
expect(fakeFormData.append).toHaveBeenCalledWith('database', database);
74+
expect(fakeFormData.append).toHaveBeenCalledWith('id', `${id}`);
75+
expect(fakeFormData.append).toHaveBeenCalledWith('notes', notes);
76+
});
7777

78-
it('should call fetch with correct route', () => {
79-
expect(apiClient.fetch).toHaveBeenCalledWith('/browse/allcrash.php', jasmine.anything());
80-
});
78+
it('should call fetch with correct route', () => {
79+
expect(apiClient.fetch).toHaveBeenCalledWith('/api/crash/notes.php', jasmine.anything());
80+
});
8181

82-
it('should call fetch with requestInit containing formData', () => {
83-
expect(apiClient.fetch).toHaveBeenCalledWith(
84-
jasmine.anything(),
85-
jasmine.objectContaining({
86-
method: 'POST',
87-
body: fakeFormData,
88-
cache: 'no-cache',
89-
credentials: 'include',
90-
redirect: 'follow'
91-
})
92-
);
93-
});
82+
it('should call fetch with requestInit containing formData', () => {
83+
expect(apiClient.fetch).toHaveBeenCalledWith(
84+
jasmine.anything(),
85+
jasmine.objectContaining({
86+
method: 'POST',
87+
body: fakeFormData,
88+
cache: 'no-cache',
89+
credentials: 'include',
90+
redirect: 'follow',
91+
})
92+
);
93+
});
9494

95-
it('should return result', () => {
96-
expect(result).toEqual(apiClientResponse);
97-
});
95+
it('should return result', () => {
96+
expect(result).toEqual(apiClientResponse);
9897
});
99-
});
98+
});
99+
});

src/crashes/crashes-api-client/crashes-api-client.ts

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,10 @@ export class CrashesApiClient {
1212
private _tableDataClient: TableDataClient;
1313

1414
constructor(private _client: ApiClient) {
15-
this._tableDataClient = new TableDataClient(
16-
this._client,
17-
'/api/crashes.php'
18-
);
15+
this._tableDataClient = new TableDataClient(this._client, '/api/crashes.php');
1916
}
2017

21-
async deleteCrashes(
22-
database: string,
23-
ids: number[]
24-
): Promise<BugSplatResponse> {
18+
async deleteCrashes(database: string, ids: number[]): Promise<BugSplatResponse> {
2519
const urlParams = new URLSearchParams({ database, ids: ids.join(',') });
2620
const request = {
2721
method: 'DELETE',
@@ -50,17 +44,12 @@ export class CrashesApiClient {
5044
};
5145
}
5246

53-
// TODO BG we should move this to an api/crash/notes endpoint and reture allcrash
54-
postNotes(
55-
database: string,
56-
id: number,
57-
notes: string
58-
): Promise<BugSplatResponse> {
47+
postNotes(database: string, id: number, notes: string): Promise<BugSplatResponse> {
5948
const formData = this._client.createFormData();
6049
formData.append('update', 'true');
6150
formData.append('database', database);
6251
formData.append('id', `${id}`);
63-
formData.append('Comments', notes);
52+
formData.append('notes', notes);
6453

6554
const request = {
6655
method: 'POST',
@@ -71,6 +60,6 @@ export class CrashesApiClient {
7160
duplex: 'half',
7261
} as RequestInit;
7362

74-
return this._client.fetch('/browse/allcrash.php', request);
63+
return this._client.fetch('/api/crash/notes.php', request);
7564
}
7665
}

0 commit comments

Comments
 (0)