Skip to content

Commit 859b96b

Browse files
authored
Replace BreadcrumbLevel and BreadcrumbType enums with String to accept arbitrary SDK values (#622)
* chore: Replace BreadcrumbLevel and BreadcrumbType enums with String to accept arbitrary SDK values * fix: tests * refactor: remove GitHub service mock * fix: import
1 parent 8c3059e commit 859b96b

7 files changed

Lines changed: 31 additions & 36 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "hawk.api",
3-
"version": "1.4.3",
3+
"version": "1.4.4",
44
"main": "index.ts",
55
"license": "BUSL-1.1",
66
"scripts": {

src/integrations/github/routes.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -522,15 +522,15 @@ export function createGitHubRouter(factories: ContextFactories): express.Router
522522
* just log query parameters and respond with 200 without signature validation.
523523
*/
524524
if (req.method !== 'POST') {
525+
// eslint-disable-next-line @typescript-eslint/camelcase, camelcase
525526
const { code, installation_id, setup_action, state, ...restQuery } = req.query as Record<string, unknown>;
526527

528+
// eslint-disable-next-line @typescript-eslint/camelcase, camelcase
527529
if (code || installation_id || state || setup_action) {
528-
// eslint-disable-next-line @typescript-eslint/camelcase, camelcase
529530
log('info', `${WEBHOOK_LOG_PREFIX}Received non-POST request on /webhook with OAuth-like params`, {
530-
// eslint-disable-next-line @typescript-eslint/camelcase, camelcase
531531
code,
532-
installation_id,
533-
setup_action,
532+
installation_id, // eslint-disable-line @typescript-eslint/camelcase, camelcase
533+
setup_action, // eslint-disable-line @typescript-eslint/camelcase, camelcase
534534
state,
535535
query: restQuery,
536536
});

src/resolvers/project.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ module.exports = {
421421
*/
422422
const taskManager = project.taskManager;
423423

424-
if (taskManager && taskManager.type === 'github' && taskManager.config?.installationId) {
424+
if (taskManager && taskManager.type === 'github' && taskManager.config && taskManager.config.installationId) {
425425
const githubService = new GitHubService();
426426

427427
await githubService.deleteInstallation(taskManager.config.installationId);

src/typeDefs/event.ts

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -116,29 +116,6 @@ type EventUser {
116116
photo: String
117117
}
118118
119-
"""
120-
Breadcrumb severity level
121-
"""
122-
enum BreadcrumbLevel {
123-
fatal
124-
error
125-
warning
126-
info
127-
debug
128-
}
129-
130-
"""
131-
Breadcrumb type - controls categorization and UI appearance
132-
"""
133-
enum BreadcrumbType {
134-
default
135-
request
136-
ui
137-
navigation
138-
logic
139-
error
140-
}
141-
142119
"""
143120
Single breadcrumb entry - represents an event that occurred before the error
144121
"""
@@ -149,9 +126,11 @@ type Breadcrumb {
149126
timestamp: Float!
150127
151128
"""
152-
Type of breadcrumb - controls UI categorization
129+
Type of breadcrumb - controls UI categorization.
130+
Common values: default, request, ui, navigation, logic, error.
131+
Accepts any string since SDK users may send custom types.
153132
"""
154-
type: BreadcrumbType
133+
type: String
155134
156135
"""
157136
Category of the event - more specific than type
@@ -164,9 +143,11 @@ type Breadcrumb {
164143
message: String
165144
166145
"""
167-
Severity level of the breadcrumb
146+
Severity level of the breadcrumb.
147+
Common values: fatal, error, warning, info, debug.
148+
Accepts any string since SDK users may send custom levels.
168149
"""
169-
level: BreadcrumbLevel
150+
level: String
170151
171152
"""
172153
Arbitrary key-value data associated with the breadcrumb

test/__mocks__/github-service.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const deleteInstallationMock = jest.fn().mockResolvedValue(undefined);
2+
3+
export const GitHubService = jest.fn().mockImplementation(() => ({
4+
deleteInstallation: deleteInstallationMock,
5+
}));

test/integrations/github-routes.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ describe('GitHub Routes - /integration/github/connect', () => {
480480

481481
expect(response.status).toBe(302);
482482
expect(response.body).toContain('http://localhost:8080/');
483-
expect(response.body).toContain('error=Missing+or+invalid+OAuth+code');
483+
expect(response.body).toContain('apiError=Missing+or+invalid+OAuth+code');
484484
});
485485

486486
it('should redirect with error when state is missing', async () => {
@@ -501,7 +501,7 @@ describe('GitHub Routes - /integration/github/connect', () => {
501501

502502
expect(response.status).toBe(302);
503503
expect(response.body).toContain('http://localhost:8080/');
504-
expect(response.body).toContain('error=Missing+or+invalid+state');
504+
expect(response.body).toContain('apiError=Missing+or+invalid+state');
505505
});
506506

507507
it('should redirect with error when state is invalid or expired', async () => {
@@ -525,7 +525,7 @@ describe('GitHub Routes - /integration/github/connect', () => {
525525

526526
expect(response.status).toBe(302);
527527
expect(response.body).toContain('http://localhost:8080/');
528-
expect(response.body).toContain('error=Invalid+or+expired+state');
528+
expect(response.body).toContain('apiError=Invalid+or+expired+state');
529529
expect(mockGetState).toHaveBeenCalledWith(state);
530530
});
531531

test/resolvers/project.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import { ObjectId } from 'mongodb';
33
import { ProjectDBScheme, ProjectTaskManagerConfig } from '@hawk.so/types';
44
import { ResolverContextWithUser } from '../../src/types/graphql';
55
import { ApolloError, UserInputError } from 'apollo-server-express';
6+
7+
jest.mock('../../src/integrations/github/service', () => require('../__mocks__/github-service'));
8+
// eslint-disable-next-line @typescript-eslint/no-var-requires
9+
import { deleteInstallationMock, GitHubService } from '../__mocks__/github-service';
10+
611
// @ts-expect-error - CommonJS module, TypeScript can't infer types properly
712
import projectResolverModule from '../../src/resolvers/project';
813

@@ -141,6 +146,8 @@ describe('Project Resolver - Task Manager Mutations', () => {
141146
)) as { taskManager: ProjectTaskManagerConfig | null };
142147

143148
expect(context.factories.projectsFactory.findById).toHaveBeenCalledWith(mockProject._id.toString());
149+
expect(GitHubService).toHaveBeenCalledTimes(1);
150+
expect(deleteInstallationMock).toHaveBeenCalledWith('123456');
144151
expect(mockProject.updateProject).toHaveBeenCalledWith({
145152
taskManager: null,
146153
});
@@ -217,6 +224,8 @@ describe('Project Resolver - Task Manager Mutations', () => {
217224
context
218225
)) as { taskManager: ProjectTaskManagerConfig | null };
219226

227+
expect(GitHubService).not.toHaveBeenCalled();
228+
expect(deleteInstallationMock).not.toHaveBeenCalled();
220229
expect(mockProject.updateProject).toHaveBeenCalledWith({
221230
taskManager: null,
222231
});

0 commit comments

Comments
 (0)