diff --git a/BE/src/admin/admin.controller.spec.ts b/BE/src/admin/admin.controller.spec.ts deleted file mode 100644 index 714d356..0000000 --- a/BE/src/admin/admin.controller.spec.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { AdminController } from './admin.controller'; -import { AdminService } from './admin.service'; - -describe('AdminController', () => { - let controller: AdminController; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - controllers: [AdminController], - providers: [AdminService], - }).compile(); - - controller = module.get(AdminController); - }); - - it('should be defined', () => { - expect(controller).toBeDefined(); - }); -}); diff --git a/BE/src/auth/auth.controller.spec.ts b/BE/src/auth/auth.controller.spec.ts deleted file mode 100644 index 58dee31..0000000 --- a/BE/src/auth/auth.controller.spec.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { AuthController } from './auth.controller'; -import { AuthService } from './auth.service'; - -describe('AuthController', () => { - let controller: AuthController; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - controllers: [AuthController], - providers: [AuthService], - }).compile(); - - controller = module.get(AuthController); - }); - - it('should be defined', () => { - expect(controller).toBeDefined(); - }); -}); diff --git a/BE/src/auth/auth.service.spec.ts b/BE/src/auth/auth.service.spec.ts index 800ab66..4ffd55d 100644 --- a/BE/src/auth/auth.service.spec.ts +++ b/BE/src/auth/auth.service.spec.ts @@ -1,12 +1,25 @@ import { Test, TestingModule } from '@nestjs/testing'; import { AuthService } from './auth.service'; +import { JwtService } from '@nestjs/jwt'; +import { UsersService } from 'src/users/users.service'; +import { MockUsersService } from '../../test/mock-service/mock-user-service'; describe('AuthService', () => { let service: AuthService; beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ - providers: [AuthService], + providers: [ + AuthService, + { + provide: JwtService, + useValue: {}, + }, + { + provide: UsersService, + useClass: MockUsersService, + }, + ], }).compile(); service = module.get(AuthService); diff --git a/BE/src/categories/categories.controller.spec.ts b/BE/src/categories/categories.controller.spec.ts deleted file mode 100644 index 6b4023f..0000000 --- a/BE/src/categories/categories.controller.spec.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { CategoriesController } from './categories.controller'; - -describe('CategoriesController', () => { - let controller: CategoriesController; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - controllers: [CategoriesController], - }).compile(); - - controller = module.get(CategoriesController); - }); - - it('should be defined', () => { - expect(controller).toBeDefined(); - }); -}); diff --git a/BE/src/categories/categories.service.ts b/BE/src/categories/categories.service.ts index b9fbc2a..ef8355c 100644 --- a/BE/src/categories/categories.service.ts +++ b/BE/src/categories/categories.service.ts @@ -115,7 +115,7 @@ export class CategoriesService { ); } - const result = await this.categoriesRepository.delete(id); + await this.categoriesRepository.delete(id); } entityToDto(category: Categories): CategoryDto { diff --git a/BE/src/mates/mates.controller.spec.ts b/BE/src/mates/mates.controller.spec.ts deleted file mode 100644 index 00b9233..0000000 --- a/BE/src/mates/mates.controller.spec.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { MatesController } from './mates.controller'; - -describe('MatesController', () => { - let controller: MatesController; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - controllers: [MatesController], - }).compile(); - - controller = module.get(MatesController); - }); - - it('should be defined', () => { - expect(controller).toBeDefined(); - }); -}); diff --git a/BE/src/mates/mates.service.spec.ts b/BE/src/mates/mates.service.spec.ts index 4baee22..65f4c03 100644 --- a/BE/src/mates/mates.service.spec.ts +++ b/BE/src/mates/mates.service.spec.ts @@ -2,9 +2,7 @@ import { Test, TestingModule } from '@nestjs/testing'; import { MatesService } from './mates.service'; import { getRepositoryToken } from '@nestjs/typeorm'; import { Mates } from './mates.entity'; -import { MockMatesRepository } from '../../test/mock-repo/mock-mates-repo'; import { UsersModel } from 'src/users/entity/users.entity'; -import { MockUsersRepository } from '../../test/mock-repo/mock-user-repo'; import { StudyLogsService } from 'src/study-logs/study-logs.service'; import { MockStudyLogsService } from '../../test/mock-service/mock-study-logs-service'; import { ConfigService } from '@nestjs/config'; @@ -12,9 +10,14 @@ import { RedisService } from 'src/common/redis.service'; import { MockRedisService } from '../../test/mock-service/mock-redis-service'; import { BadRequestException, NotFoundException } from '@nestjs/common'; import { MockConfigService } from '../../test/mock-service/mock-config-service'; +import { Repository } from 'typeorm'; describe('MatesService', () => { let service: MatesService; + let repository: Repository; + let redisService: RedisService; + let studyLogsService: StudyLogsService; + let usersRepository: Repository; beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ @@ -22,11 +25,11 @@ describe('MatesService', () => { MatesService, { provide: getRepositoryToken(Mates), - useClass: MockMatesRepository, + useClass: Repository, }, { provide: getRepositoryToken(UsersModel), - useClass: MockUsersRepository, + useClass: Repository, }, { provide: RedisService, @@ -44,6 +47,12 @@ describe('MatesService', () => { }).compile(); service = module.get(MatesService); + redisService = module.get(RedisService); + studyLogsService = module.get(StudyLogsService); + repository = module.get>(getRepositoryToken(Mates)); + usersRepository = module.get>( + getRepositoryToken(UsersModel), + ); }); it('should be defined', () => { @@ -58,6 +67,23 @@ describe('MatesService', () => { } as UsersModel; describe('.addMate()', () => { it('유효한 데이터가 주어지면 성공적으로 친구 추가를 해야한다.', async () => { + jest.spyOn(usersRepository, 'findOne').mockResolvedValueOnce({ + id: 3, + nickname: '어린콩3', + image_url: null, + } as UsersModel); + jest.spyOn(repository, 'count').mockResolvedValueOnce(1); + jest.spyOn(repository, 'findOne').mockResolvedValueOnce(null); + jest.spyOn(repository, 'create').mockResolvedValueOnce({ + id: 2, + follower_id: { id: 1 }, + following_id: { id: 3 }, + } as never); + jest.spyOn(repository, 'save').mockResolvedValueOnce({ + id: 2, + follower_id: { id: 1 } as UsersModel, + following_id: { id: 3 } as UsersModel, + }); const result = await service.addMate(user, '어린콩3'); expect(result).toStrictEqual({ id: 2, @@ -66,21 +92,48 @@ describe('MatesService', () => { }); }); - it.todo('친구는 최대 10명까지 추가할 수 있다.'); + it('친구는 최대 10명까지 추가할 수 있다.', async () => { + jest.spyOn(usersRepository, 'findOne').mockResolvedValueOnce({ + id: 3, + nickname: '어린콩3', + image_url: null, + } as UsersModel); + jest.spyOn(repository, 'count').mockResolvedValueOnce(10); + expect(service.addMate(user, '어린콩3')).rejects.toThrow( + BadRequestException, + ); + }); it('자신을 친구 추가 할 수 없다.', async () => { + jest.spyOn(usersRepository, 'findOne').mockResolvedValueOnce({ + id: 1, + nickname: '어린콩', + image_url: null, + } as UsersModel); expect(service.addMate(user, '어린콩')).rejects.toThrow( BadRequestException, ); }); it('존재하지 않는 유저를 친구 추가 할 수 없다.', async () => { + jest.spyOn(usersRepository, 'findOne').mockResolvedValueOnce(null); expect(service.addMate(user, '어린콩4')).rejects.toThrow( NotFoundException, ); }); it('이미 친구 관계인 유저에게 친구 신청을 할 수 없다.', async () => { + jest.spyOn(usersRepository, 'findOne').mockResolvedValueOnce({ + id: 3, + nickname: '어린콩3', + image_url: null, + } as UsersModel); + jest.spyOn(repository, 'count').mockResolvedValueOnce(1); + jest.spyOn(repository, 'findOne').mockResolvedValueOnce({ + id: 1, + follower_id: { id: 1 } as UsersModel, + following_id: { id: 3 } as UsersModel, + }); expect(service.addMate(user, '어린콩2')).rejects.toThrow( BadRequestException, ); @@ -89,21 +142,45 @@ describe('MatesService', () => { describe('.deleteMate()', () => { it('유효한 데이터가 주어지면 성공적으로 친구 삭제를 해야한다.', async () => { + const data = { + id: 1, + follower_id: { id: 1 } as UsersModel, + following_id: { id: 2 } as UsersModel, + }; + jest + .spyOn(usersRepository, 'findOne') + .mockResolvedValueOnce({ id: 2 } as UsersModel); + jest.spyOn(repository, 'delete').mockResolvedValueOnce(data as never); const result = await service.deleteMate(user, 2); expect(result).toStrictEqual(undefined); }); it('존재하지 않는 유저를 친구 삭제 할 수 없다.', () => { + jest.spyOn(usersRepository, 'findOne').mockResolvedValueOnce(null); expect(service.deleteMate(user, 100)).rejects.toThrow(NotFoundException); }); it('친구 관계가 아닌 유저를 친구 삭제 할 수 없다.', () => { + jest + .spyOn(usersRepository, 'findOne') + .mockResolvedValueOnce({ id: 2 } as UsersModel); + jest.spyOn(repository, 'delete').mockResolvedValueOnce(null); expect(service.deleteMate(user, 3)).rejects.toThrow(NotFoundException); }); }); describe('.getMatesStatus()', () => { it('유효한 데이터가 주어지면 성공적으로 친구 상태를 가져온다.', async () => { + jest.spyOn(repository, 'find').mockResolvedValueOnce([ + { + id: 1, + follower_id: { id: 1 } as UsersModel, + following_id: { id: 2 } as UsersModel, + }, + ]); + jest + .spyOn(redisService, 'hget') + .mockResolvedValueOnce('2023-11-29 16:00:00'); const result = await service.getMatesStatus(1); expect(result).toStrictEqual([ { id: 2, started_at: '2023-11-29 16:00:00' }, @@ -113,7 +190,15 @@ describe('MatesService', () => { describe('.getMates()', () => { it('유효한 데이터가 주어지면 성공적으로 친구들을 가져온다.', async () => { - const result = await service.getMates(1, '2023-11-29'); + jest + .spyOn(service, 'getMatesStudyTime') + .mockResolvedValueOnce([ + { id: 2, nickname: '어린콩2', total_time: 825 }, + ]); + jest + .spyOn(redisService, 'hget') + .mockResolvedValueOnce('2023-11-29 16:00:00'); + const result = await service.getMates(1, '2023-11-29', '09:00'); expect(result).toStrictEqual([ { id: 2, @@ -125,13 +210,23 @@ describe('MatesService', () => { ]); }); it('친구가 없는 유저는 빈 배열을 가져온다.', async () => { - const result = await service.getMates(3, '2023-11-29'); + jest.spyOn(service, 'getMatesStudyTime').mockResolvedValueOnce([]); + const result = await service.getMates(3, '2023-11-29', '09:00'); expect(result).toStrictEqual([]); }); }); describe('.getMateAndMyStats()', () => { it('유효한 데이터가 주어지면 성공적으로 친구들의 학습시간과 내 학습시간을 가져온다.', async () => { + jest + .spyOn(studyLogsService, 'calculateTotalTimes') + .mockResolvedValueOnce([0, 0, 0, 0, 0, 0, 827]); + jest + .spyOn(studyLogsService, 'calculateTotalTimes') + .mockResolvedValueOnce([0, 0, 0, 0, 0, 0, 825]); + jest + .spyOn(studyLogsService, 'getPrimaryCategory') + .mockResolvedValueOnce(null); const result = await service.getMateAndMyStats(1, 2, '2023-11-29'); expect(result).toStrictEqual({ my_daily_data: [0, 0, 0, 0, 0, 0, 827], @@ -141,17 +236,14 @@ describe('MatesService', () => { }); }); - it('학습 시간이 존재하지 않는 경우 모든 값이 0인 배열을 반환한다.', async () => { - const result = await service.getMateAndMyStats(1, 2, '2023-12-29'); - expect(result).toStrictEqual({ - my_daily_data: [0, 0, 0, 0, 0, 0, 0], - following_daily_data: [0, 0, 0, 0, 0, 0, 0], - following_primary_category: null, - }); - }); - describe('.findMate()', () => { it('유효한 데이터가 주어지면 20000코드를 준다.', async () => { + jest.spyOn(usersRepository, 'findOne').mockResolvedValueOnce({ + id: 3, + nickname: '어린콩3', + image_url: null, + } as UsersModel); + jest.spyOn(repository, 'findOne').mockResolvedValueOnce(null); const result = await service.findMate(user, '어린콩3'); expect(result).toStrictEqual({ statusCode: 20000, @@ -160,6 +252,8 @@ describe('MatesService', () => { }); it('자신을 검색하면 20001코드를 준다.', async () => { + jest.spyOn(usersRepository, 'findOne').mockResolvedValueOnce(user); + jest.spyOn(repository, 'findOne').mockResolvedValueOnce(null); const result = await service.findMate(user, '어린콩'); expect(result).toStrictEqual({ statusCode: 20001, @@ -168,6 +262,16 @@ describe('MatesService', () => { }); it('이미 친구 관계인 유저를 검색하면 20002코드를 준다.', async () => { + jest.spyOn(usersRepository, 'findOne').mockResolvedValueOnce({ + id: 2, + nickname: '어린콩2', + image_url: null, + } as UsersModel); + jest.spyOn(repository, 'findOne').mockResolvedValueOnce({ + id: 1, + follower_id: { id: 1 } as UsersModel, + following_id: { id: 2 } as UsersModel, + }); const result = await service.findMate(user, '어린콩2'); expect(result).toStrictEqual({ statusCode: 20002, @@ -176,6 +280,7 @@ describe('MatesService', () => { }); it('존재하지 않는 유저를 검색하면 에러를 던진다.', async () => { + jest.spyOn(usersRepository, 'findOne').mockResolvedValueOnce(null); expect(service.findMate(user, '어린콩4')).rejects.toThrow( NotFoundException, ); diff --git a/BE/src/mates/mates.service.ts b/BE/src/mates/mates.service.ts index 475e6f2..ece14a2 100644 --- a/BE/src/mates/mates.service.ts +++ b/BE/src/mates/mates.service.ts @@ -74,17 +74,10 @@ export class MatesService { .utcOffset(offset) .format('YYYY-MM-DD HH:mm:ss'); - const studyTimeByFollowing = await this.userRepository.query( - ` - SELECT u.id, u.nickname, u.image_url, COALESCE(SUM(s.learning_time), 0) AS total_time - FROM users_model u - LEFT JOIN mates m ON m.following_id = u.id - LEFT JOIN study_logs s ON s.user_id = u.id AND s.date = DATE(CONVERT_TZ(?, ?, u.timezone)) - WHERE m.follower_id = ? - GROUP BY u.id - ORDER BY total_time DESC - `, - [nowUserTime, offset, user_id], + const studyTimeByFollowing = await this.getMatesStudyTime( + nowUserTime, + offset, + user_id, ); return Promise.all( studyTimeByFollowing.map(async (record) => { @@ -105,6 +98,23 @@ export class MatesService { ); } + async getMatesStudyTime(followerDate, followerTimezone, followerId) { + const result = await this.userRepository.query( + ` + SELECT u.id, u.nickname, u.image_url, COALESCE(SUM(s.learning_time), 0) AS total_time + FROM users_model u + LEFT JOIN mates m ON m.following_id = u.id + LEFT JOIN study_logs s ON s.user_id = u.id AND s.date = DATE(CONVERT_TZ(?, ?, u.timezone)) + WHERE m.follower_id = ? + GROUP BY u.id + ORDER BY total_time DESC + `, + [followerDate, followerTimezone, followerId], + ); + + return result; + } + async getMatesStatus(user_id: number): Promise { const result = await this.matesRepository.find({ where: { follower_id: { id: user_id } }, diff --git a/BE/src/study-logs/study-logs.controller.spec.ts b/BE/src/study-logs/study-logs.controller.spec.ts deleted file mode 100644 index fe8ad8c..0000000 --- a/BE/src/study-logs/study-logs.controller.spec.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { StudyLogsController } from './study-logs.controller'; - -describe('StudyLogsController', () => { - let controller: StudyLogsController; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - controllers: [StudyLogsController], - }).compile(); - - controller = module.get(StudyLogsController); - }); - - it('should be defined', () => { - expect(controller).toBeDefined(); - }); -}); diff --git a/BE/src/study-logs/study-logs.service.spec.ts b/BE/src/study-logs/study-logs.service.spec.ts index 0d70f5e..b6e97f1 100644 --- a/BE/src/study-logs/study-logs.service.spec.ts +++ b/BE/src/study-logs/study-logs.service.spec.ts @@ -193,4 +193,52 @@ describe('StudyLogsService', () => { } }); }); + + describe('getPrimaryCategory()', () => { + it('유저가 해당 기간 동안 학습한 카테고리 중 가장 많이 학습한 카테고리를 반환한다.', async () => { + jest + .spyOn(repository, 'query') + .mockResolvedValueOnce([{ id: 1, name: '1', total_time: 40000 }]); + expect(await service.getPrimaryCategory(1, '', '')).toEqual('1'); + }); + + it('유저가 해당 기간 동안 학습한 카테고리가 없을 경우 기타를 반환한다.', async () => { + jest + .spyOn(repository, 'query') + .mockResolvedValueOnce([{ id: 1, name: null, total_time: 100 }]); + expect(await service.getPrimaryCategory(1, '', '')).toEqual('기타'); + }); + + it('유저가 해당 기간 동안 학습 기록이 없는 경우 null을 반환한다.', async () => { + jest.spyOn(repository, 'query').mockResolvedValueOnce([]); + expect(await service.getPrimaryCategory(1, '', '')).toEqual(null); + }); + }); + + describe('groupByCategory()', () => { + it('유저의 해당 날짜 학습 기록을 카테고리로 묶어서 반환한다.', async () => { + const result = [ + { + id: 1, + name: '카테고리1', + color_code: '#000000', + today_time: 3600, + }, + { + id: 2, + name: '카테고리2', + color_code: '#000000', + today_time: 7200, + }, + ]; + jest.spyOn(repository, 'query').mockResolvedValueOnce(result); + jest + .spyOn(repository, 'query') + .mockResolvedValueOnce([{ date: '2023-01-01', daily_sum: 11800 }]); + expect(await service.groupByCategory(1, '2023-01-01')).toEqual({ + total_time: 11800, + categories: result, + }); + }); + }); }); diff --git a/BE/src/study-logs/study-logs.service.ts b/BE/src/study-logs/study-logs.service.ts index c687cc7..755bd84 100644 --- a/BE/src/study-logs/study-logs.service.ts +++ b/BE/src/study-logs/study-logs.service.ts @@ -116,7 +116,20 @@ export class StudyLogsService { throw new BadRequestException('startDate는 endDate보다 작아야 합니다.'); } const result = Array.from({ length: diffDays }, () => 0); - const daily_sums = await this.studyLogsRepository.query( + const daily_sums = await this.getDailySum(user_id, start_date, end_date); + + daily_sums.forEach(({ date, daily_sum }) => { + result[moment(date).diff(startMoment, 'days')] = +daily_sum; + }); + return result; + } + + async getDailySum( + user_id, + start_date, + end_date, + ): Promise<{ date: string; daily_sum: string | number }[]> { + return this.studyLogsRepository.query( `SELECT DATE(study_logs.date) as date, SUM(study_logs.learning_time) as daily_sum FROM study_logs WHERE study_logs.user_id = ? @@ -125,11 +138,6 @@ export class StudyLogsService { ORDER BY DATE(study_logs.date) ASC`, [user_id, start_date, end_date], ); - - daily_sums.forEach(({ date, daily_sum }) => { - result[moment(date).diff(startMoment, 'days')] = +daily_sum; - }); - return result; } async getPrimaryCategory( @@ -152,8 +160,35 @@ export class StudyLogsService { ? '기타' : primary_category[0]?.name ?? null; } + async groupByCategory(user_id: number, date: string): Promise { - const studyLogsByCategory = await this.studyLogsRepository.query( + const studyLogsByCategory = await this.getTodayTotalTimeByCategory( + user_id, + date, + ); + + const categories = studyLogsByCategory.map((studyLog) => ({ + id: studyLog.id, + name: studyLog.name, + color_code: studyLog.color_code, + today_time: parseInt(studyLog.today_time), + })); + + const result = { + total_time: (await this.calculateTotalTimes(user_id, date, date))[0] ?? 0, + categories, + }; + + return result; + } + + async getTodayTotalTimeByCategory( + user_id: number, + date: string, + ): Promise< + { id: string; name: string; color_code: string; today_time: string }[] + > { + return this.studyLogsRepository.query( `SELECT c.id, c.name, @@ -170,20 +205,6 @@ export class StudyLogsService { `, [date, user_id], ); - - const categories = studyLogsByCategory.map((studyLog) => ({ - id: studyLog.id, - name: studyLog.name, - color_code: studyLog.color_code, - today_time: parseInt(studyLog.today_time), - })); - - const result = { - total_time: (await this.calculateTotalTimes(user_id, date, date))[0] ?? 0, - categories, - }; - - return result; } async deleteRowsByUserId(id: number): Promise { @@ -195,7 +216,20 @@ export class StudyLogsService { startDate: string, endDate: string, ): Promise { - const result = await this.studyLogsRepository.query( + const result = await this.getTotalTimeByDateRange(startDate, endDate); + const rank = result.findIndex((user) => user.user_id === userId) + 1; + if (!rank) { + return 100; + } + const userCount = await this.usersRepository.count(); + return (rank / userCount) * 100; + } + + async getTotalTimeByDateRange( + startDate: string, + endDate: string, + ): Promise<{ user_id: number }[]> { + return this.studyLogsRepository.query( ` SELECT user_id, SUM(learning_time) AS total_time FROM study_logs @@ -205,12 +239,6 @@ export class StudyLogsService { `, [startDate, endDate], ); - const rank = result.findIndex((user) => user.user_id === userId) + 1; - if (!rank) { - return 100; - } - const userCount = await this.usersRepository.count(); - return (rank / userCount) * 100; } entityToDto(studyLog: StudyLogs): StudyLogsDto { diff --git a/BE/src/users/users.controller.spec.ts b/BE/src/users/users.controller.spec.ts deleted file mode 100644 index 3e27c39..0000000 --- a/BE/src/users/users.controller.spec.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { UsersController } from './users.controller'; - -describe('UsersController', () => { - let controller: UsersController; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - controllers: [UsersController], - }).compile(); - - controller = module.get(UsersController); - }); - - it('should be defined', () => { - expect(controller).toBeDefined(); - }); -}); diff --git a/BE/src/users/users.service.spec.ts b/BE/src/users/users.service.spec.ts index d415727..cc7f5cf 100644 --- a/BE/src/users/users.service.spec.ts +++ b/BE/src/users/users.service.spec.ts @@ -8,11 +8,14 @@ import { MockUsersRepository } from '../../test/mock-repo/mock-user-repo'; import { UsersModel } from './entity/users.entity'; import path from 'path'; import { BadRequestException } from '@nestjs/common'; +import { AuthTypeEnum } from './const/auth-type.const'; +import { Repository } from 'typeorm'; class MockS3Service {} describe('UsersService', () => { let service: UsersService; + let repository: Repository; beforeEach(async () => { const module: TestingModule = await Test.createTestingModule({ @@ -28,6 +31,9 @@ describe('UsersService', () => { }).compile(); service = module.get(UsersService); + repository = module.get>( + getRepositoryToken(UsersModel), + ); }); it('should be defined', () => { @@ -39,11 +45,13 @@ describe('UsersService', () => { const user = { nickname: 'test', email: 'test@test.com', + auth_type: AuthTypeEnum.GOOGLE, } as UsersModel; const result = await service.createUser(user); expect(result).toStrictEqual({ id: 4, nickname: user.nickname, + auth_type: AuthTypeEnum.GOOGLE, email: user.email, image_url: null, }); diff --git a/BE/test/mock-service/mock-redis-service.ts b/BE/test/mock-service/mock-redis-service.ts index f9447bb..7d2309f 100644 --- a/BE/test/mock-service/mock-redis-service.ts +++ b/BE/test/mock-service/mock-redis-service.ts @@ -1,14 +1,14 @@ export class MockRedisService { - private redis: Map = new Map(); - constructor() { - this.redis.set('2', '2023-11-29 16:00:00'); - } - set(key: string, value: string) { - this.redis.set(key, value); + private redis: Map = new Map(); + constructor() {} + hset(key: string, field: string, value: string) { + const data = {}; + data[field] = value; + this.redis.set(key, data); } - get(key: string): Promise { - return Promise.resolve(this.redis.get(key)); + hget(key: string, field: string): Promise { + return Promise.resolve(this.redis.get(key)[field]); } async del(key: string): Promise { diff --git a/BE/test/mock-service/mock-study-logs-service.ts b/BE/test/mock-service/mock-study-logs-service.ts index 5fd8374..bf08120 100644 --- a/BE/test/mock-service/mock-study-logs-service.ts +++ b/BE/test/mock-service/mock-study-logs-service.ts @@ -22,4 +22,6 @@ export class MockStudyLogsService { }, result); return daily_sums; } + + getPrimaryCategory(id, start_date, end_date) {} } diff --git a/BE/test/mock-table/users.json b/BE/test/mock-table/users.json index 1e6c71d..969f7a0 100644 --- a/BE/test/mock-table/users.json +++ b/BE/test/mock-table/users.json @@ -4,7 +4,7 @@ "nickname": "어린콩", "auth_type": "google", "email": "yeim.dev@gmail.com", - "image_url": null + "image_url": "image.png" }, { "id": 2,