Unit tests for Citation

This commit is contained in:
Chegele 2023-07-06 15:46:47 -04:00
parent 42e2d05177
commit 0093c9eba1
1 changed files with 102 additions and 0 deletions

View File

@ -0,0 +1,102 @@
import { Edge } from "../graph.interface";
import { Citation } from "./citation";
import { Member } from "./member";
import { Post } from "./post";
describe('Reputation Service Citation', () => {
let testingPostA: Post;
let testingPostB: Post;
let testingCitation: Citation;
const TEST_AUTHOR_A = new Member("testAuthorA");
const TEST_TITLE_A = "The Hitchhiker's Guide to the Galaxy";
const TEST_CONTENT_A = "The ships hung in the sky in much the same way that bricks don't.";
const TEST_AUTHOR_B = new Member("testAuthorB");
const TEST_TITLE_B = "The Restaurant at the End of the Universe";
const TEST_CONTENT_B = "The story so far: In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move.";
beforeEach(() => {
testingPostA = new Post("testingPostA", TEST_TITLE_A, TEST_CONTENT_A, TEST_AUTHOR_A);
testingPostB = new Post("testingPostB", TEST_TITLE_B, TEST_CONTENT_B, TEST_AUTHOR_B);
testingCitation = new Citation("testingCitation", testingPostA, testingPostB, 10);
});
it('should be able to get all citations', () => {
const citations = Citation.getAllCitations();
expect(citations.length).toBe(1);
});
it('should be able to get a specific citation', () => {
const citation = Citation.getCitation("testingCitation");
expect(citation).toBeDefined();
expect(citation?.id).toBe("testingCitation");
});
it('should be able to create a new citation with random id', () => {
const citation = new Citation(null, testingPostA, testingPostB, 10);
expect(typeof citation.id).toBe("string");
expect(citation.id.length).toBeGreaterThan(5);
});
it('should be able to create a new citation with specific id', () => {
const citation = new Citation("testing", testingPostA, testingPostB, 10);
expect(citation.id).toBe("testing");
});
it('should be able to get the id of a citation', () => {
expect(testingCitation.id).toBe("testingCitation");
});
it('should be able to get if the citation is directional', () => {
expect(testingCitation.directional).toBe(true);
});
it('should be able to get the sourcePost from a citation', () => {
expect(testingCitation.sourcePost).toBe(testingPostA);
});
it('should be able to get the citedPost from a citation', () => {
expect(testingCitation.citedPost).toBe(testingPostB);
});
it('should be able to get the impact of a citation', () => {
expect(testingCitation.impact).toBe(10);
});
it('should be able to get if a citation is neutral', () => {
const citation = new Citation("testing", testingPostA, testingPostB, 0);
expect(citation.isNeutral()).toBe(true);
});
it('should be able to get if a citation is positive', () => {
const citation = new Citation("testing", testingPostA, testingPostB, 10);
expect(citation.isPositive()).toBe(true);
});
it('should be able to get if a citation is negative', () => {
const citation = new Citation("testing", testingPostA, testingPostB, -10);
expect(citation.isNegative()).toBe(true);
});
it('should be able to get the parentVertex from Citation as an Edge', () => {
const edge = testingCitation as Edge;
expect(edge.parentVertex).toBeDefined();
expect(edge.parentVertex).toBe(testingPostB);
});
it('should be able to get the childVertex from Citation as an Edge', () => {
const edge = testingCitation as Edge;
expect(edge.childVertex).toBeDefined();
expect(edge.childVertex).toBe(testingPostA);
});
it('should be able to get the adjacent Vertex from Citation as an Edge', () => {
const edge = testingCitation as Edge;
expect(edge.getAdjacent(testingPostA)).toBe(testingPostB);
expect(edge.getAdjacent(testingPostB)).toBe(testingPostA);
});
});