Merge pull request #201 from MRuy/remove-dependency-request

#177 Replace request with node-fetch
This commit is contained in:
Ajay Ramachandran
2021-01-17 21:05:10 -05:00
committed by GitHub
19 changed files with 1742 additions and 1828 deletions

291
package-lock.json generated
View File

@@ -257,17 +257,6 @@
}
}
},
"ajv": {
"version": "6.12.6",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz",
"integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==",
"requires": {
"fast-deep-equal": "^3.1.1",
"fast-json-stable-stringify": "^2.0.0",
"json-schema-traverse": "^0.4.1",
"uri-js": "^4.2.2"
}
},
"ansi-align": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ansi-align/-/ansi-align-2.0.0.tgz",
@@ -323,33 +312,11 @@
"resolved": "https://registry.npmjs.org/asap/-/asap-1.0.0.tgz",
"integrity": "sha1-sqRdpf36ILBJb8N2jMJ8EvqRan0="
},
"asn1": {
"version": "0.2.4",
"resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz",
"integrity": "sha512-jxwzQpLQjSmWXgwaCZE9Nz+glAG01yF1QnWgbhGwHI5A6FRIEY6IVqtHhIepHqI7/kyEyQEagBC5mBEFlIYvdg==",
"requires": {
"safer-buffer": "~2.1.0"
}
},
"assert-plus": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz",
"integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU="
},
"asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
},
"aws-sign2": {
"version": "0.7.0",
"resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz",
"integrity": "sha1-tG6JCTSpWR8tL2+G1+ap8bP+dqg="
},
"aws4": {
"version": "1.10.1",
"resolved": "https://registry.npmjs.org/aws4/-/aws4-1.10.1.tgz",
"integrity": "sha512-zg7Hz2k5lI8kb7U32998pRRFin7zJlkfezGJjUc2heaD4Pw2wObakCDVzkKztTm/Ln7eiVvYsjqak0Ed4LkMDA=="
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=",
"dev": true
},
"babel-runtime": {
"version": "6.26.0",
@@ -389,14 +356,6 @@
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.1.tgz",
"integrity": "sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g=="
},
"bcrypt-pbkdf": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz",
"integrity": "sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4=",
"requires": {
"tweetnacl": "^0.14.3"
}
},
"better-sqlite3": {
"version": "5.4.3",
"resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-5.4.3.tgz",
@@ -532,11 +491,6 @@
"integrity": "sha512-mYQLZnx5Qt1JgB1WEiMCf2647plpGeQ2NMR/5L0HNZzGQo4fuSPnK+wjfPnKZV0aiJDgzmWqqkV/g7JD+DW0qw==",
"dev": true
},
"caseless": {
"version": "0.12.0",
"resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz",
"integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw="
},
"chokidar": {
"version": "3.3.0",
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.3.0.tgz",
@@ -628,6 +582,7 @@
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
"dev": true,
"requires": {
"delayed-stream": "~1.0.0"
}
@@ -718,14 +673,6 @@
"integrity": "sha1-ojD2T1aDEOFJgAmUB5DsmVRbyn4=",
"dev": true
},
"dashdash": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz",
"integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=",
"requires": {
"assert-plus": "^1.0.0"
}
},
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
@@ -758,7 +705,8 @@
"delayed-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=",
"dev": true
},
"denque": {
"version": "1.4.1",
@@ -796,15 +744,6 @@
"integrity": "sha1-7gHdHKwO08vH/b6jfcCo8c4ALOI=",
"dev": true
},
"ecc-jsbn": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz",
"integrity": "sha1-OoOpBOVDUyh4dMVkt1SThoSamMk=",
"requires": {
"jsbn": "~0.1.0",
"safer-buffer": "^2.1.0"
}
},
"ecdsa-sig-formatter": {
"version": "1.0.11",
"resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz",
@@ -955,21 +894,6 @@
"resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz",
"integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g=="
},
"extsprintf": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz",
"integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU="
},
"fast-deep-equal": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
"integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q=="
},
"fast-json-stable-stringify": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz",
"integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw=="
},
"fast-text-encoding": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/fast-text-encoding/-/fast-text-encoding-1.0.3.tgz",
@@ -1016,11 +940,6 @@
"is-buffer": "~2.0.3"
}
},
"forever-agent": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz",
"integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE="
},
"form-data": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.0.tgz",
@@ -1114,14 +1033,6 @@
"integrity": "sha1-jpQ9E1jcN1VQVOy+LtsFqhdO3hQ=",
"dev": true
},
"getpass": {
"version": "0.1.7",
"resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz",
"integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=",
"requires": {
"assert-plus": "^1.0.0"
}
},
"glob": {
"version": "7.1.3",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz",
@@ -1271,20 +1182,6 @@
}
}
},
"har-schema": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz",
"integrity": "sha1-qUwiJOvKwEeCoNkDVSHyRzW37JI="
},
"har-validator": {
"version": "5.1.5",
"resolved": "https://registry.npmjs.org/har-validator/-/har-validator-5.1.5.tgz",
"integrity": "sha512-nmT2T0lljbxdQZfspsno9hgrG3Uir6Ks5afism62poxqBM6sDnMEuPmzTq8XN0OEwqKLLdh1jQI3qyE66Nzb3w==",
"requires": {
"ajv": "^6.12.3",
"har-schema": "^2.0.0"
}
},
"has": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz",
@@ -1329,16 +1226,6 @@
"toidentifier": "1.0.0"
}
},
"http-signature": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz",
"integrity": "sha1-muzZJRFHcvPZW2WmCruPfBj7rOE=",
"requires": {
"assert-plus": "^1.0.0",
"jsprim": "^1.2.2",
"sshpk": "^1.7.0"
}
},
"https-proxy-agent": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz",
@@ -1550,11 +1437,6 @@
"has-symbols": "^1.0.1"
}
},
"is-typedarray": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz",
"integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo="
},
"isarray": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
@@ -1572,11 +1454,6 @@
"resolved": "https://registry.npmjs.org/iso8601-duration/-/iso8601-duration-1.2.0.tgz",
"integrity": "sha512-ErTBd++b17E8nmWII1K1uZtBgD1E8RjyvwmxlCjPHNqHMD7gmcMHOw0E8Ro/6+QT4PhHRSnnMo7bxa1vFPkwhg=="
},
"isstream": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz",
"integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo="
},
"js-yaml": {
"version": "3.13.1",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.1.tgz",
@@ -1587,11 +1464,6 @@
"esprima": "^4.0.0"
}
},
"jsbn": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz",
"integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM="
},
"json-bigint": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/json-bigint/-/json-bigint-1.0.0.tgz",
@@ -1600,32 +1472,6 @@
"bignumber.js": "^9.0.0"
}
},
"json-schema": {
"version": "0.2.3",
"resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.2.3.tgz",
"integrity": "sha1-tIDIkuWaLwWVTOcnvT8qTogvnhM="
},
"json-schema-traverse": {
"version": "0.4.1",
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz",
"integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg=="
},
"json-stringify-safe": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz",
"integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus="
},
"jsprim": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.1.tgz",
"integrity": "sha1-MT5mvB5cwG5Di8G3SZwuXFastqI=",
"requires": {
"assert-plus": "1.0.0",
"extsprintf": "1.3.0",
"json-schema": "0.2.3",
"verror": "1.10.0"
}
},
"just-extend": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/just-extend/-/just-extend-4.1.1.tgz",
@@ -2072,11 +1918,6 @@
"path-key": "^2.0.0"
}
},
"oauth-sign": {
"version": "0.9.0",
"resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz",
"integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ=="
},
"object-inspect": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.7.0.tgz",
@@ -2204,11 +2045,6 @@
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
"integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w="
},
"performance-now": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz",
"integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns="
},
"picomatch": {
"version": "2.2.2",
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.2.2.tgz",
@@ -2257,22 +2093,12 @@
"integrity": "sha1-8FKijacOYYkX7wqKw0wa5aaChrM=",
"dev": true
},
"psl": {
"version": "1.8.0",
"resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz",
"integrity": "sha512-RIdOzyoavK+hA18OGGWDqUTsCLhtA7IcZ/6NCs4fFJaHBDab+pDDmDIByWFRQJq2Cd7r1OoQxBGKOaztq+hjIQ=="
},
"pstree.remy": {
"version": "1.1.7",
"resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.7.tgz",
"integrity": "sha512-xsMgrUwRpuGskEzBFkH8NmTimbZ5PcPup0LA8JJkHIm2IMUbQcpo3yeLNWVrufEYjh8YwtSVh0xz6UeWc5Oh5A==",
"dev": true
},
"punycode": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz",
"integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A=="
},
"qs": {
"version": "6.7.0",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz",
@@ -2368,50 +2194,6 @@
"rc": "^1.0.1"
}
},
"request": {
"version": "2.88.2",
"resolved": "https://registry.npmjs.org/request/-/request-2.88.2.tgz",
"integrity": "sha512-MsvtOrfG9ZcrOwAW+Qi+F6HbD0CWXEh9ou77uOb7FM2WPhwT7smM833PzanhJLsgXjN89Ir6V2PczXNnMpwKhw==",
"requires": {
"aws-sign2": "~0.7.0",
"aws4": "^1.8.0",
"caseless": "~0.12.0",
"combined-stream": "~1.0.6",
"extend": "~3.0.2",
"forever-agent": "~0.6.1",
"form-data": "~2.3.2",
"har-validator": "~5.1.3",
"http-signature": "~1.2.0",
"is-typedarray": "~1.0.0",
"isstream": "~0.1.2",
"json-stringify-safe": "~5.0.1",
"mime-types": "~2.1.19",
"oauth-sign": "~0.9.0",
"performance-now": "^2.1.0",
"qs": "~6.5.2",
"safe-buffer": "^5.1.2",
"tough-cookie": "~2.5.0",
"tunnel-agent": "^0.6.0",
"uuid": "^3.3.2"
},
"dependencies": {
"form-data": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz",
"integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==",
"requires": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.6",
"mime-types": "^2.1.12"
}
},
"qs": {
"version": "6.5.2",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz",
"integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA=="
}
}
},
"require-directory": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
@@ -2569,22 +2351,6 @@
"resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.1.tgz",
"integrity": "sha1-R1OT/56RR5rqYtyvDKPRSYOn+0A="
},
"sshpk": {
"version": "1.16.1",
"resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.1.tgz",
"integrity": "sha512-HXXqVUq7+pcKeLqqZj6mHFUMvXtOJt1uoUx09pFW6011inTMxqI8BA8PM95myrIyyKwdnzjdFjLiE6KBPVtJIg==",
"requires": {
"asn1": "~0.2.3",
"assert-plus": "^1.0.0",
"bcrypt-pbkdf": "^1.0.0",
"dashdash": "^1.12.0",
"ecc-jsbn": "~0.1.1",
"getpass": "^0.1.1",
"jsbn": "~0.1.0",
"safer-buffer": "^2.0.2",
"tweetnacl": "~0.14.0"
}
},
"statuses": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz",
@@ -2819,15 +2585,6 @@
"nopt": "~1.0.10"
}
},
"tough-cookie": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz",
"integrity": "sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g==",
"requires": {
"psl": "^1.1.28",
"punycode": "^2.1.1"
}
},
"ts-mock-imports": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/ts-mock-imports/-/ts-mock-imports-1.3.0.tgz",
@@ -2855,19 +2612,6 @@
}
}
},
"tunnel-agent": {
"version": "0.6.0",
"resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz",
"integrity": "sha1-J6XeoGs2sEoKmWZ3SykIaPD8QP0=",
"requires": {
"safe-buffer": "^5.0.1"
}
},
"tweetnacl": {
"version": "0.14.5",
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz",
"integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q="
},
"type-detect": {
"version": "4.0.8",
"resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz",
@@ -2972,21 +2716,6 @@
}
}
},
"uri-js": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.0.tgz",
"integrity": "sha512-B0yRTzYdUCCn9n+F4+Gh4yIDtMQcaJsmYBDsTSG8g/OejKBodLQ2IHfN3bM7jUsRXndopT7OIXWdYqc1fjmV6g==",
"requires": {
"punycode": "^2.1.0"
},
"dependencies": {
"punycode": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz",
"integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A=="
}
}
},
"url-parse-lax": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/url-parse-lax/-/url-parse-lax-1.0.0.tgz",
@@ -3021,16 +2750,6 @@
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
"integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw="
},
"verror": {
"version": "1.10.0",
"resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz",
"integrity": "sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=",
"requires": {
"assert-plus": "^1.0.0",
"core-util-is": "1.0.2",
"extsprintf": "^1.2.0"
}
},
"which": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz",

View File

@@ -20,7 +20,6 @@
"iso8601-duration": "^1.2.0",
"node-fetch": "^2.6.0",
"redis": "^3.0.2",
"request": "^2.88.2",
"sync-mysql": "^3.0.1",
"uuid": "^3.3.2",
"youtube-api": "^3.0.1"

View File

@@ -1,7 +1,8 @@
import {db} from '../databases/databases';
import request from 'request';
import {config} from '../config';
import {Request, Response} from 'express';
import fetch from 'node-fetch';
import {Logger} from '../utils/logger';
// A cache of the number of chrome web store users
let chromeUsersCache = 0;
@@ -41,30 +42,42 @@ export function getTotalStats(req: Request, res: Response) {
function updateExtensionUsers() {
if (config.userCounterURL) {
request.get(config.userCounterURL + "/api/v1/userCount", (err, response, body) => {
apiUsersCache = Math.max(apiUsersCache, JSON.parse(body).userCount);
});
fetch(config.userCounterURL + "/api/v1/userCount")
.then(res => res.json())
.then(data => {
apiUsersCache = Math.max(apiUsersCache, data.userCount);
})
.catch(() => Logger.debug("Failing to connect to user counter at: " + config.userCounterURL));
}
request.get("https://addons.mozilla.org/api/v3/addons/addon/sponsorblock/", function (err, firefoxResponse, body) {
try {
firefoxUsersCache = parseInt(JSON.parse(body).average_daily_users);
const mozillaAddonsUrl = "https://addons.mozilla.org/api/v3/addons/addon/sponsorblock/";
const chromeExtensionUrl = "https://chrome.google.com/webstore/detail/sponsorblock-for-youtube/mnjggcdmjocbbbhaepdhchncahnbgone";
request.get("https://chrome.google.com/webstore/detail/sponsorblock-for-youtube/mnjggcdmjocbbbhaepdhchncahnbgone", function (err, chromeResponse, body) {
if (body !== undefined) {
try {
chromeUsersCache = parseInt(body.match(/(?<=\<span class=\"e-f-ih\" title=\").*?(?= users\">)/)[0].replace(",", ""));
} catch (error) {
// Re-check later
lastUserCountCheck = 0;
}
} else {
lastUserCountCheck = 0;
}
});
} catch (error) {
// Re-check later
lastUserCountCheck = 0;
}
fetch(mozillaAddonsUrl)
.then(res => res.json())
.then(data => {
firefoxUsersCache = data.average_daily_users;
fetch(chromeExtensionUrl)
.then(res => res.text())
.then(body => {
// 2021-01-05
// [...]<span><meta itemprop="interactionCount" content="UserDownloads:100.000+"/><meta itemprop="opera[...]
const matchingString = '"UserDownloads:';
const matchingStringLen = matchingString.length;
const userDownloadsStartIndex = body.indexOf(matchingString);
if (userDownloadsStartIndex >= 0) {
const closingQuoteIndex = body.indexOf('"', userDownloadsStartIndex + matchingStringLen);
const userDownloadsStr = body.substr(userDownloadsStartIndex + matchingStringLen, closingQuoteIndex - userDownloadsStartIndex).replace(',','').replace('.','');
chromeUsersCache = parseInt(userDownloadsStr);
}
else {
lastUserCountCheck = 0;
}
})
.catch(() => Logger.debug("Failing to connect to " + chromeExtensionUrl));
})
.catch(err => {
Logger.debug("Failing to connect to " + mozillaAddonsUrl);
});
}

View File

@@ -3,9 +3,8 @@ import {Logger} from '../utils/logger';
import {db, privateDB} from '../databases/databases';
import {YouTubeAPI} from '../utils/youtubeApi';
import {getSubmissionUUID} from '../utils/getSubmissionUUID';
import request from 'request';
import isoDurations from 'iso8601-duration';
import fetch from 'node-fetch';
import isoDurations from 'iso8601-duration';
import {getHash} from '../utils/getHash';
import {getIP} from '../utils/getIP';
import {getFormattedTime} from '../utils/getFormattedTime';
@@ -64,8 +63,10 @@ function sendWebhooks(userID: string, videoID: string, UUID: string, segmentInfo
// If it is a first time submission
// Then send a notification to discord
if (config.discordFirstTimeSubmissionsWebhookURL === null || userSubmissionCountRow.submissionCount > 1) return;
request.post(config.discordFirstTimeSubmissionsWebhookURL, {
json: {
fetch(config.discordFirstTimeSubmissionsWebhookURL, {
method: 'POST',
body: JSON.stringify({
"embeds": [{
"title": data.items[0].snippet.title,
"url": "https://www.youtube.com/watch?v=" + videoID + "&t=" + (parseInt(startTime.toFixed(0)) - 2),
@@ -81,17 +82,19 @@ function sendWebhooks(userID: string, videoID: string, UUID: string, segmentInfo
"url": data.items[0].snippet.thumbnails.maxres ? data.items[0].snippet.thumbnails.maxres.url : "",
},
}],
},
}, (err, res) => {
if (err) {
Logger.error("Failed to send first time submission Discord hook.");
Logger.error(JSON.stringify(err));
Logger.error("\n");
} else if (res && res.statusCode >= 400) {
})
})
.then(res => {
if (res.status >= 400) {
Logger.error("Error sending first time submission Discord hook");
Logger.error(JSON.stringify(res));
Logger.error("\n");
}
})
.catch(err => {
Logger.error("Failed to send first time submission Discord hook.");
Logger.error(JSON.stringify(err));
Logger.error("\n");
});
});
}
@@ -114,8 +117,10 @@ function sendWebhooksNB(userID: string, videoID: string, UUID: string, startTime
// Send discord message
if (config.discordNeuralBlockRejectWebhookURL === null) return;
request.post(config.discordNeuralBlockRejectWebhookURL, {
json: {
fetch(config.discordNeuralBlockRejectWebhookURL, {
method: 'POST',
body: JSON.stringify({
"embeds": [{
"title": ytData.items[0].snippet.title,
"url": "https://www.youtube.com/watch?v=" + videoID + "&t=" + (parseFloat(startTime.toFixed(0)) - 2),
@@ -131,17 +136,19 @@ function sendWebhooksNB(userID: string, videoID: string, UUID: string, startTime
"url": ytData.items[0].snippet.thumbnails.maxres ? ytData.items[0].snippet.thumbnails.maxres.url : "",
},
}],
},
}, (err, res) => {
if (err) {
Logger.error("Failed to send NeuralBlock Discord hook.");
Logger.error(JSON.stringify(err));
Logger.error("\n");
} else if (res && res.statusCode >= 400) {
})
})
.then(res => {
if (res.status >= 400) {
Logger.error("Error sending NeuralBlock Discord hook");
Logger.error(JSON.stringify(res));
Logger.error("\n");
}
})
.catch(err => {
Logger.error("Failed to send NeuralBlock Discord hook.");
Logger.error(JSON.stringify(err));
Logger.error("\n");
});
}
@@ -229,15 +236,20 @@ async function autoModerateSubmission(submission: { videoID: any; userID: any; s
}
function proxySubmission(req: Request) {
request.post(config.proxySubmission + '/api/skipSegments?userID=' + req.query.userID + '&videoID=' + req.query.videoID, {json: req.body}, (err, result) => {
if (config.mode === 'development') {
if (!err) {
Logger.debug('Proxy Submission: ' + result.statusCode + ' (' + result.body + ')');
} else {
fetch(config.proxySubmission + '/api/skipSegments?userID=' + req.query.userID + '&videoID=' + req.query.videoID, {
method: 'POST',
body: req.body,
})
.then(async res => {
if (config.mode === 'development') {
Logger.debug('Proxy Submission: ' + res.status + ' (' + (await res.text()) + ')');
}
})
.catch(err => {
if (config.mode === 'development') {
Logger.error("Proxy Submission: Failed to make call");
}
}
});
});
}
export async function postSkipSegments(req: Request, res: Response) {

View File

@@ -1,7 +1,7 @@
import {Request, Response} from 'express';
import {Logger} from '../utils/logger';
import {isUserVIP} from '../utils/isUserVIP';
import request from 'request';
import fetch from 'node-fetch';
import {YouTubeAPI} from '../utils/youtubeApi';
import {db, privateDB} from '../databases/databases';
import {dispatchEvent, getVoteAuthor, getVoteAuthorRaw} from '../utils/webhookUtils';
@@ -89,8 +89,9 @@ function sendWebhooks(voteData: VoteData) {
// Send discord message
if (webhookURL !== null && !isUpvote) {
request.post(webhookURL, {
json: {
fetch(webhookURL, {
method: 'POST',
body: JSON.stringify({
"embeds": [{
"title": data.items[0].snippet.title,
"url": "https://www.youtube.com/watch?v=" + submissionInfoRow.videoID
@@ -112,17 +113,19 @@ function sendWebhooks(voteData: VoteData) {
"url": data.items[0].snippet.thumbnails.maxres ? data.items[0].snippet.thumbnails.maxres.url : "",
},
}],
},
}, (err, res) => {
if (err) {
Logger.error("Failed to send reported submission Discord hook.");
Logger.error(JSON.stringify(err));
Logger.error("\n");
} else if (res && res.statusCode >= 400) {
})
})
.then(async res => {
if (res.status >= 400) {
Logger.error("Error sending reported submission Discord hook");
Logger.error(JSON.stringify(res));
Logger.error(JSON.stringify((await res.text())));
Logger.error("\n");
}
})
.catch(err => {
Logger.error("Failed to send reported submission Discord hook.");
Logger.error(JSON.stringify(err));
Logger.error("\n");
});
}

View File

@@ -1,6 +1,6 @@
import {config} from '../config';
import {Logger} from '../utils/logger';
import request from 'request';
import fetch from 'node-fetch';
function getVoteAuthorRaw(submissionCount: number, isVIP: boolean, isOwnSubmission: boolean): string {
if (isOwnSubmission) {
@@ -36,14 +36,17 @@ function dispatchEvent(scope: string, data: any): void {
let scopes = webhook.scopes || [];
if (!scopes.includes(scope.toLowerCase())) return;
request.post(webhookURL, {
json: data, headers: {
fetch(webhookURL, {
method: 'POST',
body: JSON.stringify(data),
headers: {
"Authorization": authKey,
"Event-Type": scope, // Maybe change this in the future?
},
}).on('error', (e) => {
})
.catch(err => {
Logger.warn('Couldn\'t send webhook to ' + webhook.url);
Logger.warn(e.message);
Logger.warn(err);
});
});
}

View File

@@ -1,4 +1,4 @@
import request from 'request';
import fetch from 'node-fetch';
import {getbaseURL, Done} from '../utils';
import {db} from '../../src/databases/databases';
import {getHash} from '../../src/utils/getHash';
@@ -9,49 +9,47 @@ describe('getIsUserVIP', () => {
});
it('Should be able to get a 200', (done: Done) => {
request.get(getbaseURL()
+ "/api/isUserVIP?userID=supertestman", null,
(err, res) => {
if (err) done("couldn't call endpoint");
else if (res.statusCode !== 200) done("non 200: " + res.statusCode);
else done(); // pass
});
fetch(getbaseURL() + "/api/isUserVIP?userID=supertestman")
.then(res => {
if (res.status !== 200) done("non 200: " + res.status);
else done(); // pass
})
.catch(err => done("couldn't call endpoint"));
});
it('Should get a 400 if no userID', (done: Done) => {
request.get(getbaseURL()
+ "/api/isUserVIP", null,
(err, res) => {
if (err) done("couldn't call endpoint");
else if (res.statusCode !== 400) done("non 400: " + res.statusCode);
else done(); // pass
});
fetch(getbaseURL() + "/api/isUserVIP")
.then(res => {
if (res.status !== 400) done("non 400: " + res.status);
else done(); // pass
})
.catch(err => done("couldn't call endpoint"));
});
it('Should say a VIP is a VIP', (done: Done) => {
request.get(getbaseURL()
+ "/api/isUserVIP?userID=supertestman", null,
(err, res, body) => {
if (err) done("couldn't call endpoint");
else if (res.statusCode !== 200) done("non 200: " + res.statusCode);
else {
if (JSON.parse(body).vip === true) done(); // pass
else done("Result was non-vip when should have been vip");
}
});
fetch(getbaseURL() + "/api/isUserVIP?userID=supertestman")
.then(async res => {
if (res.status !== 200) done("non 200: " + res.status);
else {
const data = await res.json();
if (data.vip === true) done(); // pass
else done("Result was non-vip when should have been vip");
}
})
.catch(err => done("couldn't call endpoint"));
});
it('Should say a normal user is not a VIP', (done: Done) => {
request.get(getbaseURL()
+ "/api/isUserVIP?userID=regulartestman", null,
(err, res, body) => {
if (err) done("couldn't call endpoint");
else if (res.statusCode !== 200) done("non 200: " + res.statusCode);
else {
if (JSON.parse(body).vip === false) done(); // pass
else done("Result was vip when should have been non-vip");
}
});
fetch(getbaseURL() + "/api/isUserVIP?userID=regulartestman")
.then(async res => {
if (res.status !== 200) done("non 200: " + res.status);
else {
const data = await res.json();
if (data.vip === false) done(); // pass
else done("Result was vip when should have been non-vip");
}
})
.catch(err => done("couldn't call endpoint"));
});
});

View File

@@ -1,4 +1,4 @@
import request from 'request';
import fetch from 'node-fetch';
import {Done, getbaseURL} from '../utils';
import {db} from '../../src/databases/databases';
import {getHash} from '../../src/utils/getHash';
@@ -10,12 +10,11 @@ describe('getSavedTimeForUser', () => {
});
it('Should be able to get a 200', (done: Done) => {
request.get(getbaseURL()
+ "/api/getSavedTimeForUser?userID=testman", null,
(err, res) => {
if (err) done("couldn't call endpoint");
else if (res.statusCode !== 200) done("non 200");
else done(); // pass
});
fetch(getbaseURL() + "/api/getSavedTimeForUser?userID=testman")
.then(res => {
if (res.status !== 200) done("non 200");
else done(); // pass
})
.catch(err => done("couldn't call endpoint"));
});
});

View File

@@ -1,4 +1,4 @@
import request from 'request';
import fetch from 'node-fetch';
import {db} from '../../src/databases/databases';
import {Done, getbaseURL} from '../utils';
import {getHash} from '../../src/utils/getHash';
@@ -21,56 +21,47 @@ describe('getSegmentsByHash', () => {
});
it('Should be able to get a 200', (done: Done) => {
request.get(getbaseURL()
+ '/api/skipSegments/3272f?categories=["sponsor", "intro"]', null,
(err, res) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode !== 200) done("non 200 status code, was " + res.statusCode);
else {
done();
} // pass
});
fetch(getbaseURL() + '/api/skipSegments/3272f?categories=["sponsor", "intro"]')
.then(res => {
if (res.status !== 200) done("non 200 status code, was " + res.status);
else done(); // pass
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should return 404 if no segments are found even if a video for the given hash is known', (done: Done) => {
request.get(getbaseURL()
+ '/api/skipSegments/3272f?categories=["shilling"]', null,
(err, res, body) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode !== 404) done("non 404 status code, was " + res.statusCode);
else {
if (body === '[]') {
done(); // pass
} else {
done("Response had videos");
}
}
});
fetch(getbaseURL() + '/api/skipSegments/3272f?categories=["shilling"]')
.then(async res => {
if (res.status !== 404) done("non 404 status code, was " + res.status);
else {
const body = await res.text();
if (body === '[]') done(); // pass
else done("Response had videos");
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should be able to get an empty array if no videos', (done: Done) => {
request.get(getbaseURL()
+ '/api/skipSegments/11111?categories=["shilling"]', null,
(err, res, body) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode !== 404) done("non 404 status code, was " + res.statusCode);
else {
if (JSON.parse(body).length === 0 && body === '[]') done(); // pass
else done("non empty array returned");
}
});
fetch(getbaseURL() + '/api/skipSegments/11111?categories=["shilling"]')
.then(async res => {
if (res.status !== 404) done("non 404 status code, was " + res.status);
else {
const body = await res.text();
if (JSON.parse(body).length === 0 && body === '[]') done(); // pass
else done("non empty array returned");
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should return 400 prefix too short', (done: Done) => {
request.get(getbaseURL()
+ '/api/skipSegments/11?categories=["shilling"]', null,
(err, res) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode !== 400) done("non 400 status code, was " + res.statusCode);
else {
done(); // pass
}
});
fetch(getbaseURL() + '/api/skipSegments/11?categories=["shilling"]')
.then(res => {
if (res.status !== 400) done("non 400 status code, was " + res.status);
else done(); // pass
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should return 400 prefix too long', (done: Done) => {
@@ -79,120 +70,106 @@ describe('getSegmentsByHash', () => {
done('failed to generate a long enough string for the test ' + prefix.length);
return;
}
request.get(getbaseURL()
+ '/api/skipSegments/' + prefix + '?categories=["shilling"]', null,
(err, res) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode !== 400) done("non 400 status code, was " + res.statusCode);
else {
done(); // pass
}
});
fetch(getbaseURL() + '/api/skipSegments/' + prefix + '?categories=["shilling"]')
.then(res => {
if (res.status !== 400) done("non 400 status code, was " + res.status);
else done(); // pass
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should not return 400 prefix in range', (done: Done) => {
request.get(getbaseURL()
+ '/api/skipSegments/11111?categories=["shilling"]', null,
(err, res) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode === 400) done("prefix length 5 gave 400 " + res.statusCode);
else {
done(); // pass
}
});
fetch(getbaseURL() + '/api/skipSegments/11111?categories=["shilling"]')
.then(res => {
if (res.status === 400) done("prefix length 5 gave 400 " + res.status);
else done(); // pass
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should return 404 for no hash', (done: Done) => {
request.get(getbaseURL()
+ '/api/skipSegments/?categories=["shilling"]', null,
(err, res) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode !== 404) done("expected 404, got " + res.statusCode);
else {
done(); // pass
}
});
fetch(getbaseURL() + '/api/skipSegments/?categories=["shilling"]')
.then(res => {
if (res.status !== 404) done("expected 404, got " + res.status);
else done(); // pass
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should return 500 for bad format categories', (done: Done) => { // should probably be 400
request.get(getbaseURL()
+ '/api/skipSegments/?categories=shilling', null,
(err, res) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode !== 500) done("expected 500 got " + res.statusCode);
else {
done(); // pass
}
});
fetch(getbaseURL() + '/api/skipSegments/?categories=shilling')
.then(res => {
if (res.status !== 500) done("expected 500 got " + res.status);
else done(); // pass
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should be able to get multiple videos', (done: Done) => {
request.get(getbaseURL()
+ '/api/skipSegments/fdaf?categories=["sponsor","intro"]', null,
(err, res, body) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode !== 200) done("non 200 status code, was " + res.statusCode);
else {
body = JSON.parse(body);
if (body.length !== 2) done("expected 2 video, got " + body.length);
else if (body[0].segments.length !== 2) done("expected 2 segments for first video, got " + body[0].segments.length);
else if (body[1].segments.length !== 1) done("expected 1 segment for second video, got " + body[1].segments.length);
else done();
}
});
fetch(getbaseURL() + '/api/skipSegments/fdaf?categories=["sponsor","intro"]')
.then(async res => {
if (res.status !== 200) done("non 200 status code, was " + res.status);
else {
const body = await res.json();
if (body.length !== 2) done("expected 2 videos, got " + body.length);
else if (body[0].segments.length !== 2) done("expected 2 segments for first video, got " + body[0].segments.length);
else if (body[1].segments.length !== 1) done("expected 1 segment for second video, got " + body[1].segments.length);
else done();
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should be able to get 200 for no categories (default sponsor)', (done: Done) => {
request.get(getbaseURL()
+ '/api/skipSegments/fdaf', null,
(err, res, body) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode !== 200) done("non 200 status code, was " + res.statusCode);
else {
body = JSON.parse(body);
if (body.length !== 2) done("expected 2 videos, got " + body.length);
else if (body[0].segments.length !== 1) done("expected 1 segments for first video, got " + body[0].segments.length);
else if (body[1].segments.length !== 1) done("expected 1 segments for second video, got " + body[1].segments.length);
else if (body[0].segments[0].category !== 'sponsor' || body[1].segments[0].category !== 'sponsor') done("both segments are not sponsor");
else done();
}
});
fetch(getbaseURL() + '/api/skipSegments/fdaf')
.then(async res => {
if (res.status !== 200) done("non 200 status code, was " + res.status);
else {
const body = await res.json();
if (body.length !== 2) done("expected 2 videos, got " + body.length);
else if (body[0].segments.length !== 1) done("expected 1 segments for first video, got " + body[0].segments.length);
else if (body[1].segments.length !== 1) done("expected 1 segments for second video, got " + body[1].segments.length);
else if (body[0].segments[0].category !== 'sponsor' || body[1].segments[0].category !== 'sponsor') done("both segments are not sponsor");
else done();
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should be able to post a segment and get it using endpoint', (done: Done) => {
let testID = 'abc123goodVideo';
request.post(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
userID: "test",
videoID: testID,
segments: [{
segment: [13, 17],
category: "sponsor",
}],
},
fetch(getbaseURL() + "/api/postVideoSponsorTimes", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
(err, res) => {
if (err) done('(post) ' + err);
else if (res.statusCode === 200) {
request.get(getbaseURL()
+ '/api/skipSegments/' + getHash(testID, 1).substring(0, 3), null,
(err, res, body) => {
if (err) done("(get) Couldn't call endpoint");
else if (res.statusCode !== 200) done("(get) non 200 status code, was " + res.statusCode);
else {
body = JSON.parse(body);
if (body.length !== 1) done("(get) expected 1 video, got " + body.length);
else if (body[0].segments.length !== 1) done("(get) expected 1 segments for first video, got " + body[0].segments.length);
else if (body[0].segments[0].category !== 'sponsor') done("(get) segment should be sponsor, was " + body[0].segments[0].category);
else done();
}
});
} else {
done("(post) non 200 status code, was " + res.statusCode);
}
},
);
body: JSON.stringify({
userID: "test",
videoID: testID,
segments: [{
segment: [13, 17],
category: "sponsor",
}],
}),
})
.then(async res => {
if (res.status === 200) {
fetch(getbaseURL() + '/api/skipSegments/' + getHash(testID, 1).substring(0, 3))
.then(async res => {
if (res.status !== 200) done("(get) non 200 status code, was " + res.status);
else {
const body = await res.json();
if (body.length !== 1) done("(get) expected 1 video, got " + body.length);
else if (body[0].segments.length !== 1) done("(get) expected 1 segments for first video, got " + body[0].segments.length);
else if (body[0].segments[0].category !== 'sponsor') done("(get) segment should be sponsor, was " + body[0].segments[0].category);
else done();
}
})
.catch(err => done("(get) Couldn't call endpoint"));
} else {
done("(post) non 200 status code, was " + res.status);
}
})
.catch(err => done('(post) ' + err));
});
});

View File

@@ -1,4 +1,4 @@
import request from 'request';
import fetch from 'node-fetch';
import {db} from '../../src/databases/databases';
import {Done, getbaseURL} from '../utils';
import {getHash} from '../../src/utils/getHash';
@@ -17,200 +17,194 @@ describe('getSkipSegments', () => {
it('Should be able to get a time by category 1', (done: Done) => {
request.get(getbaseURL()
+ "/api/skipSegments?videoID=testtesttest&category=sponsor", null,
(err, res) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode !== 200) done("Status code was: " + res.statusCode);
else {
let data = JSON.parse(res.body);
if (data.length === 1 && data[0].segment[0] === 1 && data[0].segment[1] === 11
&& data[0].category === "sponsor" && data[0].UUID === "1-uuid-0") {
done();
} else {
done("Received incorrect body: " + res.body);
}
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&category=sponsor")
.then(async res => {
if (res.status !== 200) done("Status code was: " + res.status);
else {
const data = await res.json();
if (data.length === 1 && data[0].segment[0] === 1 && data[0].segment[1] === 11
&& data[0].category === "sponsor" && data[0].UUID === "1-uuid-0") {
done();
} else {
done("Received incorrect body: " + (await res.text()));
}
});
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should be able to get a time by category 2', (done: Done) => {
request.get(getbaseURL()
+ "/api/skipSegments?videoID=testtesttest&category=intro", null,
(err, res) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode !== 200) done("Status code was: " + res.statusCode);
else {
let data = JSON.parse(res.body);
if (data.length === 1 && data[0].segment[0] === 20 && data[0].segment[1] === 33
&& data[0].category === "intro" && data[0].UUID === "1-uuid-2") {
done();
} else {
done("Received incorrect body: " + res.body);
}
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&category=intro")
.then(async res => {
if (res.status !== 200) done("Status code was: " + res.status);
else {
const data = await res.json();
if (data.length === 1 && data[0].segment[0] === 20 && data[0].segment[1] === 33
&& data[0].category === "intro" && data[0].UUID === "1-uuid-2") {
done();
} else {
done("Received incorrect body: " + (await res.text()));
}
});
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should be able to get a time by categories array', (done: Done) => {
request.get(getbaseURL()
+ "/api/skipSegments?videoID=testtesttest&categories=[\"sponsor\"]", null,
(err, res) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode !== 200) done("Status code was: " + res.statusCode);
else {
let data = JSON.parse(res.body);
if (data.length === 1 && data[0].segment[0] === 1 && data[0].segment[1] === 11
&& data[0].category === "sponsor" && data[0].UUID === "1-uuid-0") {
done();
} else {
done("Received incorrect body: " + res.body);
}
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&categories=[\"sponsor\"]")
.then(async res => {
if (res.status !== 200) done("Status code was: " + res.status);
else {
const data = await res.json();
if (data.length === 1 && data[0].segment[0] === 1 && data[0].segment[1] === 11
&& data[0].category === "sponsor" && data[0].UUID === "1-uuid-0") {
done();
} else {
done("Received incorrect body: " + (await res.text()));
}
});
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should be able to get a time by categories array 2', (done: Done) => {
request.get(getbaseURL()
+ "/api/skipSegments?videoID=testtesttest&categories=[\"intro\"]", null,
(err, res) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode !== 200) done("Status code was: " + res.statusCode);
else {
let data = JSON.parse(res.body);
if (data.length === 1 && data[0].segment[0] === 20 && data[0].segment[1] === 33
&& data[0].category === "intro" && data[0].UUID === "1-uuid-2") {
done();
} else {
done("Received incorrect body: " + res.body);
}
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&categories=[\"intro\"]")
.then(async res => {
if (res.status !== 200) done("Status code was: " + res.status);
else {
const data = await res.json();
if (data.length === 1 && data[0].segment[0] === 20 && data[0].segment[1] === 33
&& data[0].category === "intro" && data[0].UUID === "1-uuid-2") {
done();
} else {
done("Received incorrect body: " + (await res.text()));
}
});
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should be able to get multiple times by category', (done: Done) => {
request.get(getbaseURL()
+ "/api/skipSegments?videoID=multiple&categories=[\"intro\"]", null,
(err, res) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode !== 200) done("Status code was: " + res.statusCode);
else {
let data = JSON.parse(res.body);
if (data.length === 2) {
let success = true;
for (const segment of data) {
if ((segment.segment[0] !== 20 || segment.segment[1] !== 33
|| segment.category !== "intro" || segment.UUID !== "1-uuid-7") &&
(segment.segment[0] !== 1 || segment.segment[1] !== 11
|| segment.category !== "intro" || segment.UUID !== "1-uuid-6")) {
success = false;
break;
}
fetch(getbaseURL() + "/api/skipSegments?videoID=multiple&categories=[\"intro\"]")
.then(async res => {
if (res.status !== 200) done("Status code was: " + res.status);
else {
const body = await res.text();
const data = JSON.parse(body);
if (data.length === 2) {
let success = true;
for (const segment of data) {
if ((segment.segment[0] !== 20 || segment.segment[1] !== 33
|| segment.category !== "intro" || segment.UUID !== "1-uuid-7") &&
(segment.segment[0] !== 1 || segment.segment[1] !== 11
|| segment.category !== "intro" || segment.UUID !== "1-uuid-6")) {
success = false;
break;
}
if (success) done();
else done("Received incorrect body: " + res.body);
} else {
done("Received incorrect body: " + res.body);
}
if (success) done();
else done("Received incorrect body: " + body);
} else {
done("Received incorrect body: " + body);
}
});
}
})
.catch(err => done("Couldn't call endpoint\n\n" + err));
});
it('Should be able to get multiple times by multiple categories', (done: Done) => {
request.get(getbaseURL()
+ "/api/skipSegments?videoID=testtesttest&categories=[\"sponsor\", \"intro\"]", null,
(err, res) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode !== 200) done("Status code was: " + res.statusCode);
else {
let data = JSON.parse(res.body);
if (data.length === 2) {
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&categories=[\"sponsor\", \"intro\"]")
.then(async res => {
if (res.status !== 200) done("Status code was: " + res.status);
else {
const body = await res.text();
const data = JSON.parse(body);
if (data.length === 2) {
let success = true;
for (const segment of data) {
if ((segment.segment[0] !== 20 || segment.segment[1] !== 33
|| segment.category !== "intro" || segment.UUID !== "1-uuid-2") &&
(segment.segment[0] !== 1 || segment.segment[1] !== 11
|| segment.category !== "sponsor" || segment.UUID !== "1-uuid-0")) {
success = false;
break;
}
let success = true;
for (const segment of data) {
if ((segment.segment[0] !== 20 || segment.segment[1] !== 33
|| segment.category !== "intro" || segment.UUID !== "1-uuid-2") &&
(segment.segment[0] !== 1 || segment.segment[1] !== 11
|| segment.category !== "sponsor" || segment.UUID !== "1-uuid-0")) {
success = false;
break;
}
if (success) done();
else done("Received incorrect body: " + res.body);
} else {
done("Received incorrect body: " + res.body);
}
if (success) done();
else done("Received incorrect body: " + body);
} else {
done("Received incorrect body: " + body);
}
});
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should be possible to send unexpected query parameters', (done: Done) => {
request.get(getbaseURL()
+ "/api/skipSegments?videoID=testtesttest&fakeparam=hello&category=sponsor", null,
(err, res) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode !== 200) done("Status code was: " + res.statusCode);
else {
let data = JSON.parse(res.body);
if (data.length === 1 && data[0].segment[0] === 1 && data[0].segment[1] === 11
&& data[0].category === "sponsor" && data[0].UUID === "1-uuid-0") {
done();
} else {
done("Received incorrect body: " + res.body);
}
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&fakeparam=hello&category=sponsor")
.then(async res => {
if (res.status !== 200) done("Status code was: " + res.status);
else {
const body = await res.text();
const data = JSON.parse(body);
if (data.length === 1 && data[0].segment[0] === 1 && data[0].segment[1] === 11
&& data[0].category === "sponsor" && data[0].UUID === "1-uuid-0") {
done();
} else {
done("Received incorrect body: " + body);
}
});
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Low voted submissions should be hidden', (done: Done) => {
request.get(getbaseURL()
+ "/api/skipSegments?videoID=test3&category=sponsor", null,
(err, res) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode !== 200) done("Status code was: " + res.statusCode);
else {
let data = JSON.parse(res.body);
if (data.length === 1 && data[0].segment[0] === 1 && data[0].segment[1] === 11
&& data[0].category === "sponsor" && data[0].UUID === "1-uuid-4") {
done();
} else {
done("Received incorrect body: " + res.body);
}
fetch(getbaseURL() + "/api/skipSegments?videoID=test3&category=sponsor")
.then(async res => {
if (res.status !== 200) done("Status code was: " + res.status);
else {
const body = await res.text();
const data = JSON.parse(body);
if (data.length === 1 && data[0].segment[0] === 1 && data[0].segment[1] === 11
&& data[0].category === "sponsor" && data[0].UUID === "1-uuid-4") {
done();
} else {
done("Received incorrect body: " + body);
}
});
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should return 404 if no segment found', (done: Done) => {
request.get(getbaseURL()
+ "/api/skipSegments?videoID=notarealvideo", null,
(err, res) => {
if (err) done("couldn't call endpoint");
else if (res.statusCode !== 404) done("non 404 respone code: " + res.statusCode);
else done(); // pass
});
fetch(getbaseURL() + "/api/skipSegments?videoID=notarealvideo")
.then(res => {
if (res.status !== 404) done("non 404 respone code: " + res.status);
else done(); // pass
})
.catch(err => done("couldn't call endpoint"));
});
it('Should be able send a comma in a query param', (done: Done) => {
request.get(getbaseURL()
+ "/api/skipSegments?videoID=testtesttest,test&category=sponsor", null,
(err, res) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode !== 200) done("Status code was: " + res.statusCode);
else {
let data = JSON.parse(res.body);
if (data.length === 1 && data[0].segment[0] === 1 && data[0].segment[1] === 11
&& data[0].category === "sponsor" && data[0].UUID === "1-uuid-1") {
done();
} else {
done("Received incorrect body: " + res.body);
}
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest,test&category=sponsor")
.then(async res => {
if (res.status !== 200) done("Status code was: " + res.status);
else {
const body = await res.text();
const data = JSON.parse(body);
if (data.length === 1 && data[0].segment[0] === 1 && data[0].segment[1] === 11
&& data[0].category === "sponsor" && data[0].UUID === "1-uuid-1") {
done();
} else {
done("Received incorrect body: " + body);
}
});
}
})
.catch(err => done("Couldn't call endpoint"));
});
});

View File

@@ -1,4 +1,4 @@
import request from 'request';
import fetch from 'node-fetch';
import {Done, getbaseURL} from '../utils';
import {db} from '../../src/databases/databases';
import {getHash} from '../../src/utils/getHash';
@@ -24,144 +24,101 @@ describe('getUserInfo', () => {
});
it('Should be able to get a 200', (done: Done) => {
request.get(getbaseURL()
+ '/api/getUserInfo?userID=getuserinfo_user_01', null,
(err, res) => {
if (err) {
done('couldn\'t call endpoint');
} else {
if (res.statusCode !== 200) {
done('non 200 (' + res.statusCode + ')');
} else {
done(); // pass
}
}
});
fetch(getbaseURL() + '/api/getUserInfo?userID=getuserinfo_user_01')
.then(res => {
if (res.status !== 200) done('non 200 (' + res.status + ')');
else done(); // pass
})
.catch(err => done('couldn\'t call endpoint'));
});
it('Should be able to get a 400 (No userID parameter)', (done: Done) => {
request.get(getbaseURL()
+ '/api/getUserInfo', null,
(err, res) => {
if (err) {
done('couldn\'t call endpoint');
} else {
if (res.statusCode !== 400) {
done('non 400');
} else {
done(); // pass
}
}
});
fetch(getbaseURL() + '/api/getUserInfo')
.then(res => {
if (res.status !== 400) done('non 400 (' + res.status + ')');
else done(); // pass
})
.catch(err => done('couldn\'t call endpoint'));
});
it('Should return info', (done: Done) => {
request.get(getbaseURL()
+ '/api/getUserInfo?userID=getuserinfo_user_01', null,
(err, res, body) => {
if (err) {
done("couldn't call endpoint");
fetch(getbaseURL() + '/api/getUserInfo?userID=getuserinfo_user_01')
.then(async res => {
if (res.status !== 200) {
done("non 200");
} else {
const data = await res.json();
if (data.userName !== 'Username user 01') {
done('Returned incorrect userName "' + data.userName + '"');
} else if (data.minutesSaved !== 5) {
done('Returned incorrect minutesSaved "' + data.minutesSaved + '"');
} else if (data.viewCount !== 30) {
done('Returned incorrect viewCount "' + data.viewCount + '"');
} else if (data.segmentCount !== 3) {
done('Returned incorrect segmentCount "' + data.segmentCount + '"');
} else {
if (res.statusCode !== 200) {
done("non 200");
} else {
const data = JSON.parse(body);
if (data.userName !== 'Username user 01') {
done('Returned incorrect userName "' + data.userName + '"');
} else if (data.minutesSaved !== 5) {
done('Returned incorrect minutesSaved "' + data.minutesSaved + '"');
} else if (data.viewCount !== 30) {
done('Returned incorrect viewCount "' + data.viewCount + '"');
} else if (data.segmentCount !== 3) {
done('Returned incorrect segmentCount "' + data.segmentCount + '"');
} else {
done(); // pass
}
}
done(); // pass
}
});
}
})
.catch(err => done("couldn't call endpoint"));
});
it('Should get warning data', (done: Done) => {
request.get(getbaseURL()
+ '/api/getUserInfo?userID=getuserinfo_warning_0', null,
(err, res, body) => {
if (err) {
done("couldn't call endpoint");
} else {
if (res.statusCode !== 200) {
done("non 200");
} else {
const data = JSON.parse(body);
if (data.warnings !== 1) {
done('wrong number of warnings: ' + data.warnings + ', not ' + 1);
} else {
done(); // pass
}
}
}
});
fetch(getbaseURL() + '/api/getUserInfo?userID=getuserinfo_warning_0')
.then(async res => {
if (res.status !== 200) {
done('non 200 (' + res.status + ')');
} else {
const data = await res.json();;
if (data.warnings !== 1) done('wrong number of warnings: ' + data.warnings + ', not ' + 1);
else done(); // pass
}
})
.catch(err => done("couldn't call endpoint"));
});
it('Should get multiple warnings', (done: Done) => {
request.get(getbaseURL()
+ '/api/getUserInfo?userID=getuserinfo_warning_1', null,
(err, res, body) => {
if (err) {
done("couldn't call endpoint");
} else {
if (res.statusCode !== 200) {
done("non 200");
} else {
const data = JSON.parse(body);
if (data.warnings !== 2) {
done('wrong number of warnings: ' + data.warnings + ', not ' + 2);
} else {
done(); // pass
}
}
}
});
fetch(getbaseURL() + '/api/getUserInfo?userID=getuserinfo_warning_1')
.then(async res => {
if (res.status !== 200) {
done('non 200 (' + res.status + ')');
} else {
const data = await res.json();
if (data.warnings !== 2) done('wrong number of warnings: ' + data.warnings + ', not ' + 2);
else done(); // pass
}
})
.catch(err => done("couldn't call endpoint"));
});
it('Should not get warnings if noe', (done: Done) => {
request.get(getbaseURL()
+ '/api/getUserInfo?userID=getuserinfo_warning_2', null,
(err, res, body) => {
if (err) {
done("couldn't call endpoint");
} else {
if (res.statusCode !== 200) {
done("non 200");
} else {
const data = JSON.parse(body);
if (data.warnings !== 0) {
done('wrong number of warnings: ' + data.warnings + ', not ' + 0);
} else {
done(); // pass
}
}
}
});
fetch(getbaseURL() + '/api/getUserInfo?userID=getuserinfo_warning_2')
.then(async res => {
if (res.status !== 200) {
done('non 200 (' + res.status + ')');
} else {
const data = await res.json();
if (data.warnings !== 0) done('wrong number of warnings: ' + data.warnings + ', not ' + 0);
else done(); // pass
}
})
.catch(err => done("couldn't call endpoint"));
});
it('Should return userID for userName (No userName set)', (done: Done) => {
request.get(getbaseURL()
+ '/api/getUserInfo?userID=getuserinfo_user_02', null,
(err, res, body) => {
if (err) {
done('couldn\'t call endpoint');
} else {
if (res.statusCode !== 200) {
done('non 200');
} else {
const data = JSON.parse(body);
if (data.userName !== 'c2a28fd225e88f74945794ae85aef96001d4a1aaa1022c656f0dd48ac0a3ea0f') {
return done('Did not return userID for userName');
}
done(); // pass
}
fetch(getbaseURL() + '/api/getUserInfo?userID=getuserinfo_user_02')
.then(async res => {
if (res.status !== 200) {
done('non 200 (' + res.status + ')');
} else {
const data = await res.json();
if (data.userName !== 'c2a28fd225e88f74945794ae85aef96001d4a1aaa1022c656f0dd48ac0a3ea0f') {
return done('Did not return userID for userName');
}
});
done(); // pass
}
})
.catch(err => done('couldn\'t call endpoint'));
});
});

View File

@@ -1,4 +1,4 @@
import request from 'request';
import fetch from 'node-fetch';
import {Done, getbaseURL} from '../utils';
import {getHash} from '../../src/utils/getHash';
import {db} from '../../src/databases/databases';
@@ -48,21 +48,28 @@ describe('noSegmentRecords', () => {
],
};
request.post(getbaseURL()
+ "/api/noSegments", {json},
(err, res, body) => {
if (err) done(err);
else if (res.statusCode === 200) {
if (JSON.stringify(body) === JSON.stringify(expected)) {
done();
} else {
done("Incorrect response: expected " + JSON.stringify(expected) + " got " + JSON.stringify(body));
}
fetch(getbaseURL() + "/api/noSegments", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json)
})
.then(async res => {
if (res.status === 200) {
const data = await res.json();
if (JSON.stringify(data) === JSON.stringify(expected)) {
done();
} else {
console.log(body);
done("Status code was " + res.statusCode);
done("Incorrect response: expected " + JSON.stringify(expected) + " got " + JSON.stringify(data));
}
});
} else {
const body = await res.text();
console.log(body);
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should be able to submit categories not in video (sql check)', (done: Done) => {
@@ -79,23 +86,29 @@ describe('noSegmentRecords', () => {
],
};
request.post(getbaseURL()
+ "/api/noSegments", {json},
(err, res, body) => {
if (err) done(err);
else if (res.statusCode === 200) {
let result = db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['no-segments-video-id-1']);
if (result.length !== 4) {
console.log(result);
done("Expected 4 entrys in db, got " + result.length);
} else {
done();
}
fetch(getbaseURL() + "/api/noSegments", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json)
})
.then(async res => {
if (res.status === 200) {
let result = db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['no-segments-video-id-1']);
if (result.length !== 4) {
console.log(result);
done("Expected 4 entrys in db, got " + result.length);
} else {
console.log(body);
done("Status code was " + res.statusCode);
done();
}
});
} else {
const body = await res.text();
console.log(body);
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should be able to submit categories with _ in the category', (done: Done) => {
@@ -107,23 +120,29 @@ describe('noSegmentRecords', () => {
],
};
request.post(getbaseURL()
+ "/api/noSegments", {json},
(err, res, body) => {
if (err) done(err);
else if (res.statusCode === 200) {
let result = db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['underscore']);
if (result.length !== 1) {
console.log(result);
done("Expected 1 entrys in db, got " + result.length);
} else {
done();
}
fetch(getbaseURL() + "/api/noSegments", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json),
})
.then(async res => {
if (res.status === 200) {
let result = db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['underscore']);
if (result.length !== 1) {
console.log(result);
done("Expected 1 entrys in db, got " + result.length);
} else {
console.log(body);
done("Status code was " + res.statusCode);
done();
}
});
} else {
const body = await res.text();
console.log(body);
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should be able to submit categories with upper and lower case in the category', (done: Done) => {
@@ -135,23 +154,29 @@ describe('noSegmentRecords', () => {
],
};
request.post(getbaseURL()
+ "/api/noSegments", {json},
(err, res, body) => {
if (err) done(err);
else if (res.statusCode === 200) {
let result = db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['bothCases']);
if (result.length !== 1) {
console.log(result);
done("Expected 1 entrys in db, got " + result.length);
} else {
done();
}
fetch(getbaseURL() + "/api/noSegments", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json),
})
.then(async res => {
if (res.status === 200) {
let result = db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['bothCases']);
if (result.length !== 1) {
console.log(result);
done("Expected 1 entrys in db, got " + result.length);
} else {
console.log(body);
done("Status code was " + res.statusCode);
done();
}
});
} else {
const body = await res.text();
console.log(body);
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should not be able to submit categories with $ in the category', (done: Done) => {
@@ -163,36 +188,47 @@ describe('noSegmentRecords', () => {
],
};
request.post(getbaseURL()
+ "/api/noSegments", {json},
(err, res, body) => {
if (err) done(err);
else if (res.statusCode === 200) {
let result = db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['specialChar']);
if (result.length !== 0) {
console.log(result);
done("Expected 0 entrys in db, got " + result.length);
} else {
done();
}
fetch(getbaseURL() + "/api/noSegments", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json),
})
.then(async res => {
if (res.status === 200) {
let result = db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['specialChar']);
if (result.length !== 0) {
console.log(result);
done("Expected 0 entrys in db, got " + result.length);
} else {
console.log(body);
done("Status code was " + res.statusCode);
done();
}
});
} else {
const body = await res.text();
console.log(body);
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should return 400 for missing params', (done: Done) => {
request.post(getbaseURL()
+ "/api/noSegments", {json: {}},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 400) {
done();
} else {
done("Status code was " + res.statusCode);
}
});
fetch(getbaseURL() + "/api/noSegments", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({}),
})
.then(res => {
if (res.status === 400) {
done();
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should return 400 for no categories', (done: Done) => {
@@ -202,16 +238,21 @@ describe('noSegmentRecords', () => {
categories: [],
};
request.post(getbaseURL()
+ "/api/noSegments", {json},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 400) {
done();
} else {
done("Status code was " + res.statusCode);
}
});
fetch(getbaseURL() + "/api/noSegments", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json),
})
.then(res => {
if (res.status === 400) {
done();
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should return 400 for no userID', (done: Done) => {
@@ -221,16 +262,21 @@ describe('noSegmentRecords', () => {
categories: ['sponsor'],
};
request.post(getbaseURL()
+ "/api/noSegments", {json},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 400) {
done();
} else {
done("Status code was " + res.statusCode);
}
});
fetch(getbaseURL() + "/api/noSegments", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json),
})
.then(res => {
if (res.status === 400) {
done();
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should return 400 for no videoID', (done: Done) => {
@@ -240,16 +286,21 @@ describe('noSegmentRecords', () => {
categories: ['sponsor'],
};
request.post(getbaseURL()
+ "/api/noSegments", {json},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 400) {
done();
} else {
done("Status code was " + res.statusCode);
}
});
fetch(getbaseURL() + "/api/noSegments", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json),
})
.then(res => {
if (res.status === 400) {
done();
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should return 400 object categories)', (done: Done) => {
@@ -259,16 +310,21 @@ describe('noSegmentRecords', () => {
categories: {},
};
request.post(getbaseURL()
+ "/api/noSegments", {json},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 400) {
done();
} else {
done("Status code was " + res.statusCode);
}
});
fetch(getbaseURL() + "/api/noSegments", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json),
})
.then(res => {
if (res.status === 400) {
done();
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should return 400 bad format categories', (done: Done) => {
@@ -278,16 +334,21 @@ describe('noSegmentRecords', () => {
categories: 'sponsor',
};
request.post(getbaseURL()
+ "/api/noSegments", {json},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 400) {
done();
} else {
done("Status code was " + res.statusCode);
}
});
fetch(getbaseURL() + "/api/noSegments", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json),
})
.then(res => {
if (res.status === 400) {
done();
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should return 403 if user is not VIP', (done: Done) => {
@@ -299,16 +360,21 @@ describe('noSegmentRecords', () => {
],
};
request.post(getbaseURL()
+ "/api/noSegments", {json},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 403) {
done();
} else {
done("Status code was " + res.statusCode);
}
});
fetch(getbaseURL() + "/api/noSegments", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json),
})
.then(res => {
if (res.status === 403) {
done();
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should be able to delete a noSegment record', (done: Done) => {
@@ -320,21 +386,26 @@ describe('noSegmentRecords', () => {
],
};
request.delete(getbaseURL()
+ "/api/noSegments", {json},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let result = db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['delete-record']);
if (result.length === 0) {
done();
} else {
done("Didn't delete record");
}
fetch(getbaseURL() + "/api/noSegments", {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json),
})
.then(res => {
if (res.status === 200) {
let result = db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['delete-record']);
if (result.length === 0) {
done();
} else {
done("Status code was " + res.statusCode);
done("Didn't delete record");
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should be able to delete one noSegment record without removing another', (done: Done) => {
@@ -346,21 +417,26 @@ describe('noSegmentRecords', () => {
],
};
request.delete(getbaseURL()
+ "/api/noSegments", {json},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let result = db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['delete-record-1']);
if (result.length === 1) {
done();
} else {
done("Didn't delete record");
}
fetch(getbaseURL() + "/api/noSegments", {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json),
})
.then(res => {
if (res.status === 200) {
let result = db.prepare('all', 'SELECT * FROM noSegments WHERE videoID = ?', ['delete-record-1']);
if (result.length === 1) {
done();
} else {
done("Status code was " + res.statusCode);
done("Didn't delete record");
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
@@ -370,31 +446,37 @@ describe('noSegmentRecords', () => {
*/
it('Should not be able to submit a segment to a video with a no-segment record (single submission)', (done: Done) => {
request.post(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
userID: "testman42",
videoID: "noSubmitVideo",
segments: [{
segment: [20, 40],
category: "sponsor",
}],
},
fetch(getbaseURL() + "/api/postVideoSponsorTimes", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 403) {
done();
} else {
done("Status code was " + res.statusCode);
}
});
body: JSON.stringify({
userID: "testman42",
videoID: "noSubmitVideo",
segments: [{
segment: [20, 40],
category: "sponsor",
}],
}),
})
.then(res => {
if (res.status === 403) {
done();
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should not be able to submit segments to a video where any of the submissions with a no-segment record', (done: Done) => {
request.post(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
fetch(getbaseURL() + "/api/postVideoSponsorTimes", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
userID: "testman42",
videoID: "noSubmitVideo",
segments: [{
@@ -404,60 +486,66 @@ describe('noSegmentRecords', () => {
segment: [50, 60],
category: "intro",
}],
},
},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 403) {
done();
} else {
done("Status code was " + res.statusCode);
}
});
},),
})
.then(res => {
if (res.status === 403) {
done();
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should be able to submit a segment to a video with a different no-segment record', (done: Done) => {
request.post(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
userID: "testman42",
videoID: "noSubmitVideo",
segments: [{
segment: [20, 40],
category: "intro",
}],
},
fetch(getbaseURL() + "/api/postVideoSponsorTimes", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
done();
} else {
done("Status code was " + res.statusCode);
}
});
body: JSON.stringify({
userID: "testman42",
videoID: "noSubmitVideo",
segments: [{
segment: [20, 40],
category: "intro",
}],
}),
})
.then(res => {
if (res.status === 200) {
done();
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should be able to submit a segment to a video with no no-segment records', (done: Done) => {
request.post(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
fetch(getbaseURL() + "/api/postVideoSponsorTimes", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
userID: "testman42",
videoID: "normalVideo",
segments: [{
segment: [20, 40],
category: "intro",
}],
},
},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
done();
} else {
done("Status code was " + res.statusCode);
}
});
}),
})
.then(res => {
if (res.status === 200) {
done();
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
});

View File

@@ -1,4 +1,4 @@
import request from 'request';
import fetch from 'node-fetch';
import {db} from '../../src/databases/databases';
import {Done, getbaseURL} from '../utils';
import {getHash} from '../../src/utils/getHash';
@@ -24,64 +24,60 @@ describe('getVideoSponsorTime (Old get method)', () => {
});
it('Should be able to get a time', (done: Done) => {
request.get(getbaseURL()
+ "/api/getVideoSponsorTimes?videoID=old-testtesttest", null,
(err, res) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode !== 200) done("non 200");
else done(); // pass
});
fetch(getbaseURL() + "/api/getVideoSponsorTimes?videoID=old-testtesttest")
.then(res => {
if (res.status !== 200) done("non 200 (" + res.status + ")");
else done(); // pass
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should return 404 if no segment found', (done: Done) => {
request.get(getbaseURL()
+ "/api/getVideoSponsorTimes?videoID=notarealvideo", null,
(err, res) => {
if (err) done("couldn't call endpoint");
else if (res.statusCode !== 404) done("non 404 respone code: " + res.statusCode);
else done(); // pass
});
fetch(getbaseURL() + "/api/getVideoSponsorTimes?videoID=notarealvideo")
.then(res => {
if (res.status !== 404) done("non 404 respone code: " + res.status);
else done(); // pass
})
.catch(err => done("couldn't call endpoint"));
});
it('Should be possible to send unexpected query parameters', (done: Done) => {
request.get(getbaseURL()
+ "/api/getVideoSponsorTimes?videoID=old-testtesttest&fakeparam=hello", null,
(err, res) => {
if (err) done("couldn't callendpoint");
else if (res.statusCode !== 200) done("non 200");
else done(); // pass
});
fetch(getbaseURL() + "/api/getVideoSponsorTimes?videoID=old-testtesttest&fakeparam=hello")
.then(res => {
if (res.status !== 200) done("non 200");
else done(); // pass
})
.catch(err => done("couldn't callendpoint"));
});
it('Should be able send a comma in a query param', (done: Done) => {
request.get(getbaseURL()
+ "/api/getVideoSponsorTimes?videoID=old-testtesttest,test", null,
(err, res, body) => {
if (err) done("couln't call endpoint");
else if (res.statusCode !== 200) done("non 200 response: " + res.statusCode);
else if (JSON.parse(body).UUIDs[0] === 'uuid-1') done(); // pass
else done("couldn't parse response");
});
fetch(getbaseURL() + "/api/getVideoSponsorTimes?videoID=old-testtesttest,test")
.then(async res => {
const body = await res.text();
if (res.status !== 200) done("non 200 response: " + res.status);
else if (JSON.parse(body).UUIDs[0] === 'uuid-1') done(); // pass
else done("couldn't parse response");
})
.catch(err => done("couln't call endpoint"));
});
it('Should be able to get the correct time', (done: Done) => {
request.get(getbaseURL()
+ "/api/getVideoSponsorTimes?videoID=old-testtesttest", null,
(err, res, body) => {
if (err) done("couldn't call endpoint");
else if (res.statusCode !== 200) done("non 200");
else {
let parsedBody = JSON.parse(body);
if (parsedBody.sponsorTimes[0][0] === 1
&& parsedBody.sponsorTimes[0][1] === 11
&& parsedBody.UUIDs[0] === 'uuid-0') {
done(); // pass
} else {
done("Wrong data was returned + " + parsedBody);
}
fetch(getbaseURL() + "/api/getVideoSponsorTimes?videoID=old-testtesttest")
.then(async res => {
if (res.status !== 200) done("non 200");
else {
const parsedBody = await res.json();
if (parsedBody.sponsorTimes[0][0] === 1
&& parsedBody.sponsorTimes[0][1] === 11
&& parsedBody.UUIDs[0] === 'uuid-0') {
done(); // pass
} else {
done("Wrong data was returned + " + JSON.stringify(parsedBody));
}
}
});
})
.catch(err => done("couldn't call endpoint"));
});
});

View File

@@ -1,52 +1,57 @@
import request from 'request';
import fetch from 'node-fetch';
import {Done, getbaseURL} from '../utils';
import {db} from '../../src/databases/databases';
describe('postVideoSponsorTime (Old submission method)', () => {
it('Should be able to submit a time (GET)', (done: Done) => {
request.get(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=dQw4w9WgXcQ&startTime=1&endTime=10&userID=test", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcQ"]);
if (row.startTime === 1 && row.endTime === 10 && row.category === "sponsor") {
done();
} else {
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
}
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=dQw4w9WgXcQ&startTime=1&endTime=10&userID=test")
.then(res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcQ"]);
if (row.startTime === 1 && row.endTime === 10 && row.category === "sponsor") {
done();
} else {
done("Status code was " + res.statusCode);
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should be able to submit a time (POST)', (done: Done) => {
request.post(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=dQw4w9WgXcE&startTime=1&endTime=11&userID=test", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcE"]);
if (row.startTime === 1 && row.endTime === 11 && row.category === "sponsor") {
done();
} else {
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
}
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=dQw4w9WgXcE&startTime=1&endTime=11&userID=test", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
})
.then(res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcE"]);
if (row.startTime === 1 && row.endTime === 11 && row.category === "sponsor") {
done();
} else {
done("Status code was " + res.statusCode);
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should return 400 for missing params', (done: Done) => {
request.get(getbaseURL()
+ "/api/postVideoSponsorTimes?startTime=1&endTime=10&userID=test", null,
(err, res) => {
if (err) done(err);
if (res.statusCode === 400) done();
else done("Status code was: " + res.statusCode);
});
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes?startTime=1&endTime=10&userID=test")
.then(res => {
if (res.status === 400) done();
else done("Status code was: " + res.status);
})
.catch(err => done(err));
});
});

View File

@@ -1,4 +1,4 @@
import request from 'request';
import fetch from 'node-fetch';
import {config} from '../../src/config';
import {getHash} from '../../src/utils/getHash';
import {Done, getbaseURL} from '../utils';
@@ -37,54 +37,67 @@ describe('postSkipSegments', () => {
});
it('Should be able to submit a single time (Params method)', (done: Done) => {
request.post(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=dQw4w9WgXcR&startTime=2&endTime=10&userID=test&category=sponsor", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcR"]);
if (row.startTime === 2 && row.endTime === 10 && row.category === "sponsor") {
done();
} else {
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
}
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=dQw4w9WgXcR&startTime=2&endTime=10&userID=test&category=sponsor", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
})
.then(res => {
if (res.status === 200) {
const row = db.prepare('get', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcR"]);
if (row.startTime === 2 && row.endTime === 10 && row.category === "sponsor") {
done();
} else {
done("Status code was " + res.statusCode);
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should be able to submit a single time (JSON method)', (done: Done) => {
request.post(getbaseURL()
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
userID: "test",
videoID: "dQw4w9WgXcF",
segments: [{
segment: [0, 10],
category: "sponsor",
}],
},
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcF"]);
if (row.startTime === 0 && row.endTime === 10 && row.category === "sponsor") {
done();
} else {
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
}
body: JSON.stringify({
userID: "test",
videoID: "dQw4w9WgXcF",
segments: [{
segment: [0, 10],
category: "sponsor",
}],
}),
})
.then(res => {
if (res.status === 200) {
const row = db.prepare('get', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcF"]);
if (row.startTime === 0 && row.endTime === 10 && row.category === "sponsor") {
done();
} else {
done("Status code was " + res.statusCode);
done("Submitted times were not saved. Actual submission: " + JSON.stringify(row));
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should be able to submit multiple times (JSON method)', (done: Done) => {
request.post(getbaseURL()
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
userID: "test",
videoID: "dQw4w9WgXcQ",
segments: [{
@@ -94,35 +107,38 @@ describe('postSkipSegments', () => {
segment: [30, 60],
category: "intro",
}],
},
},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let rows = db.prepare('all', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcR"]);
let success = true;
if (rows.length === 2) {
for (const row of rows) {
if ((row.startTime !== 3 || row.endTime !== 10 || row.category !== "sponsor") &&
(row.startTime !== 30 || row.endTime !== 60 || row.category !== "intro")) {
success = false;
break;
}
}),
})
.then(res => {
if (res.status === 200) {
const rows = db.prepare('all', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ?", ["dQw4w9WgXcR"]);
let success = true;
if (rows.length === 2) {
for (const row of rows) {
if ((row.startTime !== 3 || row.endTime !== 10 || row.category !== "sponsor") &&
(row.startTime !== 30 || row.endTime !== 60 || row.category !== "intro")) {
success = false;
break;
}
}
if (success) done();
else done("Submitted times were not saved. Actual submissions: " + JSON.stringify(rows));
} else {
done("Status code was " + res.statusCode);
}
});
if (success) done();
else done("Submitted times were not saved. Actual submissions: " + JSON.stringify(rows));
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
}).timeout(5000);
it('Should allow multiple times if total is under 80% of video(JSON method)', (done: Done) => {
request.post(getbaseURL()
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
userID: "test",
videoID: "L_jWHffIx5E",
segments: [{
@@ -138,37 +154,40 @@ describe('postSkipSegments', () => {
segment: [99, 170],
category: "sponsor",
}],
},
},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let rows = db.prepare('all', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ? and votes > -1", ["L_jWHffIx5E"]);
let success = true;
if (rows.length === 4) {
for (const row of rows) {
if ((row.startTime !== 3 || row.endTime !== 3000 || row.category !== "sponsor") &&
(row.startTime !== 3002 || row.endTime !== 3050 || row.category !== "intro") &&
(row.startTime !== 45 || row.endTime !== 100 || row.category !== "interaction") &&
(row.startTime !== 99 || row.endTime !== 170 || row.category !== "sponsor")) {
success = false;
break;
}
}),
})
.then(res => {
if (res.status === 200) {
const rows = db.prepare('all', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ? and votes > -1", ["L_jWHffIx5E"]);
let success = true;
if (rows.length === 4) {
for (const row of rows) {
if ((row.startTime !== 3 || row.endTime !== 3000 || row.category !== "sponsor") &&
(row.startTime !== 3002 || row.endTime !== 3050 || row.category !== "intro") &&
(row.startTime !== 45 || row.endTime !== 100 || row.category !== "interaction") &&
(row.startTime !== 99 || row.endTime !== 170 || row.category !== "sponsor")) {
success = false;
break;
}
}
if (success) done();
else done("Submitted times were not saved. Actual submissions: " + JSON.stringify(rows));
} else {
done("Status code was " + res.statusCode);
}
});
if (success) done();
else done("Submitted times were not saved. Actual submissions: " + JSON.stringify(rows));
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
}).timeout(5000);
it('Should reject multiple times if total is over 80% of video (JSON method)', (done: Done) => {
request.post(getbaseURL()
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
userID: "test",
videoID: "n9rIGdXnSJc",
segments: [{
@@ -184,275 +203,334 @@ describe('postSkipSegments', () => {
segment: [4050, 4750],
category: "intro",
}],
},
},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 400) {
let rows = db.prepare('all', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ? and votes > -1", ["n9rIGdXnSJc"]);
let success = true;
if (rows.length === 4) {
for (const row of rows) {
if ((row.startTime === 0 || row.endTime === 2000 || row.category === "interaction") ||
(row.startTime === 3000 || row.endTime === 4000 || row.category === "sponsor") ||
(row.startTime === 1500 || row.endTime === 2750 || row.category === "sponsor") ||
(row.startTime === 4050 || row.endTime === 4750 || row.category === "intro")) {
success = false;
break;
}
}
}
if (success) done();
else
done("Submitted times were not saved. Actual submissions: " + JSON.stringify(rows));
} else {
done("Status code was " + res.statusCode);
}
});
}).timeout(5000);
it('Should reject multiple times if total is over 80% of video including previosuly submitted times(JSON method)', (done: Done) => {
request.post(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
userID: "test",
videoID: "80percent_video",
segments: [{
segment: [2000, 4000],
category: "sponsor",
}, {
segment: [1500, 2750],
category: "sponsor",
}, {
segment: [4050, 4750],
category: "sponsor",
}],
},
},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 400) {
let rows = db.prepare('all', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ? and votes > -1", ["80percent_video"]);
let success = rows.length == 2;
}),
})
.then(res => {
if (res.status === 400) {
const rows = db.prepare('all', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ? and votes > -1", ["n9rIGdXnSJc"]);
let success = true;
if (rows.length === 4) {
for (const row of rows) {
if ((row.startTime === 2000 || row.endTime === 4000 || row.category === "sponsor") ||
if ((row.startTime === 0 || row.endTime === 2000 || row.category === "interaction") ||
(row.startTime === 3000 || row.endTime === 4000 || row.category === "sponsor") ||
(row.startTime === 1500 || row.endTime === 2750 || row.category === "sponsor") ||
(row.startTime === 4050 || row.endTime === 4750 || row.category === "sponsor")) {
(row.startTime === 4050 || row.endTime === 4750 || row.category === "intro")) {
success = false;
break;
}
}
if (success) done();
else
done("Submitted times were not saved. Actual submissions: " + JSON.stringify(rows));
} else {
done("Status code was " + res.statusCode);
}
});
if (success) done();
else
done("Submitted times were not saved. Actual submissions: " + JSON.stringify(rows));
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
}).timeout(5000);
it('Should reject multiple times if total is over 80% of video including previosuly submitted times(JSON method)', (done: Done) => {
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
userID: "test",
videoID: "80percent_video",
segments: [{
segment: [2000, 4000],
category: "sponsor",
}, {
segment: [1500, 2750],
category: "sponsor",
}, {
segment: [4050, 4750],
category: "sponsor",
}],
}),
})
.then(res => {
if (res.status === 400) {
const rows = db.prepare('all', "SELECT startTime, endTime, category FROM sponsorTimes WHERE videoID = ? and votes > -1", ["80percent_video"]);
let success = rows.length == 2;
for (const row of rows) {
if ((row.startTime === 2000 || row.endTime === 4000 || row.category === "sponsor") ||
(row.startTime === 1500 || row.endTime === 2750 || row.category === "sponsor") ||
(row.startTime === 4050 || row.endTime === 4750 || row.category === "sponsor")) {
success = false;
break;
}
}
if (success) done();
else
done("Submitted times were not saved. Actual submissions: " + JSON.stringify(rows));
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
}).timeout(5000);
it('Should be accepted if a non-sponsor is less than 1 second', (done: Done) => {
request.post(getbaseURL()
+ "/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testing&category=intro", null,
(err, res, body) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode === 200) done(); // pass
else done("non 200 status code: " + res.statusCode + " (" + body + ")");
});
fetch(getbaseURL()
+ "/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testing&category=intro", {
method: 'POST',
})
.then(async res => {
if (res.status === 200) done(); // pass
else {
const body = await res.text();
done("non 200 status code: " + res.status + " (" + body + ")");
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should be rejected if a sponsor is less than 1 second', (done: Done) => {
request.post(getbaseURL()
+ "/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testing", null,
(err, res, body) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode === 400) done(); // pass
else done("non 403 status code: " + res.statusCode + " (" + body + ")");
});
fetch(getbaseURL()
+ "/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testing", {
method: 'POST',
})
.then(async res => {
if (res.status === 400) done(); // pass
else {
const body = await res.text();
done("non 403 status code: " + res.status + " (" + body + ")");
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should be rejected if over 80% of the video', (done: Done) => {
request.get(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=qqwerty&startTime=30&endTime=1000000&userID=testing", null,
(err, res, body) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode === 403) done(); // pass
else done("non 403 status code: " + res.statusCode + " (" + body + ")");
});
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=qqwerty&startTime=30&endTime=1000000&userID=testing")
.then(async res => {
if (res.status === 403) done(); // pass
else {
const body = await res.text();
done("non 403 status code: " + res.status + " (" + body + ")");
}
})
.catch(err => done("Couldn't call endpoint"));
});
it("Should be rejected if NB's predicted probability is <70%.", (done: Done) => {
request.get(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=LevkAjUE6d4&startTime=40&endTime=60&userID=testing", null,
(err, res, body) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode === 200) done(); // pass
else done("non 200 status code: " + res.statusCode + " (" + body + ")");
});
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=LevkAjUE6d4&startTime=40&endTime=60&userID=testing")
.then(async res => {
if (res.status === 200) done(); // pass
else {
const body = await res.text();
done("non 200 status code: " + res.status + " (" + body + ")");
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should be rejected if user has to many active warnings', (done: Done) => {
request.post(getbaseURL()
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
userID: "warn-user01",
videoID: "dQw4w9WgXcF",
segments: [{
segment: [0, 10],
category: "sponsor",
}],
},
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
(err, res) => {
if (err) done(err);
else if (res.statusCode === 403) {
done(); // success
} else {
done("Status code was " + res.statusCode);
}
});
body: JSON.stringify({
userID: "warn-user01",
videoID: "dQw4w9WgXcF",
segments: [{
segment: [0, 10],
category: "sponsor",
}],
}),
})
.then(res => {
if (res.status === 403) {
done(); // success
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should be accepted if user has some active warnings', (done: Done) => {
request.post(getbaseURL()
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
userID: "warn-user02",
videoID: "dQw4w9WgXcF",
segments: [{
segment: [50, 60],
category: "sponsor",
}],
},
},
(err, res, body) => {
if (err) done(err);
else if (res.statusCode === 200) {
done(); // success
} else {
done("Status code was " + res.statusCode + " " + body);
}
});
}),
})
.then(async res => {
if (res.status === 200) {
done(); // success
} else {
const body = await res.text();
done("Status code was " + res.status + " " + body);
}
})
.catch(err => done(err));
});
it('Should be allowed if youtube thinks duration is 0', (done: Done) => {
request.get(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=noDuration&startTime=30&endTime=10000&userID=testing", null,
(err, res, body) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode === 200) done(); // pass
else done("non 200 status code: " + res.statusCode + " (" + body + ")");
});
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=noDuration&startTime=30&endTime=10000&userID=testing", {
method: 'POST',
})
.then(async res => {
if (res.status === 200) done(); // pass
else {
const body = await res.text();
done("non 200 status code: " + res.status + " (" + body + ")");
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should be rejected if not a valid videoID', (done: Done) => {
request.get(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=knownWrongID&startTime=30&endTime=1000000&userID=testing", null,
(err, res, body) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode === 403) done(); // pass
else done("non 403 status code: " + res.statusCode + " (" + body + ")");
});
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=knownWrongID&startTime=30&endTime=1000000&userID=testing")
.then(async res => {
if (res.status === 403) done(); // pass
else {
const body = await res.text();
done("non 403 status code: " + res.status + " (" + body + ")");
}
})
.catch(err => done("Couldn't call endpoint"));
});
it('Should return 400 for missing params (Params method)', (done: Done) => {
request.post(getbaseURL()
+ "/api/postVideoSponsorTimes?startTime=9&endTime=10&userID=test", null,
(err, res) => {
if (err) done(true);
if (res.statusCode === 400) done();
else done(true);
});
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes?startTime=9&endTime=10&userID=test", {
method: 'POST',
})
.then(res => {
if (res.status === 400) done();
else done(true);
})
.catch(err => done(true));
});
it('Should return 400 for missing params (JSON method) 1', (done: Done) => {
request.post(getbaseURL()
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
userID: "test",
segments: [{
segment: [9, 10],
category: "sponsor",
}, {
segment: [31, 60],
category: "intro",
}],
},
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
(err, res) => {
if (err) done(true);
else if (res.statusCode === 400) done();
else done(true);
});
body: JSON.stringify({
userID: "test",
segments: [{
segment: [9, 10],
category: "sponsor",
}, {
segment: [31, 60],
category: "intro",
}],
}),
})
.then(res => {
if (res.status === 400) done();
else done(true);
})
.catch(err => done(true));
});
it('Should return 400 for missing params (JSON method) 2', (done: Done) => {
request.post(getbaseURL()
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
userID: "test",
videoID: "dQw4w9WgXcQ",
},
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
(err, res) => {
if (err) done(true);
else if (res.statusCode === 400) done();
else done(true);
});
body: JSON.stringify({
userID: "test",
videoID: "dQw4w9WgXcQ",
}),
})
.then(res => {
if (res.status === 400) done();
else done(true);
})
.catch(err => done(true));
});
it('Should return 400 for missing params (JSON method) 3', (done: Done) => {
request.post(getbaseURL()
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
userID: "test",
videoID: "dQw4w9WgXcQ",
segments: [{
segment: [0],
category: "sponsor",
}, {
segment: [31, 60],
category: "intro",
}],
},
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
(err, res) => {
if (err) done(true);
else if (res.statusCode === 400) done();
else done(true);
});
body: JSON.stringify({
userID: "test",
videoID: "dQw4w9WgXcQ",
segments: [{
segment: [0],
category: "sponsor",
}, {
segment: [31, 60],
category: "intro",
}],
}),
})
.then(res => {
if (res.status === 400) done();
else done(true);
})
.catch(err => done(true));
});
it('Should return 400 for missing params (JSON method) 4', (done: Done) => {
request.post(getbaseURL()
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
userID: "test",
videoID: "dQw4w9WgXcQ",
segments: [{
segment: [9, 10],
}, {
segment: [31, 60],
category: "intro",
}],
},
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
(err, res) => {
if (err) done(true);
else if (res.statusCode === 400) done();
else done(true);
});
body: JSON.stringify({
userID: "test",
videoID: "dQw4w9WgXcQ",
segments: [{
segment: [9, 10],
}, {
segment: [31, 60],
category: "intro",
}],
}),
})
.then(res => {
if (res.status === 400) done();
else done(true);
})
.catch(err => done(true));
});
it('Should return 400 for missing params (JSON method) 5', (done: Done) => {
request.post(getbaseURL()
fetch(getbaseURL()
+ "/api/postVideoSponsorTimes", {
json: {
userID: "test",
videoID: "dQw4w9WgXcQ",
},
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
(err, res) => {
if (err) done(true);
else if (res.statusCode === 400) done();
else done(true);
});
body: JSON.stringify({
userID: "test",
videoID: "dQw4w9WgXcQ",
}),
})
.then(res => {
if (res.status === 400) done();
else done(true);
})
.catch(err => done(true));
});
});

View File

@@ -1,4 +1,4 @@
import request from 'request';
import fetch from 'node-fetch';
import {Done, getbaseURL} from '../utils';
import {db} from '../../src/databases/databases';
import {getHash} from '../../src/utils/getHash';
@@ -13,23 +13,29 @@ describe('postWarning', () => {
issuerUserID: 'warning-vip',
userID: 'warning-0',
};
request.post(getbaseURL()
+ "/api/warnUser", {json},
(err, res, body) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT userID, issueTime, issuerUserID, enabled FROM warnings WHERE userID = ?", [json.userID]);
if (row?.enabled == 1 && row?.issuerUserID == getHash(json.issuerUserID)) {
done();
} else {
done("Warning missing from database");
}
fetch(getbaseURL()
+ "/api/warnUser", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json),
})
.then(async res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT userID, issueTime, issuerUserID, enabled FROM warnings WHERE userID = ?", [json.userID]);
if (row?.enabled == 1 && row?.issuerUserID == getHash(json.issuerUserID)) {
done();
} else {
console.log(body);
done("Status code was " + res.statusCode);
done("Warning missing from database");
}
});
} else {
const body = await res.text();
console.log(body);
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should be not be able to create a duplicate warning if vip', (done: Done) => {
@@ -38,22 +44,29 @@ describe('postWarning', () => {
userID: 'warning-0',
};
request.post(getbaseURL()
+ "/api/warnUser", {json},
(err, res, body) => {
if (err) done(err);
else if (res.statusCode === 409) {
let row = db.prepare('get', "SELECT userID, issueTime, issuerUserID, enabled FROM warnings WHERE userID = ?", [json.userID]);
if (row?.enabled == 1 && row?.issuerUserID == getHash(json.issuerUserID)) {
done();
} else {
done("Warning missing from database");
}
fetch(getbaseURL()
+ "/api/warnUser", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json),
})
.then(async res => {
if (res.status === 409) {
let row = db.prepare('get', "SELECT userID, issueTime, issuerUserID, enabled FROM warnings WHERE userID = ?", [json.userID]);
if (row?.enabled == 1 && row?.issuerUserID == getHash(json.issuerUserID)) {
done();
} else {
console.log(body);
done("Status code was " + res.statusCode);
done("Warning missing from database");
}
});
} else {
const body = await res.text();
console.log(body);
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should be able to remove warning if vip', (done: Done) => {
@@ -63,22 +76,29 @@ describe('postWarning', () => {
enabled: false
};
request.post(getbaseURL()
+ "/api/warnUser", {json},
(err, res, body) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT userID, issueTime, issuerUserID, enabled FROM warnings WHERE userID = ?", [json.userID]);
if (row?.enabled == 0) {
done();
} else {
done("Warning missing from database");
}
fetch(getbaseURL()
+ "/api/warnUser", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json),
})
.then(async res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT userID, issueTime, issuerUserID, enabled FROM warnings WHERE userID = ?", [json.userID]);
if (row?.enabled == 0) {
done();
} else {
console.log(body);
done("Status code was " + res.statusCode);
done("Warning missing from database");
}
});
} else {
const body = await res.text();
console.log(body);
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should not be able to create warning if vip (exp 403)', (done: Done) => {
@@ -87,16 +107,23 @@ describe('postWarning', () => {
userID: 'warning-1',
};
request.post(getbaseURL()
+ "/api/warnUser", {json},
(err, res, body) => {
if (err) done(err);
else if (res.statusCode === 403) {
done();
} else {
console.log(body);
done("Status code was " + res.statusCode);
}
});
fetch(getbaseURL()
+ "/api/warnUser", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(json),
})
.then(async res => {
if (res.status === 403) {
done();
} else {
const body = await res.text();
console.log(body);
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
});

View File

@@ -1,4 +1,4 @@
import request from 'request';
import fetch from 'node-fetch';
import {Done, getbaseURL} from '../utils';
import {db} from '../../src/databases/databases';
import {getHash} from '../../src/utils/getHash';
@@ -70,30 +70,39 @@ describe('segmentShift', function () {
});
it('Reject none VIP user', function (done: Done) {
request.post(`${baseURL}/api/segmentShift`, {
json: {
fetch(`${baseURL}/api/segmentShift`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
videoID: 'vsegshift01',
userID: 'segshift_randomuser001',
startTime: 20,
endTime: 30,
},
}, (err, res) => {
if (err) return done(err);
return done(res.statusCode === 403 ? undefined : res.statusCode);
});
}),
})
.then(res => {
done(res.status === 403 ? undefined : res.status);
})
.catch(err => done(err));
});
it('Shift is outside segments', function (done: Done) {
request.post(`${baseURL}/api/segmentShift`, {
json: {
fetch(`${baseURL}/api/segmentShift`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
videoID: 'vsegshift01',
userID: privateVipUserID,
startTime: 20,
endTime: 30,
},
}, (err, res) => {
if (err) return done(err);
if (res.statusCode !== 200) return done(`Status code was ${res.statusCode}`);
}),
})
.then(res => {
if (res.status !== 200) return done(`Status code was ${res.status}`);
const expect = [
{
UUID: 'vsegshifttest01uuid01',
@@ -117,20 +126,25 @@ describe('segmentShift', function () {
},
];
done(dbSponsorTimesCompareExpect(db, expect));
});
})
.catch(err => done(err));
});
it('Shift is inside segment', function (done: Done) {
request.post(`${baseURL}/api/segmentShift`, {
json: {
fetch(`${baseURL}/api/segmentShift`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
videoID: 'vsegshift01',
userID: privateVipUserID,
startTime: 65,
endTime: 75,
},
}, (err, res) => {
if (err) return done(err);
if (res.statusCode !== 200) return done(`Status code was ${res.statusCode}`);
}),
})
.then(res => {
if (res.status !== 200) return done(`Status code was ${res.status}`);
const expect = [
{
UUID: 'vsegshifttest01uuid01',
@@ -154,20 +168,25 @@ describe('segmentShift', function () {
},
];
done(dbSponsorTimesCompareExpect(db, expect));
});
})
.catch(err => done(err));
});
it('Shift is overlaping startTime of segment', function (done: Done) {
request.post(`${baseURL}/api/segmentShift`, {
json: {
fetch(`${baseURL}/api/segmentShift`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
videoID: 'vsegshift01',
userID: privateVipUserID,
startTime: 32,
endTime: 42,
},
}, (err, res) => {
if (err) return done(err);
if (res.statusCode !== 200) return done(`Status code was ${res.statusCode}`);
}),
})
.then(res => {
if (res.status !== 200) return done(`Status code was ${res.status}`);
const expect = [
{
UUID: 'vsegshifttest01uuid01',
@@ -191,20 +210,25 @@ describe('segmentShift', function () {
},
];
done(dbSponsorTimesCompareExpect(db, expect));
});
})
.catch(err => done(err));
});
it('Shift is overlaping endTime of segment', function (done: Done) {
request.post(`${baseURL}/api/segmentShift`, {
json: {
fetch(`${baseURL}/api/segmentShift`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
videoID: 'vsegshift01',
userID: privateVipUserID,
startTime: 85,
endTime: 95,
},
}, (err, res) => {
if (err) return done(err);
if (res.statusCode !== 200) return done(`Status code was ${res.statusCode}`);
}),
})
.then(res => {
if (res.status !== 200) return done(`Status code was ${res.status}`);
const expect = [
{
UUID: 'vsegshifttest01uuid01',
@@ -228,20 +252,25 @@ describe('segmentShift', function () {
},
];
done(dbSponsorTimesCompareExpect(db, expect));
});
})
.catch(err => done(err));
});
it('Shift is overlaping segment', function (done: Done) {
request.post(`${baseURL}/api/segmentShift`, {
json: {
fetch(`${baseURL}/api/segmentShift`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
videoID: 'vsegshift01',
userID: privateVipUserID,
startTime: 35,
endTime: 55,
},
}, (err, res) => {
if (err) return done(err);
if (res.statusCode !== 200) return done(`Status code was ${res.statusCode}`);
}),
})
.then(res => {
if (res.status !== 200) return done(`Status code was ${res.status}`);
const expect = [
{
UUID: 'vsegshifttest01uuid01',
@@ -266,8 +295,7 @@ describe('segmentShift', function () {
},
];
done(dbSponsorTimesCompareExpect(db, expect));
});
})
.catch(err => done(err));
});
});

View File

@@ -1,4 +1,4 @@
import request from 'request';
import fetch from 'node-fetch';
import * as utils from '../utils';
import { getHash } from '../../src/utils/getHash';
@@ -23,9 +23,14 @@ describe('unBan', () => {
});
it('Should be able to unban a user and re-enable shadow banned segments', (done) => {
request.post(utils.getbaseURL() + "/api/shadowBanUser?userID=testMan-unBan&adminUserID=VIPUser-unBan&enabled=false", null, (err, res, body) => {
if (err) done(err);
else if (res.statusCode === 200) {
fetch(utils.getbaseURL() + "/api/shadowBanUser?userID=testMan-unBan&adminUserID=VIPUser-unBan&enabled=false", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
})
.then(async res => {
if (res.status === 200) {
let result = db.prepare('all', 'SELECT * FROM sponsorTimes WHERE videoID = ? AND userID = ? AND shadowHidden = ?', ['unBan-videoID-0', 'testMan-unBan', 1]);
if (result.length !== 0) {
console.log(result);
@@ -34,34 +39,48 @@ describe('unBan', () => {
done();
}
} else {
const body = await res.text();
console.log(body);
done("Status code was " + res.statusCode);
done("Status code was " + res.status);
}
});
})
.catch(err => done(err));
});
it('Should be able to unban a user and re-enable shadow banned segments without noSegment entrys', (done) => {
request.post(utils.getbaseURL() + "/api/shadowBanUser?userID=testWoman-unBan&adminUserID=VIPUser-unBan&enabled=false", null, (err, res, body) => {
if (err) done(err);
else if (res.statusCode === 200) {
let result = db.prepare('all', 'SELECT * FROM sponsorTimes WHERE videoID = ? AND userID = ? AND shadowHidden = ?', ['unBan-videoID-1', 'testWoman-unBan', 1]);
if (result.length !== 1) {
console.log(result);
done("Expected 1 banned entry1 in db, got " + result.length);
fetch(utils.getbaseURL() + "/api/shadowBanUser?userID=testWoman-unBan&adminUserID=VIPUser-unBan&enabled=false", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
})
.then(async res => {
if (res.status === 200) {
let result = db.prepare('all', 'SELECT * FROM sponsorTimes WHERE videoID = ? AND userID = ? AND shadowHidden = ?', ['unBan-videoID-1', 'testWoman-unBan', 1]);
if (result.length !== 1) {
console.log(result);
done("Expected 1 banned entry1 in db, got " + result.length);
} else {
done();
}
} else {
done();
const body = await res.text();
console.log(body);
done("Status code was " + res.status);
}
} else {
console.log(body);
done("Status code was " + res.statusCode);
}
});
})
.catch(err => done(err));
});
it('Should be able to unban a user and re-enable shadow banned segments with a mix of noSegment entrys', (done) => {
request.post(utils.getbaseURL() + "/api/shadowBanUser?userID=testEntity-unBan&adminUserID=VIPUser-unBan&enabled=false", null, (err, res, body) => {
if (err) done(err);
else if (res.statusCode === 200) {
fetch(utils.getbaseURL() + "/api/shadowBanUser?userID=testEntity-unBan&adminUserID=VIPUser-unBan&enabled=false", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
})
.then(async res => {
if (res.status === 200) {
let result = db.prepare('all', 'SELECT * FROM sponsorTimes WHERE userID = ? AND shadowHidden = ?', ['testEntity-unBan', 1]);
if (result.length !== 1) {
console.log(result);
@@ -70,9 +89,11 @@ describe('unBan', () => {
done();
}
} else {
console.log(body);
done("Status code was " + res.statusCode);
const body = await res.text();
console.log(body);
done("Status code was " + res.status);
}
});
})
.catch(err => done(err));
});
});

View File

@@ -1,4 +1,4 @@
import request from 'request';
import fetch from 'node-fetch';
import {config} from '../../src/config';
import {db, privateDB} from '../../src/databases/databases';
import {Done, getbaseURL} from '../utils';
@@ -63,251 +63,249 @@ describe('voteOnSponsorTime', () => {
});
it('Should be able to upvote a segment', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID&UUID=vote-uuid-0&type=1", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-0"]);
if (row.votes === 3) {
done();
} else {
done("Vote did not succeed. Submission went from 2 votes to " + row.votes);
}
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID&UUID=vote-uuid-0&type=1")
.then(res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-0"]);
if (row.votes === 3) {
done();
} else {
done("Status code was " + res.statusCode);
done("Vote did not succeed. Submission went from 2 votes to " + row.votes);
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should be able to downvote a segment', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-2&type=0", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-2"]);
if (row.votes < 10) {
done();
} else {
done("Vote did not succeed. Submission went from 10 votes to " + row.votes);
}
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-2&type=0")
.then(res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-2"]);
if (row.votes < 10) {
done();
} else {
done("Status code was " + res.statusCode);
done("Vote did not succeed. Submission went from 10 votes to " + row.votes);
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should not be able to downvote the same segment when voting from a different user on the same IP', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID3&UUID=vote-uuid-2&type=0", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-2"]);
if (row.votes === 9) {
done();
} else {
done("Vote did not fail. Submission went from 9 votes to " + row.votes);
}
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID3&UUID=vote-uuid-2&type=0")
.then(res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-2"]);
if (row.votes === 9) {
done();
} else {
done("Status code was " + res.statusCode);
done("Vote did not fail. Submission went from 9 votes to " + row.votes);
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it("Should not be able to downvote a segment if the user is shadow banned", (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID4&UUID=vote-uuid-1.6&type=0", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-1.6"]);
if (row.votes === 10) {
done();
} else {
done("Vote did not fail. Submission went from 10 votes to " + row.votes);
}
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID4&UUID=vote-uuid-1.6&type=0")
.then(res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-1.6"]);
if (row.votes === 10) {
done();
} else {
done("Status code was " + res.statusCode);
done("Vote did not fail. Submission went from 10 votes to " + row.votes);
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it("Should not be able to upvote a segment if the user hasn't submitted yet", (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=hasNotSubmittedID&UUID=vote-uuid-1&type=1", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-1"]);
if (row.votes === 2) {
done();
} else {
done("Vote did not fail. Submission went from 2 votes to " + row.votes);
}
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=hasNotSubmittedID&UUID=vote-uuid-1&type=1")
.then(res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-1"]);
if (row.votes === 2) {
done();
} else {
done("Status code was " + res.statusCode);
done("Vote did not fail. Submission went from 2 votes to " + row.votes);
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it("Should not be able to downvote a segment if the user hasn't submitted yet", (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=hasNotSubmittedID&UUID=vote-uuid-1.5&type=0", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-1.5"]);
if (row.votes === 10) {
done();
} else {
done("Vote did not fail. Submission went from 10 votes to " + row.votes);
}
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=hasNotSubmittedID&UUID=vote-uuid-1.5&type=0")
.then(res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-1.5"]);
if (row.votes === 10) {
done();
} else {
done("Status code was " + res.statusCode);
done("Vote did not fail. Submission went from 10 votes to " + row.votes);
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('VIP should be able to completely downvote a segment', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-3&type=0", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-3"]);
if (row.votes <= -2) {
done();
} else {
done("Vote did not succeed. Submission went from 100 votes to " + row.votes);
}
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-3&type=0")
.then(res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-3"]);
if (row.votes <= -2) {
done();
} else {
done("Status code was " + res.statusCode);
done("Vote did not succeed. Submission went from 100 votes to " + row.votes);
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('should be able to completely downvote your own segment', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=own-submission-id&UUID=own-submission-uuid&type=0", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["own-submission-uuid"]);
if (row.votes <= -2) {
done();
} else {
done("Vote did not succeed. Submission went from 500 votes to " + row.votes);
}
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=own-submission-id&UUID=own-submission-uuid&type=0")
.then(res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["own-submission-uuid"]);
if (row.votes <= -2) {
done();
} else {
done("Status code was " + res.statusCode);
done("Vote did not succeed. Submission went from 500 votes to " + row.votes);
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('should not be able to completely downvote somebody elses segment', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=not-own-submission-uuid&type=0", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["not-own-submission-uuid"]);
if (row.votes === 499) {
done();
} else {
done("Vote did not succeed. Submission went from 500 votes to " + row.votes);
}
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=not-own-submission-uuid&type=0")
.then(res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["not-own-submission-uuid"]);
if (row.votes === 499) {
done();
} else {
done("Status code was " + res.statusCode);
done("Vote did not succeed. Submission went from 500 votes to " + row.votes);
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should be able to vote for a category and it should add your vote to the database', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-4&category=intro", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-4"]);
let categoryRows = db.prepare('all', "SELECT votes, category FROM categoryVotes WHERE UUID = ?", ["vote-uuid-4"]);
if (row.category === "sponsor" && categoryRows.length === 2
&& categoryRows[0]?.votes === 1 && categoryRows[0]?.category === "intro"
&& categoryRows[1]?.votes === 1 && categoryRows[1]?.category === "sponsor") {
done();
} else {
done("Submission changed to " + row.category + " instead of staying as sponsor. Vote was applied as " + categoryRows[0]?.category + " with " + categoryRows[0]?.votes + " votes and there were " + categoryRows.length + " rows.");
}
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-4&category=intro")
.then(res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-4"]);
let categoryRows = db.prepare('all', "SELECT votes, category FROM categoryVotes WHERE UUID = ?", ["vote-uuid-4"]);
if (row.category === "sponsor" && categoryRows.length === 2
&& categoryRows[0]?.votes === 1 && categoryRows[0]?.category === "intro"
&& categoryRows[1]?.votes === 1 && categoryRows[1]?.category === "sponsor") {
done();
} else {
done("Status code was " + res.statusCode);
done("Submission changed to " + row.category + " instead of staying as sponsor. Vote was applied as " + categoryRows[0]?.category + " with " + categoryRows[0]?.votes + " votes and there were " + categoryRows.length + " rows.");
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should not able to change to an invalid category', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=incorrect-category&category=fakecategory", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 400) {
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["incorrect-category"]);
if (row.category === "sponsor") {
done();
} else {
done("Vote did not succeed. Submission went from sponsor to " + row.category);
}
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=incorrect-category&category=fakecategory")
.then(res => {
if (res.status === 400) {
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["incorrect-category"]);
if (row.category === "sponsor") {
done();
} else {
done("Status code was " + res.statusCode);
done("Vote did not succeed. Submission went from sponsor to " + row.category);
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should be able to change your vote for a category and it should add your vote to the database', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-4&category=outro", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let submissionRow = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-4"]);
let categoryRows = db.prepare('all', "SELECT votes, category FROM categoryVotes WHERE UUID = ?", ["vote-uuid-4"]);
let introVotes = 0;
let outroVotes = 0;
let sponsorVotes = 0;
for (const row of categoryRows) {
if (row?.category === "intro") introVotes += row?.votes;
if (row?.category === "outro") outroVotes += row?.votes;
if (row?.category === "sponsor") sponsorVotes += row?.votes;
}
if (submissionRow.category === "sponsor" && categoryRows.length === 3
&& introVotes === 0 && outroVotes === 1 && sponsorVotes === 1) {
done();
} else {
done("Submission changed to " + submissionRow.category + " instead of staying as sponsor. There were "
+ introVotes + " intro votes, " + outroVotes + " outro votes and " + sponsorVotes + " sponsor votes.");
}
} else {
done("Status code was " + res.statusCode);
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-4&category=outro")
.then(res => {
if (res.status === 200) {
let submissionRow = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-4"]);
let categoryRows = db.prepare('all', "SELECT votes, category FROM categoryVotes WHERE UUID = ?", ["vote-uuid-4"]);
let introVotes = 0;
let outroVotes = 0;
let sponsorVotes = 0;
for (const row of categoryRows) {
if (row?.category === "intro") introVotes += row?.votes;
if (row?.category === "outro") outroVotes += row?.votes;
if (row?.category === "sponsor") sponsorVotes += row?.votes;
}
});
if (submissionRow.category === "sponsor" && categoryRows.length === 3
&& introVotes === 0 && outroVotes === 1 && sponsorVotes === 1) {
done();
} else {
done("Submission changed to " + submissionRow.category + " instead of staying as sponsor. There were "
+ introVotes + " intro votes, " + outroVotes + " outro votes and " + sponsorVotes + " sponsor votes.");
}
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should not be able to change your vote to an invalid category', (done: Done) => {
const vote = (inputCat: string, assertCat: string, callback: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=incorrect-category-change&category=" + inputCat, null,
(err) => {
if (err) done(err);
else {
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["incorrect-category-change"]);
if (row.category === assertCat) {
callback();
} else {
done("Vote did not succeed. Submission went from sponsor to " + row.category);
}
}
});
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=incorrect-category-change&category=" + inputCat)
.then(res => {
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["incorrect-category-change"]);
if (row.category === assertCat) {
callback();
} else {
done("Vote did not succeed. Submission went from sponsor to " + row.category);
}
})
.catch(err => done(err));
};
vote("sponsor", "sponsor", () => {
vote("fakeCategory", "sponsor", done);
@@ -316,149 +314,148 @@ describe('voteOnSponsorTime', () => {
it('VIP should be able to vote for a category and it should immediately change', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-5&category=outro", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-5"]);
let row2 = db.prepare('get', "SELECT votes FROM categoryVotes WHERE UUID = ? and category = ?", ["vote-uuid-5", "outro"]);
if (row.category === "outro" && row2.votes === 500) {
done();
} else {
done("Vote did not succeed. Submission went from intro to " + row.category + ". Category votes are " + row2.votes + " and should be 500.");
}
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-5&category=outro")
.then(res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-5"]);
let row2 = db.prepare('get', "SELECT votes FROM categoryVotes WHERE UUID = ? and category = ?", ["vote-uuid-5", "outro"]);
if (row.category === "outro" && row2.votes === 500) {
done();
} else {
done("Status code was " + res.statusCode);
done("Vote did not succeed. Submission went from intro to " + row.category + ". Category votes are " + row2.votes + " and should be 500.");
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Submitter should be able to vote for a category and it should immediately change', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=testman&UUID=vote-uuid-5_1&category=outro", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-5"]);
if (row.category === "outro") {
done();
} else {
done("Vote did not succeed. Submission went from intro to " + row.category + ".");
}
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=testman&UUID=vote-uuid-5_1&category=outro")
.then(res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT category FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-5"]);
if (row.category === "outro") {
done();
} else {
done("Status code was " + res.statusCode);
done("Vote did not succeed. Submission went from intro to " + row.category + ".");
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should not be able to category-vote on an invalid UUID submission', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID3&UUID=invalid-uuid&category=intro", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 400) {
done();
} else {
done("Status code was " + res.statusCode + " instead of 400.");
}
});
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID3&UUID=invalid-uuid&category=intro")
.then(res => {
if (res.status === 400) {
done();
} else {
done("Status code was " + res.status + " instead of 400.");
}
})
.catch(err => done(err));
});
it('Non-VIP should not be able to upvote "dead" submission', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-5&type=1", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 403) {
done();
} else {
done("Status code was " + res.statusCode + " instead of 403");
}
});
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=randomID2&UUID=vote-uuid-5&type=1")
.then(res => {
if (res.status === 403) {
done();
} else {
done("Status code was " + res.status + " instead of 403");
}
})
.catch(err => done(err));
});
it('VIP should be able to upvote "dead" submission', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-5&type=1", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-5"]);
if (row.votes > -3) {
done();
} else {
done("Vote did not succeed. Votes raised from -3 to " + row.votes);
}
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=vote-uuid-5&type=1")
.then(res => {
if (res.status === 200) {
let row = db.prepare('get', "SELECT votes FROM sponsorTimes WHERE UUID = ?", ["vote-uuid-5"]);
if (row.votes > -3) {
done();
} else {
done("Status code was " + res.statusCode);
done("Vote did not succeed. Votes raised from -3 to " + row.votes);
}
});
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Should not be able to upvote a segment (Too many warning)', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=warn-voteuser01&UUID=warnvote-uuid-0&type=1", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 403) {
done(); // success
} else {
done("Status code was " + res.statusCode);
}
});
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=warn-voteuser01&UUID=warnvote-uuid-0&type=1")
.then(res => {
if (res.status === 403) {
done(); // success
} else {
done("Status code was " + res.status);
}
})
.catch(err => done(err));
});
it('Non-VIP should not be able to vote on a segment with no-segments category', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=no-segments-voter&UUID=no-sponsor-segments-uuid-0&type=1", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 403) {
done();
} else {
done("Status code was " + res.statusCode + " instead of 403");
}
});
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=no-segments-voter&UUID=no-sponsor-segments-uuid-0&type=1")
.then(res => {
if (res.status === 403) {
done();
} else {
done("Status code was " + res.status + " instead of 403");
}
})
.catch(err => done(err));
});
it('Non-VIP should not be able to category vote on a segment with no-segments category', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=no-segments-voter&UUID=no-sponsor-segments-uuid-0&category=outro", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 403) {
done();
} else {
done("Status code was " + res.statusCode + " instead of 403");
}
});
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=no-segments-voter&UUID=no-sponsor-segments-uuid-0&category=outro")
.then(res => {
if (res.status === 403) {
done();
} else {
done("Status code was " + res.status + " instead of 403");
}
})
.catch(err => done(err));
});
it('VIP should able to vote on a segment with no-segments category', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=no-sponsor-segments-uuid-0&type=1", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
done();
} else {
done("Status code was " + res.statusCode + " instead of 200");
}
});
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=VIPUser&UUID=no-sponsor-segments-uuid-0&type=1")
.then(res => {
if (res.status === 200) {
done();
} else {
done("Status code was " + res.status + " instead of 200");
}
})
.catch(err => done(err));
});
it('Non-VIP should be able to vote on a segment on a no-segments video with a category that doesn\'t have no-segments', (done: Done) => {
request.get(getbaseURL()
+ "/api/voteOnSponsorTime?userID=no-segments-voter&UUID=no-sponsor-segments-uuid-1&type=1", null,
(err, res) => {
if (err) done(err);
else if (res.statusCode === 200) {
done();
} else {
done("Status code was " + res.statusCode + " instead of 200");
}
});
fetch(getbaseURL()
+ "/api/voteOnSponsorTime?userID=no-segments-voter&UUID=no-sponsor-segments-uuid-1&type=1")
.then(res => {
if (res.status === 200) {
done();
} else {
done("Status code was " + res.status + " instead of 200");
}
})
.catch(err => done(err));
});
});