Skip to content

Commit

Permalink
Refactored tests to be compatible with VS CodeSense features
Browse files Browse the repository at this point in the history
  • Loading branch information
petruki committed Feb 25, 2024
1 parent 567f6b0 commit 09ab07f
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 46 deletions.
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
{
"deno.enable": true,
"deno.unstable": true
"deno.unstable": true,
"[typescript]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
},
"[typescriptreact]": {
"editor.defaultFormatter": "denoland.vscode-deno"
}
}
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ A remote document search engine that uses Skimming for Deno<br><br>

[![Master CI](https://github.com/switcherapi/switcher-searchdocs/actions/workflows/master.yml/badge.svg)](https://github.com/switcherapi/switcher-searchdocs/actions/workflows/master.yml)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=switcherapi_switcher-searchdocs&metric=alert_status)](https://sonarcloud.io/dashboard?id=switcherapi_switcher-searchdocs)
![Known Vulnerabilities](https://snyk.io/test/github/switcherapi/switcher-searchdocs/badge.svg)
[![Docker Hub](https://img.shields.io/docker/pulls/trackerforce/switcher-searchdocs.svg)](https://hub.docker.com/r/trackerforce/switcher-searchdocs)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Slack: Switcher-HQ](https://img.shields.io/badge/slack-@switcher/hq-blue.svg?logo=slack)](https://switcher-hq.slack.com/)
Expand Down
4 changes: 1 addition & 3 deletions test/middleware/helmet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import Helmet from '../../src/middleware/helmet.ts';
import { Context, Next } from '../../src/deps.ts';
import { assertEquals } from '../deps.ts';

const testTitle = (description: string) => `Helmet middleware - ${description}`;

const newRequest = () => {
return {
request: {
Expand All @@ -18,7 +16,7 @@ const newRequest = () => {
};

Deno.test({
name: testTitle('it should set the headers'),
name: 'Helmet middleware - it should set the headers',
async fn() {
const helmet = new Helmet();
const middleware = helmet.middleware();
Expand Down
6 changes: 2 additions & 4 deletions test/middleware/rate-limit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import RateLimit from '../../src/middleware/rate-limit.ts';
import { Context, Next } from '../../src/deps.ts';
import { assertEquals } from '../deps.ts';

const testTitle = (description: string) => `RateLimit middleware - ${description}`;

const newRequest = () => {
return {
request: {
Expand All @@ -18,7 +16,7 @@ const newRequest = () => {
};

Deno.test({
name: testTitle('it should return 429 error when limit is exceeded'),
name: 'RateLimit middleware - it should return 429 error when limit is exceeded',
async fn() {
const rateLimit = new RateLimit();
const middleware = rateLimit.middleware({
Expand All @@ -44,7 +42,7 @@ Deno.test({
});

Deno.test({
name: testTitle('it should reset counter after windowMs'),
name: 'RateLimit middleware - it should reset counter after windowMs',
async fn() {
const rateLimit = new RateLimit();
const middleware = rateLimit.middleware({
Expand Down
8 changes: 3 additions & 5 deletions test/routes/api.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import app from '../../src/app.ts';
import { assert, assertEquals, superoak } from '../deps.ts';

const testTitle = (description: string) => `API route - ${description}`;

Deno.test({
name: testTitle('it should return ok'),
name: 'API route - it should return ok',
async fn() {
const request = await superoak(app);
const response = await request.get('/api/check').expect(200);
Expand All @@ -30,7 +28,7 @@ Deno.test({
});

Deno.test({
name: testTitle('it should return ok - release time'),
name: 'API route - it should return ok - release time',
async fn() {
//given
Deno.env.set('RELEASE_TIME', 'tomorow');
Expand All @@ -44,7 +42,7 @@ Deno.test({
});

Deno.test({
name: testTitle('it should return ok - ssl enabled'),
name: 'API route - it should return ok - ssl enabled',
async fn() {
//given
Deno.env.set('SSL_CERT', 'cert');
Expand Down
6 changes: 2 additions & 4 deletions test/routes/searchdocs.functional.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import { SearchDocsQueryParams } from '../../src/dto/request.ts';
import { SearchDocsResponseDto } from '../../src/dto/response.ts';
import { assert, assertEquals, IResponse, superoak } from '../deps.ts';

const testTitle = (description: string) => `SearchDocs route - ${description}`;

Deno.test({
name: testTitle('it should return search results from cache on second request'),
name: 'SearchDocs route - it should return search results from cache on second request',
async fn() {
const searchParams = new URLSearchParams();
searchParams.append(SearchDocsQueryParams.query, 'Skimming');
Expand Down Expand Up @@ -35,7 +33,7 @@ Deno.test({
});

Deno.test({
name: testTitle('it should return search results from remote on second request - skipCache'),
name: 'SearchDocs route - it should return search results from remote on second request - skipCache',
async fn() {
const searchParams = new URLSearchParams();
searchParams.append(SearchDocsQueryParams.query, 'Skimming');
Expand Down
28 changes: 13 additions & 15 deletions test/routes/searchdocs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import { SearchDocsQueryParams } from '../../src/dto/request.ts';
import { SearchDocsResponseDto } from '../../src/dto/response.ts';
import { assert, assertEquals, IResponse, superoak } from '../deps.ts';

const testTitle = (description: string) => `SearchDocs route - ${description}`;

Deno.test({
name: testTitle('it should return search results'),
name: 'SearchDocs route - it should return search results',
async fn() {
const searchParams = new URLSearchParams();
searchParams.append(SearchDocsQueryParams.query, 'Skimming');
Expand All @@ -21,7 +19,7 @@ Deno.test({
});

Deno.test({
name: testTitle('it should return search results - using "previewLength"'),
name: 'SearchDocs route - it should return search results - using "previewLength"',
async fn() {
const searchParams = new URLSearchParams();
searchParams.append(SearchDocsQueryParams.query, 'Skimming');
Expand All @@ -39,7 +37,7 @@ Deno.test({
});

Deno.test({
name: testTitle('it should return search results - using "previewLength" with negative value (show line)'),
name: 'SearchDocs route - it should return search results - using "previewLength" with negative value (show line)',
async fn() {
const searchParams = new URLSearchParams();
searchParams.append(SearchDocsQueryParams.query, 'Skimming');
Expand All @@ -57,7 +55,7 @@ Deno.test({
});

Deno.test({
name: testTitle('it should NOT return search results - missing Query'),
name: 'SearchDocs route - it should NOT return search results - missing Query',
async fn() {
const request = await superoak(app);
const response = await request.get(`/`)
Expand All @@ -69,7 +67,7 @@ Deno.test({
});

Deno.test({
name: testTitle('it should NOT return search results - invalid "query" input'),
name: 'SearchDocs route - it should NOT return search results - invalid "query" input',
async fn() {
const searchParams = new URLSearchParams();
searchParams.append(SearchDocsQueryParams.query, 'A'.repeat(101));
Expand All @@ -84,7 +82,7 @@ Deno.test({
});

Deno.test({
name: testTitle('it should NOT return search results - invalid "previewLength" input'),
name: 'SearchDocs route - it should NOT return search results - invalid "previewLength" input',
async fn() {
const searchParams = new URLSearchParams();
searchParams.append(SearchDocsQueryParams.query, 'Skimming');
Expand All @@ -100,7 +98,7 @@ Deno.test({
});

Deno.test({
name: testTitle('it should NOT return search results - invalid "ignoreCase" input'),
name: 'SearchDocs route - it should NOT return search results - invalid "ignoreCase" input',
async fn() {
const searchParams = new URLSearchParams();
searchParams.append(SearchDocsQueryParams.query, 'Skimming');
Expand All @@ -116,7 +114,7 @@ Deno.test({
});

Deno.test({
name: testTitle('it should NOT return search results - invalid "url" input'),
name: 'SearchDocs route - it should NOT return search results - invalid "url" input',
async fn() {
const searchParams = new URLSearchParams();
searchParams.append(SearchDocsQueryParams.query, 'Skimming');
Expand All @@ -132,7 +130,7 @@ Deno.test({
});

Deno.test({
name: testTitle('it should NOT return search results - "url" input not allowed'),
name: 'SearchDocs route - it should NOT return search results - "url" input not allowed',
async fn() {
Deno.env.set('APP_ALLOW_URL', 'false');
Deno.env.set('APP_URL', '');
Expand All @@ -158,7 +156,7 @@ Deno.test({
});

Deno.test({
name: testTitle('it should NOT return search results - "files" input not allowed'),
name: 'SearchDocs route - it should NOT return search results - "files" input not allowed',
async fn() {
Deno.env.set('APP_ALLOW_FILES', 'false');
Deno.env.set('APP_FILES', '');
Expand All @@ -184,7 +182,7 @@ Deno.test({
});

Deno.test({
name: testTitle('it should NOT return search results - invalid "trimContent" input'),
name: 'SearchDocs route - it should NOT return search results - invalid "trimContent" input',
async fn() {
const searchParams = new URLSearchParams();
searchParams.append(SearchDocsQueryParams.query, 'Skimming');
Expand All @@ -200,7 +198,7 @@ Deno.test({
});

Deno.test({
name: testTitle('it should NOT return search results - invalid "regex" input'),
name: 'SearchDocs route - it should NOT return search results - invalid "regex" input',
async fn() {
const searchParams = new URLSearchParams();
searchParams.append(SearchDocsQueryParams.query, 'Skimming');
Expand All @@ -216,7 +214,7 @@ Deno.test({
});

Deno.test({
name: testTitle('it should NOT return search results - invalid "skipCache" input'),
name: 'SearchDocs route - it should NOT return search results - invalid "skipCache" input',
async fn() {
const searchParams = new URLSearchParams();
searchParams.append(SearchDocsQueryParams.query, 'Skimming');
Expand Down
8 changes: 3 additions & 5 deletions test/services/searchdocs.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import SearchDocsService from '../../src/services/searchdocs.ts';
import { assert, assertEquals } from '../deps.ts';

const testTitle = (description: string) => `SearchDocs service - ${description}`;

Deno.test({
name: testTitle('it should return a response with the search results - Remote'),
name: 'SearchDocs service - it should return a response with the search results - Remote',
async fn() {
//given
const service = new SearchDocsService({ expireDuration: 5, size: 100 });
Expand All @@ -27,7 +25,7 @@ Deno.test({
});

Deno.test({
name: testTitle('it should return a response with the search results - Local'),
name: 'SearchDocs service - it should return a response with the search results - Local',
async fn() {
//given
const service = new SearchDocsService({ expireDuration: 5, size: 100 });
Expand All @@ -49,7 +47,7 @@ Deno.test({
});

Deno.test({
name: testTitle('it should return a response segment with the search results - Local'),
name: 'SearchDocs service - it should return a response segment with the search results - Local',
async fn() {
//given
const service = new SearchDocsService({ expireDuration: 5, size: 100 });
Expand Down
14 changes: 6 additions & 8 deletions test/utils.logger.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { assert, assertEquals } from './deps.ts';
import { logger } from '../src/utils.ts';

const testTitle = (description: string) => `Utils (logger) - ${description}`;

const component = 'component';
const content = 'some content';

Deno.test({
name: testTitle('it should log INFO'),
name: 'Utils (logger) - it should log INFO',
fn() {
Deno.env.delete('LOG_LEVEL');
const log = logger('INFO', component, content);
Expand All @@ -16,7 +14,7 @@ Deno.test({
});

Deno.test({
name: testTitle('it should log INFO when level is DEBUG'),
name: 'Utils (logger) - it should log INFO when level is DEBUG',
fn() {
Deno.env.set('LOG_LEVEL', 'DEBUG');
const log = logger('INFO', component, content);
Expand All @@ -25,7 +23,7 @@ Deno.test({
});

Deno.test({
name: testTitle('it should NOT log DEBUG when level is INFO'),
name: 'Utils (logger) - it should NOT log DEBUG when level is INFO',
fn() {
Deno.env.set('LOG_LEVEL', 'INFO');
const log = logger('DEBUG', component, content);
Expand All @@ -34,7 +32,7 @@ Deno.test({
});

Deno.test({
name: testTitle('it should always log ERROR'),
name: 'Utils (logger) - it should always log ERROR',
fn() {
Deno.env.set('LOG_LEVEL', 'INFO');
const log = logger('ERROR', component, content);
Expand All @@ -43,15 +41,15 @@ Deno.test({
});

Deno.test({
name: testTitle('it should log ERROR object'),
name: 'Utils (logger) - it should log ERROR object',
fn() {
const log = logger('INFO', component, new Error(content), true);
assert(log);
},
});

Deno.test({
name: testTitle('it should log INFO JSON object'),
name: 'Utils (logger) - it should log INFO JSON object',
fn() {
const log = logger('INFO', component, {
foo: 'bar',
Expand Down

0 comments on commit 09ab07f

Please sign in to comment.