The Post is in this project considered to be a key aspect of the program functionality and warrants a high level of scrutiny.
Following TDD format the tests will expand as the code expands.
Tests to begin with
The tests should at least test the following functions:
findByIDfindAllcreatesave
Coverage and quality
The tests should have a high code coverage and high test quality. Meaning that functions should be tested in multiple ways, considering edge cases and providing 'depth'.
Test example for Post
// post.spec.js
describe('Post Model', () => {
describe('fromDb', () => {
it('should create a Post instance from a database object', () => {
const dbPost = {
id: 1,
content: 'This is a test post',
userId: 1,
user: {
id: 1,
cohortId: 2,
email: 'test@example.com',
profile: {
firstName: 'John',
lastName: 'Doe',
bio: 'Software Engineer',
githubUrl: 'https://github.com/johndoe'
},
password: 'hashedpassword',
role: 'STUDENT'
},
createdAt: new Date(),
updatedAt: new Date(),
};
const post = Post.fromDb(dbPost);
expect(post).toBeInstanceOf(Post);
expect(post.id).toBe(dbPost.id);
expect(post.content).toBe(dbPost.content);
expect(post.userId).toBe(dbPost.userId);
expect(post.user).toEqual(dbPost.user);
expect(post.createdAt).toEqual(dbPost.createdAt);
expect(post.updatedAt).toEqual(dbPost.updatedAt);
});
});
});
Post Automated Test
The Post is in this project considered to be a key aspect of the program functionality and warrants a high level of scrutiny. Following TDD format the tests will expand as the code expands.
Tests to begin with
The tests should at least test the following functions:
findByID
findAll
create
save
Coverage and quality
The tests should have a high code coverage and high test quality. Meaning that functions should be tested in multiple ways, considering edge cases and providing 'depth'.
Test example for Post