Skip to content

Commit 898c309

Browse files
authored
fix!: remove oauth2 scope (#151)
* fix!: remove oauth2 scope * fix!: throw errors for non-success responses * chore: isErrorResponse paths * chore: remove extraneous notes update param * chore: export ErrorResponse from table-data * fix: better error message * fix: notes endpoint * fix: versions endpoint BREAKING CHANGE: improves crashes, summary, and version API error transparency.
1 parent 7fb18a8 commit 898c309

File tree

14 files changed

+365
-327
lines changed

14 files changed

+365
-327
lines changed

.prettierrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"bracketSpacing": true,
55
"trailingComma": "es5",
66
"printWidth": 100,
7-
"tabWidth": 2,
7+
"tabWidth": 4,
88
"useTabs": false,
99
"endOfLine": "lf"
1010
}

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"jasmineExplorer.nodeArgv": [
3+
"--no-experimental-strip-types",
34
"-r",
45
"ts-node/register",
56
"-r",

src/common/client/oauth-client-credentials-api-client/oauth-client-credentials-api-client.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ describe('OAuthClientCredentialsClient', () => {
5555
expect(fakeFormData.append).toHaveBeenCalledWith('grant_type', 'client_credentials');
5656
expect(fakeFormData.append).toHaveBeenCalledWith('client_id', clientId);
5757
expect(fakeFormData.append).toHaveBeenCalledWith('client_secret', clientSecret);
58-
expect(fakeFormData.append).toHaveBeenCalledWith('scope', 'restricted');
5958
expect((sut as any)._fetch).toHaveBeenCalledWith(
6059
jasmine.anything(),
6160
jasmine.objectContaining({

src/common/client/oauth-client-credentials-api-client/oauth-client-credentials-api-client.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export class OAuthClientCredentialsClient implements ApiClient {
3636
body.append('grant_type', 'client_credentials');
3737
body.append('client_id', this._clientId);
3838
body.append('client_secret', this._clientSecret);
39-
body.append('scope', 'restricted');
4039
const request = {
4140
method,
4241
body,

src/common/data/table-data/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { TableDataClient } from './table-data-client/table-data-client';
1+
export { TableDataClient, isSuccessResponse, isErrorResponse, ErrorResponse } 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';
44
export { ColumnSortOrder } from './table-data-form-data-builder/column-sort-order';
Lines changed: 148 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -1,148 +1,158 @@
11
import { TableDataClient } from '@common';
22
import * as TableDataFormDataBuilder from '../table-data-form-data-builder/table-data-form-data-builder';
3+
import { isErrorResponse } from './table-data-client';
34

45
describe('TableDataClient', () => {
5-
let dataTableFormDataBuilder;
6-
let url;
7-
let formData;
8-
let bugSplatApiClient;
9-
let response;
10-
11-
let service: TableDataClient;
12-
13-
beforeEach(() => {
14-
url = 'https://woot.com';
15-
formData = { form: 'data!' };
16-
response = [{ Rows: [{ yee: 'ha!' }], PageData: { woo: 'hoo!' } }];
17-
dataTableFormDataBuilder = jasmine.createSpyObj('DataTableFormDataBuilder', [
18-
'withDatabase',
19-
'withColumnGroups',
20-
'withFilterGroups',
21-
'withPage',
22-
'withPageSize',
23-
'withSortColumn',
24-
'withSortOrder',
25-
'build'
26-
]);
27-
dataTableFormDataBuilder.withDatabase.and.returnValue(dataTableFormDataBuilder);
28-
dataTableFormDataBuilder.withColumnGroups.and.returnValue(dataTableFormDataBuilder);
29-
dataTableFormDataBuilder.withFilterGroups.and.returnValue(dataTableFormDataBuilder);
30-
dataTableFormDataBuilder.withPage.and.returnValue(dataTableFormDataBuilder);
31-
dataTableFormDataBuilder.withPageSize.and.returnValue(dataTableFormDataBuilder);
32-
dataTableFormDataBuilder.withSortColumn.and.returnValue(dataTableFormDataBuilder);
33-
dataTableFormDataBuilder.withSortOrder.and.returnValue(dataTableFormDataBuilder);
34-
dataTableFormDataBuilder.build.and.returnValue(formData);
35-
spyOn(TableDataFormDataBuilder, 'TableDataFormDataBuilder').and.returnValue(dataTableFormDataBuilder);
36-
37-
const json = () => response;
38-
bugSplatApiClient = jasmine.createSpyObj('BugSplatApiClient', ['fetch']);
39-
bugSplatApiClient.fetch.and.resolveTo({ json });
40-
41-
service = new TableDataClient(bugSplatApiClient, url);
42-
});
43-
44-
it('should be created', () => {
45-
expect(service).toBeTruthy();
46-
});
47-
48-
describe('getData', () => {
49-
let database;
50-
let columnGroups;
51-
let filterGroups;
52-
let page;
53-
let pageSize;
54-
let sortColumn;
55-
let sortOrder;
56-
let result;
57-
58-
beforeEach(async () => {
59-
database = 'Black Rifle Coffee';
60-
columnGroups = ['group', 'group again'];
61-
filterGroups = ['filter', 'anotha 1'];
62-
page = 9;
63-
pageSize = 9001;
64-
sortColumn = 'sorty';
65-
sortOrder = 'mcOrder';
66-
const response = await service.postGetData({
67-
database,
68-
columnGroups,
69-
filterGroups,
70-
page,
71-
pageSize,
72-
sortColumn,
73-
sortOrder
74-
});
75-
result = await response.json();
6+
let dataTableFormDataBuilder;
7+
let url;
8+
let formData;
9+
let bugSplatApiClient;
10+
let response;
11+
12+
let service: TableDataClient;
13+
14+
beforeEach(() => {
15+
url = 'https://woot.com';
16+
formData = { form: 'data!' };
17+
response = { rows: [{ yee: 'ha!' }], pageData: { woo: 'hoo!' } };
18+
dataTableFormDataBuilder = jasmine.createSpyObj('DataTableFormDataBuilder', [
19+
'withDatabase',
20+
'withColumnGroups',
21+
'withFilterGroups',
22+
'withPage',
23+
'withPageSize',
24+
'withSortColumn',
25+
'withSortOrder',
26+
'build',
27+
]);
28+
dataTableFormDataBuilder.withDatabase.and.returnValue(dataTableFormDataBuilder);
29+
dataTableFormDataBuilder.withColumnGroups.and.returnValue(dataTableFormDataBuilder);
30+
dataTableFormDataBuilder.withFilterGroups.and.returnValue(dataTableFormDataBuilder);
31+
dataTableFormDataBuilder.withPage.and.returnValue(dataTableFormDataBuilder);
32+
dataTableFormDataBuilder.withPageSize.and.returnValue(dataTableFormDataBuilder);
33+
dataTableFormDataBuilder.withSortColumn.and.returnValue(dataTableFormDataBuilder);
34+
dataTableFormDataBuilder.withSortOrder.and.returnValue(dataTableFormDataBuilder);
35+
dataTableFormDataBuilder.build.and.returnValue(formData);
36+
spyOn(TableDataFormDataBuilder, 'TableDataFormDataBuilder').and.returnValue(
37+
dataTableFormDataBuilder
38+
);
39+
40+
const json = () => response;
41+
bugSplatApiClient = jasmine.createSpyObj('BugSplatApiClient', ['fetch']);
42+
bugSplatApiClient.fetch.and.resolveTo({ status: 200, json });
43+
44+
service = new TableDataClient(bugSplatApiClient, url);
7645
});
7746

78-
it('should call DataTaableFormDataBuilder with database', () => {
79-
expect(dataTableFormDataBuilder.withDatabase).toHaveBeenCalledWith(database);
47+
it('should be created', () => {
48+
expect(service).toBeTruthy();
8049
});
8150

82-
it('should call DatatableFormDataBuilder with columng groups', () => {
83-
expect(dataTableFormDataBuilder.withColumnGroups).toHaveBeenCalledWith(columnGroups);
51+
describe('getData', () => {
52+
let database;
53+
let columnGroups;
54+
let filterGroups;
55+
let page;
56+
let pageSize;
57+
let sortColumn;
58+
let sortOrder;
59+
let result;
60+
61+
beforeEach(async () => {
62+
database = 'Black Rifle Coffee';
63+
columnGroups = ['group', 'group again'];
64+
filterGroups = ['filter', 'anotha 1'];
65+
page = 9;
66+
pageSize = 9001;
67+
sortColumn = 'sorty';
68+
sortOrder = 'mcOrder';
69+
const response = await service.postGetData({
70+
database,
71+
columnGroups,
72+
filterGroups,
73+
page,
74+
pageSize,
75+
sortColumn,
76+
sortOrder,
77+
});
78+
if (isErrorResponse(response)) {
79+
throw new Error((await response.json()).message);
80+
}
81+
result = await response.json();
82+
});
83+
84+
it('should call DataTaableFormDataBuilder with database', () => {
85+
expect(dataTableFormDataBuilder.withDatabase).toHaveBeenCalledWith(database);
86+
});
87+
88+
it('should call DatatableFormDataBuilder with columng groups', () => {
89+
expect(dataTableFormDataBuilder.withColumnGroups).toHaveBeenCalledWith(columnGroups);
90+
});
91+
92+
it('should call DataTableFormDataBuilder with filter groups', () => {
93+
expect(dataTableFormDataBuilder.withFilterGroups).toHaveBeenCalledWith(filterGroups);
94+
});
95+
96+
it('should call DataTableFormDataBuilder with page', () => {
97+
expect(dataTableFormDataBuilder.withPage).toHaveBeenCalledWith(page);
98+
});
99+
100+
it('should call DataTableFormDataBuilder with page size', () => {
101+
expect(dataTableFormDataBuilder.withPageSize).toHaveBeenCalledWith(pageSize);
102+
});
103+
104+
it('should call DataTableFormDataBuilder with sort column', () => {
105+
expect(dataTableFormDataBuilder.withSortColumn).toHaveBeenCalledWith(sortColumn);
106+
});
107+
108+
it('should call DataTableFormDataBuilder with sort order', () => {
109+
expect(dataTableFormDataBuilder.withSortOrder).toHaveBeenCalledWith(sortOrder);
110+
});
111+
112+
it('should call build on DataTableFormDataBuilder', () => {
113+
expect(dataTableFormDataBuilder.build).toHaveBeenCalled();
114+
});
115+
116+
it('should call fetch with correct url', () => {
117+
expect(bugSplatApiClient.fetch).toHaveBeenCalledWith(url, jasmine.anything());
118+
});
119+
120+
it('should call fetch with form data from DataTableFormDataBuilder', () => {
121+
expect(bugSplatApiClient.fetch).toHaveBeenCalledWith(
122+
jasmine.anything(),
123+
jasmine.objectContaining({
124+
body: formData,
125+
})
126+
);
127+
});
128+
129+
it('should return value from api', () => {
130+
expect(result).toEqual(
131+
jasmine.objectContaining({
132+
rows: response.rows,
133+
pageData: response.pageData,
134+
})
135+
);
136+
});
137+
138+
it('should throw if api returns error response', async () => {
139+
const expectedErrorMessage = 'Internal Server Error';
140+
bugSplatApiClient.fetch.and.resolveTo({
141+
status: 500,
142+
message: expectedErrorMessage,
143+
});
144+
try {
145+
await service.postGetData({
146+
filterGroups,
147+
page,
148+
pageSize,
149+
sortColumn,
150+
sortOrder,
151+
});
152+
} catch (error: any) {
153+
expect(error).toBeInstanceOf(Error);
154+
expect(error.message).toBe(expectedErrorMessage);
155+
}
156+
});
84157
});
85-
86-
it('should call DataTableFormDataBuilder with filter groups', () => {
87-
expect(dataTableFormDataBuilder.withFilterGroups).toHaveBeenCalledWith(filterGroups);
88-
});
89-
90-
it('should call DataTableFormDataBuilder with page', () => {
91-
expect(dataTableFormDataBuilder.withPage).toHaveBeenCalledWith(page);
92-
});
93-
94-
it('should call DataTableFormDataBuilder with page size', () => {
95-
expect(dataTableFormDataBuilder.withPageSize).toHaveBeenCalledWith(pageSize);
96-
});
97-
98-
it('should call DataTableFormDataBuilder with sort column', () => {
99-
expect(dataTableFormDataBuilder.withSortColumn).toHaveBeenCalledWith(sortColumn);
100-
});
101-
102-
it('should call DataTableFormDataBuilder with sort order', () => {
103-
expect(dataTableFormDataBuilder.withSortOrder).toHaveBeenCalledWith(sortOrder);
104-
});
105-
106-
it('should call build on DataTableFormDataBuilder', () => {
107-
expect(dataTableFormDataBuilder.build).toHaveBeenCalled();
108-
});
109-
110-
it('should call fetch with correct url', () => {
111-
expect(bugSplatApiClient.fetch).toHaveBeenCalledWith(url, jasmine.anything());
112-
});
113-
114-
it('should call fetch with form data from DataTableFormDataBuilder', () => {
115-
expect(bugSplatApiClient.fetch).toHaveBeenCalledWith(
116-
jasmine.anything(),
117-
jasmine.objectContaining({
118-
body: formData
119-
})
120-
);
121-
});
122-
123-
it('should return value from api', () => {
124-
expect(result).toEqual(jasmine.objectContaining({
125-
rows: response[0].Rows,
126-
pageData: response[0].PageData
127-
}));
128-
});
129-
130-
it('should return empty array if api returns null', async () => {
131-
bugSplatApiClient.fetch.and.resolveTo({ json: () => null });
132-
133-
const response = await service.postGetData({
134-
filterGroups,
135-
page,
136-
pageSize,
137-
sortColumn,
138-
sortOrder
139-
});
140-
result = await response.json();
141-
142-
expect(result).toEqual(jasmine.objectContaining({
143-
rows: [],
144-
pageData: {}
145-
}));
146-
});
147-
});
148158
});

0 commit comments

Comments
 (0)