Skip to content

Commit 6fbc666

Browse files
committed
fix: tests
1 parent b31832b commit 6fbc666

File tree

5 files changed

+22
-8
lines changed

5 files changed

+22
-8
lines changed
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+
}));

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);

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');
8+
// eslint-disable-next-line @typescript-eslint/no-var-requires
9+
const { deleteInstallationMock, GitHubService } = require('../../src/integrations/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)