Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server-util-logger test #2484

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions packages/server/test/utils/logger.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { expressRequestLogger } from '../../src/utils/logger';

Check failure on line 1 in packages/server/test/utils/logger.test.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.15.0)

Delete `;`
import { Request, Response, NextFunction } from 'express';

Check failure on line 2 in packages/server/test/utils/logger.test.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.15.0)

Delete `;`

function runTest() {
const mockReq = {
method: 'GET',
url: '/api/v1/test-url',
body: {},
query: {},
params: {},
headers: {}
} as Partial<Request>; // a subset of Request in TypeScript

Check failure on line 12 in packages/server/test/utils/logger.test.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.15.0)

Delete `;`

const mockRes = {
status: (code: number) => {

Check failure on line 15 in packages/server/test/utils/logger.test.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.15.0)

Delete `·`
console.log(`Status set to ${code}`);

Check failure on line 16 in packages/server/test/utils/logger.test.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.15.0)

Unexpected console statement

Check failure on line 16 in packages/server/test/utils/logger.test.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.15.0)

Delete `;`
return mockRes;

Check failure on line 17 in packages/server/test/utils/logger.test.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.15.0)

Delete `;·`
},
send: (responseBody: any) => {
console.log(`Response body: ${responseBody}`);

Check failure on line 20 in packages/server/test/utils/logger.test.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.15.0)

Unexpected console statement

Check failure on line 20 in packages/server/test/utils/logger.test.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.15.0)

Delete `;`
}
} as Partial<Response>; // a subset of Response.

Check failure on line 22 in packages/server/test/utils/logger.test.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.15.0)

Delete `;`

const mockNext: NextFunction = () => console.log('next() called');

console.log('Running Test: Should call next() for a valid API call');
expressRequestLogger(mockReq as Request, mockRes as Response, mockNext);
}

runTest();
Loading