Skip to content

Commit

Permalink
Merge pull request #94 from cuappdev/ashley/fix-testing
Browse files Browse the repository at this point in the history
fix: debugging getPostsByUserId and test suite
  • Loading branch information
mateow99 authored Nov 9, 2024
2 parents 510499d + 975cb53 commit c357e9d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
8 changes: 3 additions & 5 deletions src/services/PostService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@ export class PostService {

public async getPostsByUserId(currentUser: UserModel, params: UuidParam): Promise<PostModel[]> {
return this.transactions.readOnly(async (transactionalEntityManager) => {
const userRepository = Repositories.user(transactionalEntityManager);
const user = await userRepository.getUserById(params.id)
if (!user) throw new NotFoundError('User not found!');
if (!user.isActive) throw new NotFoundError('User is not active!');
return this.filterBlockedUserPosts(user.posts, currentUser);
const postRepository = Repositories.post(transactionalEntityManager);
const userPosts = await postRepository.getPostsByUserId(params.id);
return this.filterBlockedUserPosts(userPosts, currentUser);
});
}

Expand Down
9 changes: 2 additions & 7 deletions src/tests/PostTest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,9 @@ describe('post tests', () => {
.createUsers(post.user)
.write();

expectedPost.user = post.user;

const getPostsResponse = await postController.getPostsByUserId(post.user, uuidParam);
const getPostsResponse = await postController.getPostsByUserId(post.user, {id: post.user.id});
getPostsResponse.posts[0].original_price = Number(getPostsResponse.posts[0].original_price);
getPostsResponse.posts[0].altered_price = Number(getPostsResponse.posts[0].altered_price);
expectedPost.created = getPostsResponse.posts[0].created;

expect(getPostsResponse.posts).toEqual([expectedPost]);
expect(getPostsResponse.posts).toEqual([post]);
});

test('create post', async () => {
Expand Down

0 comments on commit c357e9d

Please sign in to comment.