Unit tests for member

This commit is contained in:
Chegele 2023-07-06 15:46:25 -04:00
parent 824e0a6b39
commit 81303586d7
1 changed files with 70 additions and 0 deletions

View File

@ -0,0 +1,70 @@
import { Member } from "./member";
describe('Reputation Service Member', () => {
let testMemberA: Member;
let testMemberB: Member;
beforeEach(() => {
testMemberA = new Member("testMemberA");
testMemberB = new Member("testMemberB");
});
it('should be able to get all members', () => {
const members = Member.getAllMembers();
expect(members.length).toBe(2);
expect(members[0]).toBe(testMemberA);
expect(members[1]).toBe(testMemberB);
});
it('should be able to get a specific member', () => {
const member = Member.getMember("testMemberA");
expect(member).toBeDefined();
});
it('should be able to create a new member with random id', () => {
const member = new Member();
expect(typeof member.id).toBe("string");
expect(member.id.length).toBeGreaterThan(5);
});
it('should be able to create a new member with specific id', () => {
const member = new Member("testing");
expect(member.id).toBe("testing");
});
it('should be able to get the id of a member', () => {
expect(testMemberA.id).toBe("testMemberA");
});
it('should be able to get the reputation of a member', () => {
expect(testMemberA.reputation).toBe(0);
});
it('should be able to get the ledger for a member', () => {
expect(testMemberA.ledger.length).toBe(0);
});
it('should produce a ledger entry when modifying reputation', () => {
const entry = testMemberA.postReputation("testPost", 10);
expect(testMemberA.ledger.length).toBe(1);
expect(testMemberA.ledger[0]).toBe(entry);
expect(entry.timestamp).toBeDefined();
expect(entry.type).toBe("post");
expect(entry.postId).toBe("testPost");
expect(entry.citationId).toBeNull();
expect(entry.change).toBe(10);
expect(entry.balance).toBe(10);
});
it('should be able to modify members reputation with a post', () => {
testMemberA.postReputation("testPost", 10);
expect(testMemberA.reputation).toBe(10);
});
it('should be able to modify members reputation with a citation', () => {
testMemberA.citationReputation("testPost", "testCitation", 10);
expect(testMemberA.reputation).toBe(10);
});
});