Skip to content

Commit

Permalink
User reviews done
Browse files Browse the repository at this point in the history
  • Loading branch information
akmatchev committed Sep 6, 2023
1 parent 7abfabd commit dc8ffc1
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/api/controllers/PostController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class PostController {
}

@Post('edit/postID/:id/')
async editPrice(@Body() editPriceRequest : EditPostPriceRequest, @CurrentUser() user: UserModel, @Params() params: UuidParam): Promise<EditPriceResponse> {
async editPrice(@Body() editPriceRequest: EditPostPriceRequest, @CurrentUser() user: UserModel, @Params() params: UuidParam): Promise<EditPriceResponse> {
return { new_price: await (await this.postService.editPostPrice(user, params, editPriceRequest)).altered_price };
}
}
3 changes: 2 additions & 1 deletion src/migrations/0000_AddAlteredPrice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export class AddAlteredPrice1681680434289 implements MigrationInterface {
name: "altered_price",
type: "numeric",
scale: 2,
default: 0,
// originally was 0
default: -1,
})
);
}
Expand Down
3 changes: 2 additions & 1 deletion src/repositories/UserReviewRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ export class UserReviewRepository extends AbstractRepository<UserReviewModel> {
return await this.repository
.createQueryBuilder("review")
.leftJoinAndSelect("review.buyer", "user")
.leftJoinAndSelect("review.seller", "user2")
.where("review.id = :id", { id })
.getOne();
}

public async createUserReview(
fulfilled: boolean,
stars: number,
Expand Down
15 changes: 14 additions & 1 deletion src/tests/PostTest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ describe('post tests', () => {

const getPostResponse = await postController.getPostById(uuidParam);
getPostResponse.post.original_price = Number(getPostResponse.post.original_price);
getPostResponse.post.altered_price = Number(getPostResponse.post.altered_price);
expectedPost.created = getPostResponse.post.created;
expect(getPostResponse.post).toEqual(expectedPost);
});
Expand All @@ -107,11 +108,12 @@ describe('post tests', () => {

const getPostsResponse = await postController.getPostsByUserId(uuidParam);
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]);
});

test('create post', async () => {
const user = UserFactory.fakeTemplate();

Expand Down Expand Up @@ -196,6 +198,7 @@ describe('post tests', () => {

const getPostsResponse = await postController.searchPosts(search);
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]);
Expand All @@ -218,6 +221,7 @@ describe('post tests', () => {

const getPostsResponse = await postController.searchPosts(search);
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]);
Expand All @@ -240,6 +244,7 @@ describe('post tests', () => {

const getPostsResponse = await postController.searchPosts(search);
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]);
Expand Down Expand Up @@ -282,6 +287,7 @@ describe('post tests', () => {

let getPostsResponse = await postController.filterPosts(filter);
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]);
Expand All @@ -292,6 +298,7 @@ describe('post tests', () => {

getPostsResponse = await postController.filterPosts(filter);
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]);
Expand Down Expand Up @@ -323,6 +330,7 @@ describe('post tests', () => {

let getPostsResponse = await postController.filterPostsByPrice(filter);
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]);
Expand All @@ -346,6 +354,7 @@ describe('post tests', () => {

let getPostsResponse = await postController.filterPostsByPrice(filter);
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]);
Expand All @@ -368,6 +377,7 @@ describe('post tests', () => {

let getPostsResponse = await postController.filterPostsByPrice(filter);
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]);
Expand Down Expand Up @@ -411,6 +421,7 @@ describe('post tests', () => {
postsResponse = await postController.getSavedPostsByUserId(user);
expect(postsResponse).not.toBeUndefined();
postsResponse.posts[0].original_price = Number(postsResponse.posts[0].original_price);
postsResponse.posts[0].altered_price = Number(postsResponse.posts[0].altered_price);
expectedPost.created = postsResponse.posts[0].created;
expect(postsResponse.posts).toEqual([expectedPost]);

Expand Down Expand Up @@ -475,6 +486,7 @@ describe('post tests', () => {

const getPostsResponse = await postController.getArchivedPostsByUserId(uuidParam);
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]);
Expand Down Expand Up @@ -512,6 +524,7 @@ describe('post tests', () => {

const getPostResponse = await postController.archivePost(post.user, uuidParam);
getPostResponse.post.original_price = Number(getPostResponse.post.original_price);
getPostResponse.post.altered_price = Number(getPostResponse.post.altered_price);
expectedPost.created = getPostResponse.post.created;

expect(getPostResponse.post).toEqual(expectedPost);
Expand Down
18 changes: 9 additions & 9 deletions src/tests/UserReviewTest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let expectedUserReview: UserReviewModel;
let conn: Connection;
let userReviewController: UserReviewController;

beforeAll(async() => {
beforeAll(async () => {
await DatabaseConnection.connect();
});

Expand Down Expand Up @@ -48,9 +48,9 @@ describe('user review tests', () => {
userReview.buyer = UserFactory.fake();
userReview.seller = UserFactory.fake();
await new DataFactory()
.createUserReviews(userReview)
.createUsers(userReview.buyer, userReview.seller)
.write();
.createUserReviews(userReview)
.createUsers(userReview.buyer, userReview.seller)
.write();

const getUserReviewsResponse = await userReviewController.getUserReviews();

Expand All @@ -63,9 +63,9 @@ describe('user review tests', () => {
userReview.seller = UserFactory.fakeTemplate2();

await new DataFactory()
.createUserReviews(userReview)
.createUsers(userReview.buyer, userReview.seller)
.write();
.createUserReviews(userReview)
.createUsers(userReview.buyer, userReview.seller)
.write();

expectedUserReview.buyer = userReview.buyer;
expectedUserReview.seller = userReview.seller;
Expand All @@ -81,8 +81,8 @@ describe('user review tests', () => {
const seller = UserFactory.fakeTemplate2();

await new DataFactory()
.createUsers(buyer, seller)
.write();
.createUsers(buyer, seller)
.write();

const newUserReview = {
fulfilled: false,
Expand Down
8 changes: 5 additions & 3 deletions src/tests/UserSessionTest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ describe('user session tests', () => {
.write();

const getUsersResponse = await authController.deleteUserById(uuidParam);

if (getUsersResponse.user != undefined) {
getUsersResponse.user.stars = Number(getUsersResponse.user.stars);
}
expect(getUsersResponse.user).toEqual(expectedUser);
});

Expand Down Expand Up @@ -105,7 +107,7 @@ describe('user session tests', () => {
.createUsers(user)
.createUserSessions(session)
.write();

const refreshToken = session.refreshToken;
const accessToken = session.accessToken;

Expand All @@ -128,7 +130,7 @@ describe('user session tests', () => {
.createUsers(user)
.createUserSessions(session)
.write();

const refreshToken = session.refreshToken;
const accessToken = session.accessToken;

Expand Down
16 changes: 12 additions & 4 deletions src/tests/UserTest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ describe('user tests', () => {
.write();

const getUserResponse = await userController.getUserById(uuidParam);

if (getUserResponse.user != undefined) {
getUserResponse.user.stars = Number(getUserResponse.user.stars);
}
expect(getUserResponse.user).toEqual(expectedUser);
});

Expand All @@ -99,7 +101,9 @@ describe('user tests', () => {
.write();

const getUserResponse = await userController.getUserByEmail({ email: 'sn999@cornell.edu' });

if (getUserResponse.user != undefined) {
getUserResponse.user.stars = Number(getUserResponse.user.stars);
}
expect(getUserResponse.user).toEqual(expectedUser);
});

Expand All @@ -111,7 +115,9 @@ describe('user tests', () => {
.write();

const getUserResponse = await userController.getUserByGoogleId('shungoGoogleID');

if (getUserResponse.user != undefined) {
getUserResponse.user.stars = Number(getUserResponse.user.stars);
}
expect(getUserResponse.user).toEqual(expectedUser);
});

Expand All @@ -133,7 +139,9 @@ describe('user tests', () => {
expectedUser.venmoHandle = "@Shungo-Najima1";

const getUserResponse = await userController.getUserByGoogleId('shungoGoogleID');

if (getUserResponse.user != undefined) {
getUserResponse.user.stars = Number(getUserResponse.user.stars);
}
expect(getUserResponse.user).toEqual(expectedUser);
});

Expand Down
2 changes: 2 additions & 0 deletions src/tests/data/PostFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class PostFactory {
fakePost.archive = false;
fakePost.categories = ['HANDMADE', 'OTHER'];
fakePost.original_price = 500.15;
fakePost.altered_price = -1;
fakePost.images = ['https://upload.wikimedia.org/wikipedia/commons/thumb/4/48/Kombucha_Mature.jpg/640px-Kombucha_Mature.jpg', 'https://images.heb.com/is/image/HEBGrocery/001017916'];
fakePost.location = 'The Dorm Hotel';

Expand All @@ -48,6 +49,7 @@ export class PostFactory {
fakePost.archive = false;
fakePost.categories = ['SPORTS & OUTDOORS'];
fakePost.original_price = Number(faker.commerce.price(100, 400));
fakePost.altered_price = -1;
fakePost.images = [faker.internet.url()];
fakePost.location = faker.address.city();

Expand Down

0 comments on commit dc8ffc1

Please sign in to comment.