Skip to content

Commit

Permalink
Merge pull request #96 from cuappdev/fix-tests
Browse files Browse the repository at this point in the history
Fixed tests
  • Loading branch information
Daniel-jw authored Nov 10, 2024
2 parents c357e9d + 65c606b commit e57679c
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 3 deletions.
13 changes: 13 additions & 0 deletions src/migrations/1731186421123-addarchivetorequests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {MigrationInterface, QueryRunner} from "typeorm";

export class AddArchiveToRequest1731186421123 implements MigrationInterface {
name = 'AddArchiveToRequest1731186421123'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "Request" ADD COLUMN IF NOT EXISTS "archive" boolean NOT NULL DEFAULT false`);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "Request" DROP COLUMN IF EXISTS "archive"`);
}
}
1 change: 1 addition & 0 deletions src/models/RequestModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class RequestModel {
id: this.id,
title: this.title,
description: this.description,
archive: this.archive,
user: this.user,
matches: this.matches,
};
Expand Down
2 changes: 1 addition & 1 deletion src/repositories/PostRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class PostRepository extends AbstractRepository<PostModel> {
.createQueryBuilder()
.update(PostModel)
.set({ archive: true })
.where("userId = :userId", { userId })
.where("user.id = :userId", { userId })
.execute();
}

Expand Down
4 changes: 3 additions & 1 deletion src/repositories/RequestRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ export class RequestRepository extends AbstractRepository<RequestModel> {
public async createRequest(
title: string,
description: string,
archive: boolean,
user: UserModel
): Promise<RequestModel> {
const request = this.repository.create({
title,
description,
archive,
user,
});
await this.repository.save(request);
Expand All @@ -56,7 +58,7 @@ export class RequestRepository extends AbstractRepository<RequestModel> {
.createQueryBuilder()
.update(RequestModel)
.set({ archive: true })
.where("userId = :userId", { userId })
.where("user.id = :userId", { userId })
.execute();
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/RequestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class RequestService {
const user = await userRepository.getUserById(request.userId);
if (!user) throw new NotFoundError('User not found!');
const requestRepository = Repositories.request(transactionalEntityManager);
return await requestRepository.createRequest(request.title, request.description, user);
return await requestRepository.createRequest(request.title, request.description, request.archive, user);
});
}

Expand Down
2 changes: 2 additions & 0 deletions src/tests/RequestTest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ beforeEach(async () => {
expectedRequest.id = '81e6896c-a549-41bf-8851-604e7fbd4f1f';
expectedRequest.title = 'Textbook';
expectedRequest.description = 'Textbook for CS 1110';
expectedRequest.archive = false;
});

afterAll(async () => {
Expand Down Expand Up @@ -105,6 +106,7 @@ describe('request tests', () => {
const newRequest = {
title: 'Textbook',
description: 'Textbook for CS 1110',
archive: false,
userId: user.id,
};

Expand Down
1 change: 1 addition & 0 deletions src/tests/data/RequestFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class RequestFactory {
fakeRequest.id = '81e6896c-a549-41bf-8851-604e7fbd4f1f';
fakeRequest.title = 'Textbook';
fakeRequest.description = 'Textbook for CS 1110';
fakeRequest.archive = false;

return fakeRequest;
}
Expand Down
1 change: 1 addition & 0 deletions src/types/ApiRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export interface UploadImageRequest {
export interface CreateRequestRequest {
title: string;
description: string;
archive: boolean;
userId: Uuid;
}

Expand Down
1 change: 1 addition & 0 deletions src/types/ApiResponses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export interface Request {
id: Uuid;
title: string;
description: string;
archive: boolean;
user: PrivateProfile;
matches: PostModel[];
}
Expand Down

0 comments on commit e57679c

Please sign in to comment.