remove ratings tests

This commit is contained in:
Ajay
2022-08-22 11:04:33 -04:00
parent 38a418a37a
commit 8dbfe17ee4
3 changed files with 0 additions and 287 deletions

View File

@@ -1,118 +0,0 @@
import { db } from "../../../src/databases/databases";
import { getHash } from "../../../src/utils/getHash";
import assert from "assert";
import { client } from "../../utils/httpClient";
import { AxiosResponse } from "axios";
import { partialDeepEquals, arrayPartialDeepEquals } from "../../utils/partialDeepEquals";
const endpoint = "/api/ratings/rate";
const getRating = (hash: string, params?: unknown): Promise<AxiosResponse> => client.get(`${endpoint}/${hash}`, { params });
const getBulkRating = (hashes: string[], params?: any): Promise<AxiosResponse> => client.get(endpoint, { params: { ...params, prefix: hashes } });
const videoOneID = "some-likes-and-dislikes";
const videoOneIDHash = getHash(videoOneID, 1);
const videoOnePartialHash = videoOneIDHash.substr(0, 4);
const videoTwoID = "some-likes-and-dislikes-2";
const videoTwoIDHash = getHash(videoTwoID, 1);
const videoTwoPartialHash = videoTwoIDHash.substr(0, 4);
describe("getRating", () => {
before(async () => {
const insertUserNameQuery = 'INSERT INTO "ratings" ("videoID", "service", "type", "count", "hashedVideoID") VALUES (?, ?, ?, ?, ?)';
await db.prepare("run", insertUserNameQuery, [videoOneID, "YouTube", 0, 5, videoOneIDHash]);
await db.prepare("run", insertUserNameQuery, [videoOneID, "YouTube", 1, 10, videoOneIDHash]);
await db.prepare("run", insertUserNameQuery, [videoTwoID, "YouTube", 0, 20, videoTwoIDHash]);
await db.prepare("run", insertUserNameQuery, [videoTwoID, "YouTube", 1, 30, videoTwoIDHash]);
});
it("Should be able to get dislikes and likes by default", (done) => {
getRating(videoOnePartialHash)
.then(res => {
assert.strictEqual(res.status, 200);
const expected = [{
type: 0,
count: 5,
}, {
type: 1,
count: 10,
}];
assert.ok(partialDeepEquals(res.data, expected));
done();
})
.catch(err => done(err));
});
it("Should be able to filter for only dislikes", (done) => {
getRating(videoOnePartialHash, { type: 0 })
.then(res => {
assert.strictEqual(res.status, 200);
const expected = [{
type: 0,
count: 5,
}];
assert.ok(partialDeepEquals(res.data, expected));
done();
})
.catch(err => done(err));
});
/*
This test will fail if tests are already ran with redis.
*/
it("Should be able to bulk fetch", (done) => {
getBulkRating([videoOnePartialHash, videoTwoPartialHash])
.then(res => {
assert.strictEqual(res.status, 200);
const expected = [{
type: 0,
count: 20,
hash: videoTwoIDHash,
},
{
type: 1,
count: 30,
hash: videoTwoIDHash,
}, {
type: 0,
count: 5,
hash: videoOneIDHash,
}, {
type: 1,
count: 10,
hash: videoOneIDHash,
}];
assert.ok(arrayPartialDeepEquals(res.data, expected));
done();
})
.catch(err => done(err));
});
it("Should return 400 for invalid hash", (done) => {
getRating("a")
.then(res => {
assert.strictEqual(res.status, 400);
done();
})
.catch(err => done(err));
});
it("Should return 404 for nonexitent type", (done) => {
getRating(videoOnePartialHash, { type: 100 })
.then(res => {
assert.strictEqual(res.status, 404);
done();
})
.catch(err => done(err));
});
it("Should return 404 for nonexistent videoID", (done) => {
getRating("aaaa")
.then(res => {
assert.strictEqual(res.status, 404);
done();
})
.catch(err => done(err));
});
});

View File

@@ -1,51 +0,0 @@
import { db } from "../../../src/databases/databases";
import { getHash } from "../../../src/utils/getHash";
import assert from "assert";
import { client } from "../../utils/httpClient";
const VIPUser = "clearCacheVIP";
const regularUser = "regular-user";
const endpoint = "/api/ratings/clearCache";
const postClearCache = (userID: string, videoID: string) => client({ method: "post", url: endpoint, params: { userID, videoID } });
describe("ratings postClearCache", () => {
before(async () => {
await db.prepare("run", `INSERT INTO "vipUsers" ("userID") VALUES ('${getHash(VIPUser)}')`);
});
it("Should be able to clear cache amy video", (done) => {
postClearCache(VIPUser, "dne-video")
.then(res => {
assert.strictEqual(res.status, 200);
done();
})
.catch(err => done(err));
});
it("Should get 403 as non-vip", (done) => {
postClearCache(regularUser, "clear-test")
.then(res => {
assert.strictEqual(res.status, 403);
done();
})
.catch(err => done(err));
});
it("Should give 400 with missing videoID", (done) => {
client.post(endpoint, { params: { userID: VIPUser } })
.then(res => {
assert.strictEqual(res.status, 400);
done();
})
.catch(err => done(err));
});
it("Should give 400 with missing userID", (done) => {
client.post(endpoint, { params: { videoID: "clear-test" } })
.then(res => {
assert.strictEqual(res.status, 400);
done();
})
.catch(err => done(err));
});
});

View File

@@ -1,118 +0,0 @@
import { db } from "../../../src/databases/databases";
import { getHash } from "../../../src/utils/getHash";
import assert from "assert";
import { client } from "../../utils/httpClient";
import { AxiosResponse } from "axios";
import { partialDeepEquals } from "../../utils/partialDeepEquals";
const endpoint = "/api/ratings/rate/";
const postRating = (body: unknown): Promise<AxiosResponse> => client.post(endpoint, body);
const queryDatabase = (videoID: string) => db.prepare("all", `SELECT * FROM "ratings" WHERE "videoID" = ?`, [videoID]);
const videoIDOne = "normal-video";
const videoIDTwo = "multiple-rates";
const ratingUserID = "rating-testman";
describe("postRating", () => {
before(async () => {
const insertUserNameQuery = 'INSERT INTO "ratings" ("videoID", "service", "type", "count", "hashedVideoID") VALUES (?, ?, ?, ?, ?)';
await db.prepare("run", insertUserNameQuery, [videoIDTwo, "YouTube", 0, 3, getHash(videoIDTwo, 1)]);
});
it("Should be able to vote on a video", (done) => {
const videoID = videoIDOne;
postRating({
userID: ratingUserID,
videoID,
type: 0
})
.then(async res => {
assert.strictEqual(res.status, 200);
const expected = [{
hashedVideoID: getHash(videoID, 1),
videoID,
type: 0,
count: 1,
service: "YouTube"
}];
assert.ok(partialDeepEquals(await queryDatabase(videoID), expected));
done();
})
.catch(err => done(err));
});
it("Should be able to undo a vote on a video", (done) => {
const videoID = videoIDOne;
postRating({
userID: ratingUserID,
videoID,
type: 0,
enabled: false
})
.then(async res => {
assert.strictEqual(res.status, 200);
const expected = [{
type: 0,
count: 0
}];
assert.ok(partialDeepEquals(await queryDatabase(videoID), expected));
done();
})
.catch(err => done(err));
});
it("Should be able to vote after someone else on a video", (done) => {
const videoID = videoIDTwo;
postRating({
userID: ratingUserID,
videoID,
type: 0
})
.then(async res => {
assert.strictEqual(res.status, 200);
const expected = [{
type: 0,
count: 4
}];
assert.ok(partialDeepEquals(await queryDatabase(videoID), expected));
done();
})
.catch(err => done(err));
});
it("Should be able to vote a different type than existing votes on a video", (done) => {
const videoID = videoIDTwo;
postRating({
userID: ratingUserID,
videoID,
type: 1
})
.then(async res => {
assert.strictEqual(res.status, 200);
const expected = [{
type: 0,
count: 4
}, {
type: 1,
count: 1
}];
assert.ok(partialDeepEquals(await queryDatabase(videoID), expected));
done();
})
.catch(err => done(err));
});
it("Should not be able to vote with nonexistent type", (done) => {
const videoID = videoIDOne;
postRating({
userID: ratingUserID,
videoID,
type: 100
})
.then(res => {
assert.strictEqual(res.status, 400);
done();
})
.catch(err => done(err));
});
});