Skip to content

Commit

Permalink
test: Update test descriptions for HttpError Classes and middleware f…
Browse files Browse the repository at this point in the history
…unctions
  • Loading branch information
wajeht committed Nov 22, 2024
1 parent 948eb19 commit fa1f93f
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/ai.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('openAI', function () {
});
});

describe('claudeAI', function () {
describe('claudeAI', { concurrency: true }, function () {
const createMockAIService = (mockMessage: string | null) => ({
generate: mock.fn<(diff: string, apiKey?: string) => Promise<string | null>>(() =>
Promise.resolve(mockMessage),
Expand Down
12 changes: 6 additions & 6 deletions src/error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import assert from 'assert';
import { describe, it } from 'node:test';

describe('HttpError Classes', () => {
describe('HttpError Classes', { concurrency: true }, () => {
describe('HttpError', () => {
it('should set the statusCode and message correctly', () => {
const error = new HttpError(500, 'Oh no, something went wrong!');
Expand All @@ -24,7 +24,7 @@ describe('HttpError Classes', () => {
});
});

describe('ForbiddenError', () => {
describe('ForbiddenError', { concurrency: true }, () => {
it('should set the statusCode to 403 and message correctly', () => {
const error = new ForbiddenError('Forbidden');
assert.strictEqual(error.statusCode, 403);
Expand All @@ -38,7 +38,7 @@ describe('HttpError Classes', () => {
});
});

describe('UnauthorizedError', () => {
describe('UnauthorizedError', { concurrency: true }, () => {
it('should set the statusCode to 401 and message correctly', () => {
const error = new UnauthorizedError('Unauthorized');
assert.strictEqual(error.statusCode, 401);
Expand All @@ -52,7 +52,7 @@ describe('HttpError Classes', () => {
});
});

describe('NotFoundError', () => {
describe('NotFoundError', { concurrency: true }, () => {
it('should set the statusCode to 404 and message correctly', () => {
const error = new NotFoundError('Not Found');
assert.strictEqual(error.statusCode, 404);
Expand All @@ -66,7 +66,7 @@ describe('HttpError Classes', () => {
});
});

describe('ValidationError', () => {
describe('ValidationError', { concurrency: true }, () => {
it('should set the statusCode to 422 and message correctly', () => {
const error = new ValidationError('Validation Error');
assert.strictEqual(error.statusCode, 422);
Expand All @@ -80,7 +80,7 @@ describe('HttpError Classes', () => {
});
});

describe('UnimplementedFunctionError', () => {
describe('UnimplementedFunctionError', { concurrency: true }, () => {
it('should set the statusCode to 501 and message correctly', () => {
const error = new UnimplementedFunctionError('Function Not Implemented');
assert.strictEqual(error.statusCode, 501);
Expand Down
6 changes: 3 additions & 3 deletions src/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { describe, it, mock } from 'node:test';
import { AIService, CacheType, Provider } from './types';
import { getHealthzHandler, getIndexHandler, postGenerateCommitMessageHandler } from './handler';

describe('getHealthzHandler', () => {
describe('getHealthzHandler', { concurrency: true }, () => {
it('should return ok', () => {
const req = {
get: mock.fn((header: string) =>
Expand All @@ -32,7 +32,7 @@ describe('getHealthzHandler', () => {
});
});

describe('getIndexHandler', () => {
describe('getIndexHandler', { concurrency: true }, () => {
it('should return the commit.sh file with the correct headers', async () => {
const req = {
headers: {
Expand Down Expand Up @@ -223,7 +223,7 @@ describe('getIndexHandler', () => {
});
});

describe('postGenerateCommitMessageHandler', () => {
describe('postGenerateCommitMessageHandler', { concurrency: true }, () => {
const createMockAIService = (mockMessage: string | null) => ({
generate: mock.fn<(diff: string, apiKey?: string) => Promise<string | null>>(() =>
Promise.resolve(mockMessage),
Expand Down
6 changes: 3 additions & 3 deletions src/middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import assert from 'assert';
import { describe, it, mock } from 'node:test';
import { Request, Response, NextFunction } from 'express';

describe('limitIPsMiddleware', () => {
describe('limitIPsMiddleware', { concurrency: true }, () => {
it('should call next() if IP is allowed', () => {
const req = {} as Request;
const res = {} as Response;
Expand Down Expand Up @@ -72,7 +72,7 @@ describe('limitIPsMiddleware', () => {
});
});

describe('notFoundMiddleware', () => {
describe('notFoundMiddleware', { concurrency: true }, () => {
it('should throw NotFoundError', () => {
const req = {} as Request;
const res = {} as Response;
Expand All @@ -90,7 +90,7 @@ describe('notFoundMiddleware', () => {
});
});

describe('errorMiddleware', () => {
describe('errorMiddleware', { concurrency: true }, () => {
it('should return 403 for ForbiddenError', () => {
const req = {
headers: {
Expand Down
6 changes: 3 additions & 3 deletions src/router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ after((done) => {
mock.reset();
});

describe('GET /healthz', () => {
describe('GET /healthz', { concurrency: true }, () => {
it('should reach with content json', async () => {
const response = await fetch('http://localhost:3000/healthz', {
headers: {
Expand All @@ -36,7 +36,7 @@ describe('GET /healthz', () => {
});
});

describe('GET /', () => {
describe('GET /', { concurrency: true }, () => {
it('should return the script with domain replaced', async () => {
const readFileMock = mock.method(fs, 'readFile', async () => 'echo "http://localhost"');
const response = await fetch('http://localhost:3000/', {
Expand All @@ -55,7 +55,7 @@ describe('GET /', () => {
});
});

describe('POST /', () => {
describe('POST /', { concurrency: true }, () => {
it('should call OpenAI API and return a commit message', async () => {
const generateCommitMessageMock = mock.method(
openAI,
Expand Down
12 changes: 6 additions & 6 deletions src/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import assert from 'node:assert';
import { Request } from 'express';
import { describe, it, beforeEach, afterEach } from 'node:test';

describe('Cache', () => {
describe('Cache', { concurrency: true }, () => {
it('should set and get a value', () => {
cache.set('key1', 'value1');
assert.equal(cache.get('key1'), 'value1');
Expand All @@ -27,7 +27,7 @@ describe('Cache', () => {
});
});

describe('logger', () => {
describe('logger', { concurrency: true }, () => {
it('should log debug messages', () => {
const originalDebug = console.debug;
let output = '';
Expand Down Expand Up @@ -75,7 +75,7 @@ describe('logger', () => {
});
});

describe('extractDomain', () => {
describe('extractDomain', { concurrency: true }, () => {
it('should extract domain with port', () => {
const req = {
hostname: 'example.com',
Expand Down Expand Up @@ -116,7 +116,7 @@ describe('extractDomain', () => {
});
});

describe('getIpAddress', () => {
describe('getIpAddress', { concurrency: true }, () => {
it('should get IP address from x-forwarded-for header (string)', () => {
const req = {
headers: {
Expand Down Expand Up @@ -214,7 +214,7 @@ describe('getIpAddress', () => {
});
});

describe('getRandomElement', () => {
describe('getRandomElement', { concurrency: true }, () => {
it('should return an element from the list', () => {
const list = [1, 2, 3, 4, 5];
const element = getRandomElement(list);
Expand All @@ -233,7 +233,7 @@ describe('getRandomElement', () => {
});
});

describe('validateConfig', () => {
describe('validateConfig', { concurrency: true }, () => {
let originalLoggerError: (...args: any[]) => void;
let loggerOutput: string;

Expand Down

0 comments on commit fa1f93f

Please sign in to comment.