Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
b652102
move mocks to subfolder
mchangrh Sep 21, 2022
f5bafa2
add nyc output to gitignore
mchangrh Sep 25, 2022
3f470a7
add additional/missing tests
mchangrh Sep 21, 2022
f683ed4
add userCounter mocks and rearrange webhook path
mchangrh Sep 21, 2022
dd7656d
add lockCategories tests, getUserInfo
mchangrh Sep 21, 2022
e0be474
fix tokenUtils tests, skip if not configured
mchangrh Sep 21, 2022
0a102c1
add lockCategory tests and typo tweak
mchangrh Sep 21, 2022
6499381
add coverage reports to PostgreSQL tests
mchangrh Sep 21, 2022
a00048a
add getIP test cases, misc others
mchangrh Sep 21, 2022
7457b51
add getByHash tests, remove redundant check
mchangrh Sep 25, 2022
4761671
move patreon mock
mchangrh Sep 25, 2022
c0952c1
fix getTotalStats userCount
mchangrh Sep 25, 2022
9ca0872
add token tests
mchangrh Sep 25, 2022
005ae2c
add ignores for impossible cases
mchangrh Sep 25, 2022
8562dc2
lint fix
mchangrh Sep 25, 2022
506b657
add ignore next to catch errors
mchangrh Sep 25, 2022
a469f2f
add uniform parsing and catching for arrays, remove redundant check
mchangrh Sep 25, 2022
c34de1b
add 4xx tests
mchangrh Sep 25, 2022
a8ddae1
Merge branch 'master' of github.com:ajayyy/SponsorBlockServer into mo…
mchangrh Sep 29, 2022
d80be9e
Merge branch 'master' of https://github.com/ajayyy/SponsorBlockServer…
mchangrh Sep 30, 2022
9ef0eaf
add istanbul exclusions
mchangrh Oct 1, 2022
0b9e702
minor optimizations
mchangrh Oct 1, 2022
715d41f
getStatus, token tests and mocks
mchangrh Oct 1, 2022
d163b1d
shadowban tests
mchangrh Oct 1, 2022
67eb165
getSearchSegments tests
mchangrh Oct 1, 2022
95dd36a
getUserInfo and free chapters tests
mchangrh Oct 1, 2022
9286f16
add ingores to tokenUtils
mchangrh Oct 27, 2022
622511c
Merge branch 'master' of https://github.com/ajayyy/SponsorBlockServer…
mchangrh Oct 27, 2022
19289a1
test against new chapters access
mchangrh Oct 27, 2022
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
4 changes: 3 additions & 1 deletion .github/workflows/postgres-redis-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ jobs:
env:
TEST_POSTGRES: true
timeout-minutes: 5
run: npm test
run: npx nyc --silent npm test
- name: Generate coverage report
run: npm run cover:report
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ working
/dist/

# nyc coverage output
.nyc_output/
.nyc_output/
coverage/
11 changes: 10 additions & 1 deletion .nycrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
{
"extends": "@istanbuljs/nyc-config-typescript",
"check-coverage": false,
"ski-full": true,
"reporter": ["text", "html"],
"include": [
"src/**/*.ts"
],
"exclude": [
"src/routes/addUnlitedVideo.ts"
"src/routes/addUnlistedVideo.ts",
"src/cronjob/downvoteSegmentArchiveJob.ts",
"src/databases/*"
]
}
14 changes: 10 additions & 4 deletions ci.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
"globalSalt": "testSalt",
"adminUserID": "4bdfdc9cddf2c7d07a8a87b57bf6d25389fb75d1399674ee0e0938a6a60f4c3b",
"newLeafURLs": ["placeholder"],
"discordReportChannelWebhookURL": "http://127.0.0.1:8081/ReportChannelWebhook",
"discordFirstTimeSubmissionsWebhookURL": "http://127.0.0.1:8081/FirstTimeSubmissionsWebhook",
"discordCompletelyIncorrectReportWebhookURL": "http://127.0.0.1:8081/CompletelyIncorrectReportWebhook",
"discordNeuralBlockRejectWebhookURL": "http://127.0.0.1:8081/NeuralBlockRejectWebhook",
"discordReportChannelWebhookURL": "http://127.0.0.1:8081/webhook/ReportChannel",
"discordFirstTimeSubmissionsWebhookURL": "http://127.0.0.1:8081/webhook/FirstTimeSubmissions",
"discordCompletelyIncorrectReportWebhookURL": "http://127.0.0.1:8081/webhook/CompletelyIncorrectReport",
"discordNeuralBlockRejectWebhookURL": "http://127.0.0.1:8081/webhook/NeuralBlockReject",
"neuralBlockURL": "http://127.0.0.1:8081/NeuralBlock",
"userCounterURL": "http://127.0.0.1:8081/UserCounter",
"behindProxy": true,
"postgres": {
"user": "ci_db_user",
Expand Down Expand Up @@ -70,5 +71,10 @@
"statusCode": 200
}
},
"patreon": {
"clientId": "testClientID",
"clientSecret": "testClientSecret",
"redirectUri": "http://127.0.0.1/fake/callback"
},
"minReputationToSubmitFiller": -1
}
109 changes: 109 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "src/index.ts",
"scripts": {
"test": "npm run tsc && ts-node test/test.ts",
"test:coverage": "nyc npm run test",
"cover": "nyc npm test",
"cover:report": "nyc report",
"dev": "nodemon",
"dev:bash": "nodemon -x 'npm test ; npm start'",
"postgres:docker": "docker run --rm -p 5432:5432 -e POSTGRES_USER=ci_db_user -e POSTGRES_PASSWORD=ci_db_pass postgres:alpine",
Expand All @@ -32,15 +33,18 @@
"sync-mysql": "^3.0.1"
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.2",
"@types/better-sqlite3": "^7.5.0",
"@types/cron": "^2.0.0",
"@types/express": "^4.17.13",
"@types/lodash": "^4.14.182",
"@types/mocha": "^9.1.1",
"@types/node": "^18.0.3",
"@types/pg": "^8.6.5",
"@types/sinon": "^10.0.13",
"@typescript-eslint/eslint-plugin": "^5.30.6",
"@typescript-eslint/parser": "^5.30.6",
"axios-mock-adapter": "^1.21.2",
"eslint": "^8.19.0",
"mocha": "^10.0.0",
"nodemon": "^2.0.19",
Expand Down
1 change: 1 addition & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ function setupRoutes(router: Router) {
router.get("/api/generateToken/:type", generateTokenRequest);
router.get("/api/verifyToken", verifyTokenRequest);

/* istanbul ignore next */
if (config.postgres?.enabled) {
router.get("/database", (req, res) => dumpDatabase(req, res, true));
router.get("/database.json", (req, res) => dumpDatabase(req, res, false));
Expand Down
3 changes: 2 additions & 1 deletion src/routes/deleteLockCategories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export async function deleteLockCategoriesEndpoint(req: DeleteLockCategoriesRequ
|| !categories
|| !Array.isArray(categories)
|| categories.length === 0
|| actionTypes && !Array.isArray(actionTypes)
|| actionTypes.length === 0
) {
return res.status(400).json({
Expand All @@ -48,7 +49,7 @@ export async function deleteLockCategoriesEndpoint(req: DeleteLockCategoriesRequ

if (!userIsVIP) {
return res.status(403).json({
message: "Must be a VIP to mark videos.",
message: "Must be a VIP to lock videos.",
});
}

Expand Down
3 changes: 3 additions & 0 deletions src/routes/generateToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export async function generateTokenRequest(req: GenerateTokenRequest, res: Respo
if (type === TokenType.patreon || (type === TokenType.local && adminUserIDHash === config.adminUserID)) {
const licenseKey = await createAndSaveToken(type, code);

/* istanbul ignore else */
if (licenseKey) {
return res.status(200).send(`
<h1>
Expand All @@ -45,5 +46,7 @@ export async function generateTokenRequest(req: GenerateTokenRequest, res: Respo
</h1>
`);
}
} else {
return res.sendStatus(403);
}
}
6 changes: 5 additions & 1 deletion src/routes/getDaysSavedFormatted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ export async function getDaysSavedFormatted(req: Request, res: Response): Promis
if (row !== undefined) {
//send this result
return res.send({
daysSaved: row.daysSaved.toFixed(2),
daysSaved: row.daysSaved?.toFixed(2) ?? "0",
});
} else {
return res.send({
daysSaved: 0
});
}
}
2 changes: 1 addition & 1 deletion src/routes/getIsUserVIP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function getIsUserVIP(req: Request, res: Response): Promise<Respons
hashedUserID: hashedUserID,
vip: vipState,
});
} catch (err) {
} catch (err) /* istanbul ignore next */ {
Logger.error(err as string);
return res.sendStatus(500);
}
Expand Down
2 changes: 1 addition & 1 deletion src/routes/getLockCategories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function getLockCategories(req: Request, res: Response): Promise<Re
categories,
actionTypes
});
} catch (err) {
} catch (err) /* istanbul ignore next */{
Logger.error(err as string);
return res.sendStatus(500);
}
Expand Down
27 changes: 19 additions & 8 deletions src/routes/getLockCategoriesByHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,25 @@ const mergeLocks = (source: DBLock[], actionTypes: ActionType[]): LockResultByHa

export async function getLockCategoriesByHash(req: Request, res: Response): Promise<Response> {
let hashPrefix = req.params.prefix as VideoIDHash;
const actionTypes: ActionType[] = req.query.actionTypes
? JSON.parse(req.query.actionTypes as string)
: req.query.actionType
? Array.isArray(req.query.actionType)
? req.query.actionType
: [req.query.actionType]
: [ActionType.Skip, ActionType.Mute];
let actionTypes: ActionType[] = [];
try {
actionTypes = req.query.actionTypes
? JSON.parse(req.query.actionTypes as string)
: req.query.actionType
? Array.isArray(req.query.actionType)
? req.query.actionType
: [req.query.actionType]
: [ActionType.Skip, ActionType.Mute];
if (!Array.isArray(actionTypes)) {
//invalid request
return res.sendStatus(400);
}
} catch (err) {
//invalid request
return res.status(400).send("Invalid request: JSON parse error (actionTypes)");
}
if (!hashPrefixTester(req.params.prefix)) {

return res.status(400).send("Hash prefix does not match format requirements."); // Exit early on faulty prefix
}
hashPrefix = hashPrefix.toLowerCase() as VideoIDHash;
Expand All @@ -62,7 +73,7 @@ export async function getLockCategoriesByHash(req: Request, res: Response): Prom
if (lockedRows.length === 0 || !lockedRows[0]) return res.sendStatus(404);
// merge all locks
return res.send(mergeLocks(lockedRows, actionTypes));
} catch (err) {
} catch (err) /* istanbul ignore next */ {
Logger.error(err as string);
return res.sendStatus(500);
}
Expand Down
Loading