Merged PR 164: ユニットテスト実装(タスク一覧取得 | typist)
## 概要 [Task1965: ユニットテスト実装(タスク一覧取得 | typist)](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/1965) - Typistによるタスク一覧取得のユニットテスト部分を実装 ## レビューポイント - 現状、ユニットテストとして問題ないか - レビュー対象外の部分は対象外で問題ないか ## レビュー対象外 - ライセンス周辺のテストが失敗している ## 動作確認状況 - ローカルで確認
This commit is contained in:
parent
fd69541e1a
commit
bb926f9feb
@ -18,7 +18,7 @@ describe('TasksService', () => {
|
||||
const accessToken = { userId: 'userId', role: 'admin', tier: 5 };
|
||||
const offset = 0;
|
||||
const limit = 20;
|
||||
const status = ['Uploaded,Backup'];
|
||||
const status = ['Uploaded', 'Backup'];
|
||||
const paramName = 'JOB_NUMBER';
|
||||
const direction = 'ASC';
|
||||
expect(
|
||||
@ -83,7 +83,7 @@ describe('TasksService', () => {
|
||||
const accessToken = { userId: 'userId', role: 'admin', tier: 5 };
|
||||
const offset = 0;
|
||||
const limit = 20;
|
||||
const status = ['Uploaded,Backup'];
|
||||
const status = ['Uploaded', 'Backup'];
|
||||
const paramName = 'JOB_NUMBER';
|
||||
const direction = 'ASC';
|
||||
await expect(
|
||||
@ -115,7 +115,7 @@ describe('TasksService', () => {
|
||||
const accessToken = { userId: 'userId', role: 'admin', tier: 5 };
|
||||
const offset = 0;
|
||||
const limit = 20;
|
||||
const status = ['Uploaded,Backup'];
|
||||
const status = ['Uploaded', 'Backup'];
|
||||
const paramName = 'JOB_NUMBER';
|
||||
const direction = 'ASC';
|
||||
await expect(
|
||||
@ -181,7 +181,7 @@ describe('TasksService', () => {
|
||||
const accessToken = { userId: 'userId', role: 'admin', tier: 5 };
|
||||
const offset = 0;
|
||||
const limit = 20;
|
||||
const status = ['Uploaded,Backup'];
|
||||
const status = ['Uploaded', 'Backup'];
|
||||
const paramName = 'JOB_NUMBER';
|
||||
const direction = 'ASC';
|
||||
await expect(
|
||||
@ -217,7 +217,7 @@ describe('TasksService', () => {
|
||||
const accessToken = { userId: 'userId', role: 'author', tier: 5 };
|
||||
const offset = 0;
|
||||
const limit = 20;
|
||||
const status = ['Uploaded,Backup'];
|
||||
const status = ['Uploaded', 'Backup'];
|
||||
const paramName = 'JOB_NUMBER';
|
||||
const direction = 'ASC';
|
||||
const result = await service.tasksService.getTasks(
|
||||
@ -270,7 +270,8 @@ describe('TasksService', () => {
|
||||
expect(
|
||||
service.taskRepoService.getTasksFromAuthorIdAndAccountId,
|
||||
).toHaveBeenCalledWith('abcdef', 1, 0, 20, 'JOB_NUMBER', 'ASC', [
|
||||
'Uploaded,Backup',
|
||||
'Uploaded',
|
||||
'Backup',
|
||||
]);
|
||||
});
|
||||
|
||||
@ -288,7 +289,115 @@ describe('TasksService', () => {
|
||||
const accessToken = { userId: 'userId', role: 'author', tier: 5 };
|
||||
const offset = 0;
|
||||
const limit = 20;
|
||||
const status = ['Uploaded,Backup'];
|
||||
const status = ['Uploaded', 'Backup'];
|
||||
const paramName = 'JOB_NUMBER';
|
||||
const direction = 'ASC';
|
||||
await expect(
|
||||
service.tasksService.getTasks(
|
||||
accessToken,
|
||||
offset,
|
||||
limit,
|
||||
status,
|
||||
paramName,
|
||||
direction,
|
||||
),
|
||||
).rejects.toEqual(
|
||||
new HttpException(
|
||||
makeErrorResponse('E000101'),
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
it('タスク一覧を取得できる(typist)', async () => {
|
||||
const tasksRepositoryMockValue = makeDefaultTasksRepositoryMockValue();
|
||||
const usersRepositoryMockValue = makeDefaultUsersRepositoryMockValue();
|
||||
if (usersRepositoryMockValue.findUserByExternalId instanceof Error) {
|
||||
return;
|
||||
}
|
||||
usersRepositoryMockValue.findUserByExternalId.role = 'typist';
|
||||
|
||||
const service = await makeTasksServiceMock(
|
||||
tasksRepositoryMockValue,
|
||||
usersRepositoryMockValue,
|
||||
);
|
||||
|
||||
const accessToken = { userId: 'userId', role: 'typist', tier: 5 };
|
||||
const offset = 0;
|
||||
const limit = 20;
|
||||
const status = ['Uploaded', 'Backup'];
|
||||
const paramName = 'JOB_NUMBER';
|
||||
const direction = 'ASC';
|
||||
const result = await service.tasksService.getTasks(
|
||||
accessToken,
|
||||
offset,
|
||||
limit,
|
||||
status,
|
||||
paramName,
|
||||
direction,
|
||||
);
|
||||
expect(result).toEqual({
|
||||
tasks: [
|
||||
{
|
||||
assignees: [{ typistName: 'USER_userId', typistUserId: 1 }],
|
||||
audioCreatedDate: '2023-01-01T01:01:01.000Z',
|
||||
audioDuration: '123000',
|
||||
audioFileId: 1,
|
||||
audioFinishedDate: '2023-01-01T01:01:01.000Z',
|
||||
audioFormat: 'DS',
|
||||
audioUploadedDate: '2023-01-01T01:01:01.000Z',
|
||||
authorId: 'AUTHOR',
|
||||
comment: 'comment',
|
||||
fileName: 'test.zip',
|
||||
fileSize: 123000,
|
||||
isEncrypted: true,
|
||||
jobNumber: '00000001',
|
||||
optionItemList: [
|
||||
{ optionItemLabel: 'label01', optionItemValue: 'value01' },
|
||||
{ optionItemLabel: 'label02', optionItemValue: 'value02' },
|
||||
{ optionItemLabel: 'label03', optionItemValue: 'value03' },
|
||||
{ optionItemLabel: 'label04', optionItemValue: 'value04' },
|
||||
{ optionItemLabel: 'label05', optionItemValue: 'value05' },
|
||||
{ optionItemLabel: 'label06', optionItemValue: 'value06' },
|
||||
{ optionItemLabel: 'label07', optionItemValue: 'value07' },
|
||||
{ optionItemLabel: 'label08', optionItemValue: 'value08' },
|
||||
{ optionItemLabel: 'label09', optionItemValue: 'value09' },
|
||||
{ optionItemLabel: 'label10', optionItemValue: 'value10' },
|
||||
],
|
||||
priority: '00',
|
||||
status: 'Uploaded',
|
||||
transcriptionFinishedDate: undefined,
|
||||
transcriptionStartedDate: undefined,
|
||||
typist: undefined,
|
||||
url: 'test/test.zip',
|
||||
workType: 'WorkType',
|
||||
},
|
||||
],
|
||||
total: 1,
|
||||
});
|
||||
expect(
|
||||
service.taskRepoService.getTasksFromTypistRelations,
|
||||
).toHaveBeenCalledWith('userId', 0, 20, 'JOB_NUMBER', 'ASC', [
|
||||
'Uploaded',
|
||||
'Backup',
|
||||
]);
|
||||
});
|
||||
|
||||
it('タスク一覧の取得に失敗した場合、エラーを返却する(typist)', async () => {
|
||||
const tasksRepositoryMockValue = makeDefaultTasksRepositoryMockValue();
|
||||
const usersRepositoryMockValue = makeDefaultUsersRepositoryMockValue();
|
||||
tasksRepositoryMockValue.getTasksFromTypistRelations = new Error(
|
||||
'DB failed',
|
||||
);
|
||||
const service = await makeTasksServiceMock(
|
||||
tasksRepositoryMockValue,
|
||||
usersRepositoryMockValue,
|
||||
);
|
||||
|
||||
const accessToken = { userId: 'userId', role: 'typist', tier: 5 };
|
||||
const offset = 0;
|
||||
const limit = 20;
|
||||
const status = ['Uploaded', 'Backup'];
|
||||
const paramName = 'JOB_NUMBER';
|
||||
const direction = 'ASC';
|
||||
await expect(
|
||||
@ -319,7 +428,7 @@ describe('TasksService', () => {
|
||||
const accessToken = { userId: 'userId', role: 'XXX', tier: 5 };
|
||||
const offset = 0;
|
||||
const limit = 20;
|
||||
const status = ['Uploaded,Backup'];
|
||||
const status = ['Uploaded', 'Backup'];
|
||||
const paramName = 'JOB_NUMBER';
|
||||
const direction = 'ASC';
|
||||
await expect(
|
||||
|
||||
@ -40,9 +40,6 @@ export class TasksService {
|
||||
await this.usersRepository.findUserByExternalId(userId);
|
||||
|
||||
if (roles.includes(ADMIN_ROLES.ADMIN)) {
|
||||
const { account_id } = await this.usersRepository.findUserByExternalId(
|
||||
userId,
|
||||
);
|
||||
const result = await this.taskRepository.getTasksFromAccountId(
|
||||
account_id,
|
||||
offset,
|
||||
|
||||
@ -25,6 +25,13 @@ export type TasksRepositoryMockValue = {
|
||||
count: number;
|
||||
}
|
||||
| Error;
|
||||
getTasksFromTypistRelations:
|
||||
| {
|
||||
tasks: Task[];
|
||||
permissions: CheckoutPermission[];
|
||||
count: number;
|
||||
}
|
||||
| Error;
|
||||
};
|
||||
|
||||
export type UsersRepositoryMockValue = {
|
||||
@ -58,7 +65,11 @@ export const makeTasksServiceMock = async (
|
||||
};
|
||||
|
||||
export const makeTasksRepositoryMock = (value: TasksRepositoryMockValue) => {
|
||||
const { getTasksFromAccountId, getTasksFromAuthorIdAndAccountId } = value;
|
||||
const {
|
||||
getTasksFromAccountId,
|
||||
getTasksFromAuthorIdAndAccountId,
|
||||
getTasksFromTypistRelations,
|
||||
} = value;
|
||||
return {
|
||||
getTasksFromAccountId:
|
||||
getTasksFromAccountId instanceof Error
|
||||
@ -99,6 +110,32 @@ export const makeTasksRepositoryMock = (value: TasksRepositoryMockValue) => {
|
||||
[]
|
||||
>()
|
||||
.mockResolvedValue(getTasksFromAuthorIdAndAccountId),
|
||||
getTasksFromTypistRelations:
|
||||
getTasksFromTypistRelations instanceof Error
|
||||
? jest
|
||||
.fn<
|
||||
Promise<void>,
|
||||
[
|
||||
string,
|
||||
number,
|
||||
number,
|
||||
number,
|
||||
TaskListSortableAttribute,
|
||||
SortDirection,
|
||||
string[],
|
||||
]
|
||||
>()
|
||||
.mockRejectedValue(getTasksFromTypistRelations)
|
||||
: jest
|
||||
.fn<
|
||||
Promise<{
|
||||
tasks: Task[];
|
||||
permissions: CheckoutPermission[];
|
||||
count: number;
|
||||
}>,
|
||||
[]
|
||||
>()
|
||||
.mockResolvedValue(getTasksFromTypistRelations),
|
||||
};
|
||||
};
|
||||
|
||||
@ -118,6 +155,7 @@ export const makeDefaultTasksRepositoryMockValue =
|
||||
return {
|
||||
getTasksFromAccountId: defaultTasksRepositoryMockValue,
|
||||
getTasksFromAuthorIdAndAccountId: defaultTasksRepositoryMockValue,
|
||||
getTasksFromTypistRelations: defaultTasksRepositoryMockValue,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user