mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-01 14:38:48 +00:00
fix: Added setup for unit tests
This commit is contained in:
1 parent
10c03d599f
commit
f04d5ab79b
7 files changed
+3326
-61
No files matched your search
@@ -23,3 +23,4 @@ jobs:
|
||||
- run: bun install
|
||||
- run: bun run eslint
|
||||
- run: bun run build
|
||||
- run: bun run test
|
||||
@@ -24,3 +24,4 @@ jobs:
|
||||
- run: npm ci
|
||||
- run: npm run eslint
|
||||
- run: npm run build
|
||||
- run: npm run test
|
||||
@@ -2,6 +2,7 @@
|
||||
/.env
|
||||
/config/*.js
|
||||
!/config/default.js
|
||||
!/config/test.js
|
||||
/logs
|
||||
/logs/app-*.log
|
||||
/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
+73
-61
@@ -1,62 +1,74 @@
|
||||
{
|
||||
"name": "cadence-discord-bot",
|
||||
"version": "5.3.6",
|
||||
"description": "A free Discord music and audio bot.",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mariusbegby/cadence-discord-bot"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/mariusbegby/cadence-discord-bot/issues"
|
||||
},
|
||||
"homepage": "https://github.com/mariusbegby/cadence-discord-bot#readme",
|
||||
"author": {
|
||||
"name": "Marius Begby",
|
||||
"url": "https://github.com/mariusbegby"
|
||||
},
|
||||
"publisher": "mariusbegby",
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"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-no-ignore": "node ./dist/index.js | pino-pretty",
|
||||
"deploy": "node ./dist/utils/deploySlashCommands.js",
|
||||
"deploy-pretty": "node ./dist/utils/deploySlashCommands.js | pino-pretty --ignore environment,source,module,action,name,context,executionId,executionTime,shardId,guildId,interactionType",
|
||||
"bun-start": "bun ./src/index.ts",
|
||||
"bun-start-pretty": "bun ./src/index.ts | pino-pretty --ignore environment,source,module,action,name,context,executionId,executionTime,shardId,guildId,interactionType",
|
||||
"bun-start-pretty-no-ignore": "bun ./src/index.ts | pino-pretty",
|
||||
"bun-deploy": "bun ./src/utils/deploySlashCommands.ts",
|
||||
"bun-deploy-pretty": "bun ./src/utils/deploySlashCommands.ts | pino-pretty --ignore environment,source,module,action,name,context,executionId,executionTime,shardId,guildId,interactionType",
|
||||
"eslint": "eslint ./src",
|
||||
"build": "tsc"
|
||||
},
|
||||
"dependencies": {
|
||||
"@discord-player/extractor": "^4.4.3",
|
||||
"@discord-player/opus": "^0.1.2",
|
||||
"@discordjs/rest": "^2.0.1",
|
||||
"config": "^3.3.9",
|
||||
"discord-player": "^6.6.3",
|
||||
"discord-voip": "^0.1.2",
|
||||
"discord.js": "^14.13.0",
|
||||
"dotenv": "^16.3.1",
|
||||
"mediaplex": "^0.0.7",
|
||||
"node-os-utils": "^1.3.7",
|
||||
"pino": "^8.15.1",
|
||||
"pino-loki": "^2.1.3",
|
||||
"youtube-ext": "^1.1.14"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/config": "^3.3.1",
|
||||
"@types/node": "^20.6.0",
|
||||
"@types/node-os-utils": "^1.3.1",
|
||||
"@typescript-eslint/eslint-plugin": "^6.5.0",
|
||||
"@typescript-eslint/parser": "^6.5.0",
|
||||
"eslint": "^8.49.0",
|
||||
"eslint-config-prettier": "^9.0.0",
|
||||
"eslint-plugin-prettier": "^5.0.0",
|
||||
"prettier": "^3.0.3",
|
||||
"typescript": "^5.2.2"
|
||||
}
|
||||
{
|
||||
"name": "cadence-discord-bot",
|
||||
"version": "5.3.6",
|
||||
"description": "A free Discord music and audio bot.",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mariusbegby/cadence-discord-bot"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/mariusbegby/cadence-discord-bot/issues"
|
||||
},
|
||||
"homepage": "https://github.com/mariusbegby/cadence-discord-bot#readme",
|
||||
"author": {
|
||||
"name": "Marius Begby",
|
||||
"url": "https://github.com/mariusbegby"
|
||||
},
|
||||
"publisher": "mariusbegby",
|
||||
"license": "MIT",
|
||||
"main": "index.js",
|
||||
"jest": {
|
||||
"preset": "ts-jest",
|
||||
"testEnvironment": "node",
|
||||
"testMatch": [
|
||||
"**/__tests__/**/*.ts",
|
||||
"**/?(*.)+(spec|test).ts"
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"test": "jest",
|
||||
"test:watch": "jest --watch",
|
||||
"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-no-ignore": "node ./dist/index.js | pino-pretty",
|
||||
"deploy": "node ./dist/utils/deploySlashCommands.js",
|
||||
"deploy-pretty": "node ./dist/utils/deploySlashCommands.js | pino-pretty --ignore environment,source,module,action,name,context,executionId,executionTime,shardId,guildId,interactionType",
|
||||
"bun-start": "bun ./src/index.ts",
|
||||
"bun-start-pretty": "bun ./src/index.ts | pino-pretty --ignore environment,source,module,action,name,context,executionId,executionTime,shardId,guildId,interactionType",
|
||||
"bun-start-pretty-no-ignore": "bun ./src/index.ts | pino-pretty",
|
||||
"bun-deploy": "bun ./src/utils/deploySlashCommands.ts",
|
||||
"bun-deploy-pretty": "bun ./src/utils/deploySlashCommands.ts | pino-pretty --ignore environment,source,module,action,name,context,executionId,executionTime,shardId,guildId,interactionType",
|
||||
"eslint": "eslint ./src",
|
||||
"build": "tsc"
|
||||
},
|
||||
"dependencies": {
|
||||
"@discord-player/extractor": "^4.4.3",
|
||||
"@discord-player/opus": "^0.1.2",
|
||||
"@discordjs/rest": "^2.0.1",
|
||||
"config": "^3.3.9",
|
||||
"discord-player": "^6.6.3",
|
||||
"discord-voip": "^0.1.2",
|
||||
"discord.js": "^14.13.0",
|
||||
"dotenv": "^16.3.1",
|
||||
"mediaplex": "^0.0.7",
|
||||
"node-os-utils": "^1.3.7",
|
||||
"pino": "^8.15.1",
|
||||
"pino-loki": "^2.1.3",
|
||||
"youtube-ext": "^1.1.14"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/config": "^3.3.1",
|
||||
"@types/jest": "^29.5.4",
|
||||
"@types/node": "^20.6.0",
|
||||
"@types/node-os-utils": "^1.3.1",
|
||||
"@typescript-eslint/eslint-plugin": "^6.5.0",
|
||||
"@typescript-eslint/parser": "^6.5.0",
|
||||
"eslint": "^8.49.0",
|
||||
"eslint-config-prettier": "^9.0.0",
|
||||
"eslint-plugin-prettier": "^5.0.0",
|
||||
"jest": "^29.7.0",
|
||||
"prettier": "^3.0.3",
|
||||
"ts-jest": "^29.1.1",
|
||||
"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