Skip to content

Commit 80e2bde

Browse files
authored
fix: add sortOrder to table-data-request (#67)
Fixes #64
1 parent 638c2e7 commit 80e2bde

File tree

10 files changed

+52
-47
lines changed

10 files changed

+52
-47
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ export async function postNativeCrashAndSymbols(
2020
files
2121
);
2222

23+
return postNativeCrash(database, application, version);
24+
}
25+
26+
export async function postNativeCrash(
27+
database: string,
28+
application: string,
29+
version: string
30+
): Promise<number> {
2331
const crashFile = createUploadableFile('./spec/files/native/myConsoleCrasher.zip');
2432
const crashPostClient = new CrashPostClient(database);
2533
const postCrashResult = await crashPostClient.postCrash(

src/common/data/search/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,3 @@ export * from './filter-condition/filter-condition';
22
export { ApiDataFilterGroup } from './filter-group/api-data-filter-group';
33
export { FilterOperator } from './filter-operator/filter-operator';
44
export { ApiDataFilter } from './filter/api-data-filter';
5-
export { OrderFilter } from './order-filter/order-filter';
6-

src/common/data/search/order-filter/order-filter.spec.ts

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

src/common/data/search/order-filter/order-filter.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export { TableDataClient } from './table-data-client/table-data-client';
22
export { TableDataRequest } from './table-data-client/table-data-request';
33
export { TableDataResponse } from './table-data-client/table-data-response';
4-
export { TableDataFormDataBuilder } from './table-data-form-data-builder/table-data-form-data-builder';
4+
export { ColumnSortOrder } from './table-data-form-data-builder/column-sort-order';
5+
export { TableDataFormDataBuilder } from './table-data-form-data-builder/table-data-form-data-builder';
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ApiDataFilterGroup, OrderFilter } from '@common';
1+
import { ApiDataFilterGroup, ColumnSortOrder } from '@common';
22

33
export interface TableDataRequest {
44
database?: string;
@@ -7,5 +7,5 @@ export interface TableDataRequest {
77
page?: number;
88
pageSize?: number;
99
sortColumn?: string;
10-
sortOrder?: OrderFilter;
10+
sortOrder?: ColumnSortOrder;
1111
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export type ColumnSortOrder = 'asc' | 'desc' | '';

src/common/data/table-data/table-data-form-data-builder/table-data-form-data-builder.spec.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ApiDataFilter, ApiDataFilterGroup, OrderFilter } from '@common';
1+
import { ApiDataFilter, ApiDataFilterGroup } from '@common';
22
import { TableDataFormDataBuilder } from './table-data-form-data-builder';
33

44
describe('TableDataFormDataBuilder', () => {
@@ -121,18 +121,17 @@ describe('TableDataFormDataBuilder', () => {
121121

122122
describe('withSortOrder', () => {
123123
it('should add sortOrder', () => {
124-
const sortOrder = OrderFilter.ascending;
125-
const expectedSortOrder = 'asc';
124+
const sortOrder = 'asc';
126125

127126
const result = <FakeFormData><unknown>new TableDataFormDataBuilder(formDataFactory)
128127
.withSortOrder(sortOrder)
129128
.build();
130129

131-
expect(result.get('sortorder')).toEqual(expectedSortOrder);
130+
expect(result.get('sortorder')).toEqual(sortOrder);
132131
});
133132

134133
it('should not add sortorder if sortOrder is none', () => {
135-
const sortOrder = OrderFilter.none;
134+
const sortOrder = '';
136135

137136
const result = <FakeFormData><unknown>new TableDataFormDataBuilder(formDataFactory)
138137
.withSortOrder(sortOrder)

src/common/data/table-data/table-data-form-data-builder/table-data-form-data-builder.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

2-
import { ApiDataFilterGroup, OrderFilter } from '@common';
2+
import { ApiDataFilterGroup } from '@common';
33
import FormData from 'form-data';
4+
import { ColumnSortOrder } from './column-sort-order';
45

56
export class TableDataFormDataBuilder {
67

@@ -63,17 +64,9 @@ export class TableDataFormDataBuilder {
6364
return this;
6465
}
6566

66-
withSortOrder(sortOrder: OrderFilter | undefined): TableDataFormDataBuilder {
67+
withSortOrder(sortOrder: ColumnSortOrder | undefined): TableDataFormDataBuilder {
6768
if (sortOrder) {
68-
let translatedSortOrder;
69-
if (sortOrder === OrderFilter.none) {
70-
return this;
71-
} else if (sortOrder === OrderFilter.ascending) {
72-
translatedSortOrder = 'asc';
73-
} else if (sortOrder === OrderFilter.descending) {
74-
translatedSortOrder = 'desc';
75-
}
76-
this._formParts.sortorder = translatedSortOrder;
69+
this._formParts.sortorder = sortOrder;
7770
}
7871
return this;
7972
}

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

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { config } from '@spec/config';
2-
import { BugSplatApiClient } from '@common';
2+
import { ApiDataFilterGroup, BugSplatApiClient, FilterOperator } from '@common';
33
import { CrashApiClient } from '@crash';
44
import { CrashesApiClient } from '@crashes';
5-
import { postNativeCrashAndSymbols } from '@spec/files/native/post-native-crash';
5+
import { postNativeCrash, postNativeCrashAndSymbols } from '@spec/files/native/post-native-crash';
66

77
describe('CrashesApiClient', () => {
88
let crashClient: CrashApiClient;
@@ -30,9 +30,9 @@ describe('CrashesApiClient', () => {
3030
it('should return 200 and array of crashes', async () => {
3131
const database = config.database;
3232
const pageSize = 1;
33-
33+
3434
const result = await crashesClient.getCrashes({ database, pageSize });
35-
35+
3636
const row = result.rows.find(row => Number(row.id) === id);
3737
expect(result.rows).toBeTruthy();
3838
expect(result.rows.length).toEqual(pageSize);
@@ -45,21 +45,45 @@ describe('CrashesApiClient', () => {
4545
const database = config.database;
4646
const pageSize = 1;
4747
const columnGroups = ['stackKey'];
48-
48+
4949
const result = await crashesClient.getCrashes({ database, pageSize, columnGroups });
50-
50+
5151
const row = result.rows[0];
5252
expect(result.rows).toBeTruthy();
5353
expect(result.rows.length).toEqual(pageSize);
5454
expect(row?.groupByCount).toBeGreaterThanOrEqual(1);
5555
});
56+
57+
it('should return 200 with crashes sorted by sortColumn and sortOrder', async () => {
58+
const database = config.database;
59+
const pageSize = 2;
60+
const sortColumn = 'id';
61+
const sortOrder = 'asc';
62+
const newestCrashId = await postNativeCrash(
63+
config.database,
64+
application,
65+
version
66+
);
67+
const filterGroups = [ApiDataFilterGroup.fromColumnValues([`${id}`, `${newestCrashId}`], 'id', FilterOperator.or)];
68+
69+
const result = await crashesClient.getCrashes({
70+
database,
71+
filterGroups,
72+
pageSize,
73+
sortColumn,
74+
sortOrder
75+
});
76+
77+
const row = result.rows[0];
78+
expect(row.id).toEqual(id);
79+
});
5680
});
5781

5882
describe('postNotes', () => {
5983
it('should return 200', async () => {
6084
const database = config.database;
6185
const notes = 'BugSplat rocks!';
62-
86+
6387
await crashesClient.postNotes(database, id, notes);
6488
const result = await crashClient.getCrashById(database, id);
6589

0 commit comments

Comments
 (0)