mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-04 14:38:49 +00:00
Merge pull request #220 from mariusbegby/jest
fix: Added setup for unit tests
This commit is contained in:
7 files changed
+3266
-1
No files matched your search
@@ -23,3 +23,4 @@ jobs:
|
|||||||
- run: bun install
|
- run: bun install
|
||||||
- run: bun run eslint
|
- run: bun run eslint
|
||||||
- run: bun run build
|
- run: bun run build
|
||||||
|
- run: bun run test
|
||||||
@@ -24,3 +24,4 @@ jobs:
|
|||||||
- run: npm ci
|
- run: npm ci
|
||||||
- run: npm run eslint
|
- run: npm run eslint
|
||||||
- run: npm run build
|
- run: npm run build
|
||||||
|
- run: npm run test
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
/.env
|
/.env
|
||||||
/config/*.js
|
/config/*.js
|
||||||
!/config/default.js
|
!/config/default.js
|
||||||
|
!/config/test.js
|
||||||
/logs
|
/logs
|
||||||
/logs/app-*.log
|
/logs/app-*.log
|
||||||
/cookies.json
|
/cookies.json
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
// Test environment configuration settings
|
||||||
|
// Will be used in unit tests
|
||||||
|
module.exports = {};
|
||||||
Generated
+3192
File diff suppressed because it is too large.
Load diff
+13
-1
@@ -17,8 +17,17 @@
|
|||||||
"publisher": "mariusbegby",
|
"publisher": "mariusbegby",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
|
"jest": {
|
||||||
|
"preset": "ts-jest",
|
||||||
|
"testEnvironment": "node",
|
||||||
|
"testMatch": [
|
||||||
|
"**/__tests__/**/*.ts",
|
||||||
|
"**/?(*.)+(spec|test).ts"
|
||||||
|
]
|
||||||
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "jest",
|
||||||
|
"test:watch": "jest --watch",
|
||||||
"start": "node ./dist/index.js",
|
"start": "node ./dist/index.js",
|
||||||
"start-pretty": "node ./dist/index.js | pino-pretty --ignore environment,source,module,action,name,context,executionId,executionTime,shardId,guildId,interactionType",
|
"start-pretty": "node ./dist/index.js | pino-pretty --ignore environment,source,module,action,name,context,executionId,executionTime,shardId,guildId,interactionType",
|
||||||
"start-pretty-no-ignore": "node ./dist/index.js | pino-pretty",
|
"start-pretty-no-ignore": "node ./dist/index.js | pino-pretty",
|
||||||
@@ -49,6 +58,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/config": "^3.3.1",
|
"@types/config": "^3.3.1",
|
||||||
|
"@types/jest": "^29.5.4",
|
||||||
"@types/node": "^20.6.0",
|
"@types/node": "^20.6.0",
|
||||||
"@types/node-os-utils": "^1.3.1",
|
"@types/node-os-utils": "^1.3.1",
|
||||||
"@typescript-eslint/eslint-plugin": "^6.5.0",
|
"@typescript-eslint/eslint-plugin": "^6.5.0",
|
||||||
@@ -56,7 +66,9 @@
|
|||||||
"eslint": "^8.49.0",
|
"eslint": "^8.49.0",
|
||||||
"eslint-config-prettier": "^9.0.0",
|
"eslint-config-prettier": "^9.0.0",
|
||||||
"eslint-plugin-prettier": "^5.0.0",
|
"eslint-plugin-prettier": "^5.0.0",
|
||||||
|
"jest": "^29.7.0",
|
||||||
"prettier": "^3.0.3",
|
"prettier": "^3.0.3",
|
||||||
|
"ts-jest": "^29.1.1",
|
||||||
"typescript": "^5.2.2"
|
"typescript": "^5.2.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
import { transformQuery } from '../utils/validation/searchQueryValidator';
|
||||||
|
|
||||||
|
describe('searchQueryValidator', () => {
|
||||||
|
it.each(['us', 'nb', 'intl', 'en-us', 'long-code'])(
|
||||||
|
'should transform country-based Spotify url to normal Spotify url',
|
||||||
|
async (countryCode) => {
|
||||||
|
const trackId = '5T8EDUDqKcs6OSOwEsfqG7';
|
||||||
|
const query: string = `https://open.spotify.com/${countryCode}/track/${trackId}`;
|
||||||
|
const transformedQuery: string = await transformQuery({ query, executionId: 'test' });
|
||||||
|
|
||||||
|
expect(transformedQuery).toBe(`https://open.spotify.com/track/${trackId}`);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
it.each(['a', 'abcde', 'looooong', 'a-b', 'abcde-abcde'])(
|
||||||
|
'should not transform Spotify url without matching country-code patterh to normal Spotify url',
|
||||||
|
async (path) => {
|
||||||
|
const trackId = '5T8EDUDqKcs6OSOwEsfqG7';
|
||||||
|
const query: string = `https://open.spotify.com/${path}/track/${trackId}`;
|
||||||
|
const transformedQuery: string = await transformQuery({ query, executionId: 'test' });
|
||||||
|
|
||||||
|
expect(transformedQuery).toBe(`https://open.spotify.com/${path}/track/${trackId}`);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
it.each(['1', '12', '123', '1234', '12345'])(
|
||||||
|
'should not transform Spotify url with numbers as path to normal Spotify url',
|
||||||
|
async (path) => {
|
||||||
|
const trackId = '5T8EDUDqKcs6OSOwEsfqG7';
|
||||||
|
const query: string = `https://open.spotify.com/${path}/track/${trackId}`;
|
||||||
|
const transformedQuery: string = await transformQuery({ query, executionId: 'test' });
|
||||||
|
|
||||||
|
expect(transformedQuery).toBe(`https://open.spotify.com/${path}/track/${trackId}`);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
['https://google.com', 'https://google.com'],
|
||||||
|
[
|
||||||
|
'https://open.spotify.comus/track/5T8EDUDqKcs6OSOwEsfqG7',
|
||||||
|
'https://open.spotify.comus/track/5T8EDUDqKcs6OSOwEsfqG7'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'https://open.spotify.com/ustrack/5T8EDUDqKcs6OSOwEsfqG7',
|
||||||
|
'https://open.spotify.com/ustrack/5T8EDUDqKcs6OSOwEsfqG7'
|
||||||
|
]
|
||||||
|
])('should return the same url if it is not a valid Spotify url', async (inputUrl, expectedUrl) => {
|
||||||
|
const executionId: string = 'test';
|
||||||
|
const transformedQuery: string = await transformQuery({ query: inputUrl, executionId });
|
||||||
|
|
||||||
|
expect(transformedQuery).toBe(expectedUrl);
|
||||||
|
});
|
||||||
|
|
||||||
|
// not numbers
|
||||||
|
});
|
||||||
Reference in new issue
Block a user