Skip to content

Commit c357e9d

Browse files
authored
Merge pull request #94 from cuappdev/ashley/fix-testing
fix: debugging getPostsByUserId and test suite
2 parents 510499d + 975cb53 commit c357e9d

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

src/services/PostService.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,9 @@ export class PostService {
4444

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

src/tests/PostTest.test.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,9 @@ describe('post tests', () => {
104104
.createUsers(post.user)
105105
.write();
106106

107-
expectedPost.user = post.user;
108-
109-
const getPostsResponse = await postController.getPostsByUserId(post.user, uuidParam);
107+
const getPostsResponse = await postController.getPostsByUserId(post.user, {id: post.user.id});
110108
getPostsResponse.posts[0].original_price = Number(getPostsResponse.posts[0].original_price);
111-
getPostsResponse.posts[0].altered_price = Number(getPostsResponse.posts[0].altered_price);
112-
expectedPost.created = getPostsResponse.posts[0].created;
113-
114-
expect(getPostsResponse.posts).toEqual([expectedPost]);
109+
expect(getPostsResponse.posts).toEqual([post]);
115110
});
116111

117112
test('create post', async () => {

0 commit comments

Comments
 (0)