Merged PR 908: API修正(タスク削除条件のステータスチェックを修正)
## 概要 [Task4201: API修正(タスク削除条件のステータスチェックを修正)](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/4201) - タスク削除不可条件を修正 - Pendingの時も削除できないようにする ## レビューポイント - 修正の認識があっているか ## 動作確認状況 - ローカルで確認 - 行った修正がデグレを発生させていないことを確認できるか - タスクの各ステータスで削除可否を確かめられるように修正 ## 補足 - 相談、参考資料などがあれば
This commit is contained in:
parent
b7925f311b
commit
37666a00c7
@ -4336,7 +4336,7 @@ describe('deleteTask', () => {
|
||||
source = null;
|
||||
});
|
||||
|
||||
it('管理者として、アカウント内のタスクを削除できる', async () => {
|
||||
it('管理者として、アカウント内のタスクを削除できる(タスクのStatusがUploaded)', async () => {
|
||||
if (!source) fail();
|
||||
const module = await makeTestingModule(source);
|
||||
if (!module) fail();
|
||||
@ -4420,7 +4420,7 @@ describe('deleteTask', () => {
|
||||
);
|
||||
}
|
||||
});
|
||||
it('Authorとして、自身が追加したタスクを削除できる', async () => {
|
||||
it('Authorとして、自身が追加したタスクを削除できる(タスクのStatusがFinished)', async () => {
|
||||
if (!source) fail();
|
||||
const module = await makeTestingModule(source);
|
||||
if (!module) fail();
|
||||
@ -4448,7 +4448,7 @@ describe('deleteTask', () => {
|
||||
'',
|
||||
'01',
|
||||
'00000001',
|
||||
TASK_STATUS.UPLOADED,
|
||||
TASK_STATUS.FINISHED,
|
||||
);
|
||||
await createCheckoutPermissions(source, taskId, typistUserId);
|
||||
|
||||
@ -4460,7 +4460,92 @@ describe('deleteTask', () => {
|
||||
const optionItems = await getAudioOptionItems(source, taskId);
|
||||
|
||||
expect(task?.id).toBe(taskId);
|
||||
expect(task?.status).toBe(TASK_STATUS.UPLOADED);
|
||||
expect(task?.status).toBe(TASK_STATUS.FINISHED);
|
||||
expect(task?.audio_file_id).toBe(audioFileId);
|
||||
|
||||
expect(audioFile?.id).toBe(audioFileId);
|
||||
expect(audioFile?.file_name).toBe('x.zip');
|
||||
expect(audioFile?.author_id).toBe(authorId);
|
||||
|
||||
expect(checkoutPermissions.length).toBe(1);
|
||||
expect(checkoutPermissions[0].user_id).toBe(typistUserId);
|
||||
|
||||
expect(optionItems.length).toBe(10);
|
||||
}
|
||||
|
||||
const service = module.get<TasksService>(TasksService);
|
||||
const blobStorageService =
|
||||
module.get<BlobstorageService>(BlobstorageService);
|
||||
const context = makeContext(authorExternalId, 'requestId');
|
||||
|
||||
overrideBlobstorageService(service, {
|
||||
deleteFile: jest.fn(),
|
||||
});
|
||||
|
||||
await service.deleteTask(context, authorExternalId, audioFileId);
|
||||
|
||||
// 実行結果が正しいか確認
|
||||
{
|
||||
const task = await getTask(source, taskId);
|
||||
const audioFile = await getAudioFile(source, audioFileId);
|
||||
const checkoutPermissions = await getCheckoutPermissions(source, taskId);
|
||||
const optionItems = await getAudioOptionItems(source, taskId);
|
||||
|
||||
expect(task).toBe(null);
|
||||
expect(audioFile).toBe(null);
|
||||
expect(checkoutPermissions.length).toBe(0);
|
||||
expect(optionItems.length).toBe(0);
|
||||
|
||||
// Blob削除メソッドが呼ばれているか確認
|
||||
expect(blobStorageService.deleteFile).toBeCalledWith(
|
||||
context,
|
||||
account.id,
|
||||
account.country,
|
||||
'y.zip',
|
||||
);
|
||||
}
|
||||
});
|
||||
it('Authorとして、自身が追加したタスクを削除できる(タスクのStatusがBackup)', async () => {
|
||||
if (!source) fail();
|
||||
const module = await makeTestingModule(source);
|
||||
if (!module) fail();
|
||||
// 第五階層のアカウント作成
|
||||
const { account } = await makeTestAccount(source, { tier: 5 });
|
||||
const authorId = 'AUTHOR_ID';
|
||||
const { id: authorUserId, external_id: authorExternalId } =
|
||||
await makeTestUser(source, {
|
||||
account_id: account.id,
|
||||
author_id: 'AUTHOR_ID',
|
||||
external_id: 'author-user-external-id',
|
||||
role: USER_ROLES.AUTHOR,
|
||||
});
|
||||
const { id: typistUserId } = await makeTestUser(source, {
|
||||
account_id: account.id,
|
||||
external_id: 'typist-user-external-id',
|
||||
role: USER_ROLES.TYPIST,
|
||||
});
|
||||
|
||||
const { taskId, audioFileId } = await createTask(
|
||||
source,
|
||||
account.id,
|
||||
authorUserId,
|
||||
authorId,
|
||||
'',
|
||||
'01',
|
||||
'00000001',
|
||||
TASK_STATUS.BACKUP,
|
||||
);
|
||||
await createCheckoutPermissions(source, taskId, typistUserId);
|
||||
|
||||
// 作成したデータを確認
|
||||
{
|
||||
const task = await getTask(source, taskId);
|
||||
const audioFile = await getAudioFile(source, audioFileId);
|
||||
const checkoutPermissions = await getCheckoutPermissions(source, taskId);
|
||||
const optionItems = await getAudioOptionItems(source, taskId);
|
||||
|
||||
expect(task?.id).toBe(taskId);
|
||||
expect(task?.status).toBe(TASK_STATUS.BACKUP);
|
||||
expect(task?.audio_file_id).toBe(audioFileId);
|
||||
|
||||
expect(audioFile?.id).toBe(audioFileId);
|
||||
@ -4578,6 +4663,79 @@ describe('deleteTask', () => {
|
||||
}
|
||||
}
|
||||
});
|
||||
it('ステータスがPendingのタスクを削除しようとした場合、エラーとなること', async () => {
|
||||
if (!source) fail();
|
||||
const module = await makeTestingModule(source);
|
||||
if (!module) fail();
|
||||
// 第五階層のアカウント作成
|
||||
const { account } = await makeTestAccount(source, { tier: 5 });
|
||||
const authorId = 'AUTHOR_ID';
|
||||
const { id: authorUserId, external_id: authorExternalId } =
|
||||
await makeTestUser(source, {
|
||||
account_id: account.id,
|
||||
author_id: 'AUTHOR_ID',
|
||||
external_id: 'author-user-external-id',
|
||||
role: USER_ROLES.AUTHOR,
|
||||
});
|
||||
const { id: typistUserId } = await makeTestUser(source, {
|
||||
account_id: account.id,
|
||||
external_id: 'typist-user-external-id',
|
||||
role: USER_ROLES.TYPIST,
|
||||
});
|
||||
|
||||
const { taskId, audioFileId } = await createTask(
|
||||
source,
|
||||
account.id,
|
||||
authorUserId,
|
||||
authorId,
|
||||
'',
|
||||
'01',
|
||||
'00000001',
|
||||
TASK_STATUS.PENDING,
|
||||
);
|
||||
await createCheckoutPermissions(source, taskId, typistUserId);
|
||||
|
||||
// 作成したデータを確認
|
||||
{
|
||||
const task = await getTask(source, taskId);
|
||||
const audioFile = await getAudioFile(source, audioFileId);
|
||||
const checkoutPermissions = await getCheckoutPermissions(source, taskId);
|
||||
const optionItems = await getAudioOptionItems(source, taskId);
|
||||
|
||||
expect(task?.id).toBe(taskId);
|
||||
expect(task?.status).toBe(TASK_STATUS.PENDING);
|
||||
expect(task?.audio_file_id).toBe(audioFileId);
|
||||
|
||||
expect(audioFile?.id).toBe(audioFileId);
|
||||
expect(audioFile?.file_name).toBe('x.zip');
|
||||
expect(audioFile?.author_id).toBe(authorId);
|
||||
|
||||
expect(checkoutPermissions.length).toBe(1);
|
||||
expect(checkoutPermissions[0].user_id).toBe(typistUserId);
|
||||
|
||||
expect(optionItems.length).toBe(10);
|
||||
}
|
||||
|
||||
const service = module.get<TasksService>(TasksService);
|
||||
const context = makeContext(authorExternalId, 'requestId');
|
||||
|
||||
overrideBlobstorageService(service, {
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
deleteFile: async () => {},
|
||||
});
|
||||
|
||||
try {
|
||||
await service.deleteTask(context, authorExternalId, audioFileId);
|
||||
fail();
|
||||
} catch (e) {
|
||||
if (e instanceof HttpException) {
|
||||
expect(e.getStatus()).toEqual(HttpStatus.BAD_REQUEST);
|
||||
expect(e.getResponse()).toEqual(makeErrorResponse('E010601'));
|
||||
} else {
|
||||
fail();
|
||||
}
|
||||
}
|
||||
});
|
||||
it('Authorが自身が作成したタスク以外を削除しようとした場合、エラーとなること', async () => {
|
||||
if (!source) fail();
|
||||
const module = await makeTestingModule(source);
|
||||
|
||||
@ -1436,13 +1436,15 @@ export class TasksRepositoryService {
|
||||
}
|
||||
}
|
||||
|
||||
// タスクのステータスがInProgressの場合はエラー
|
||||
if (task.status === TASK_STATUS.IN_PROGRESS) {
|
||||
// タスクのステータスがInProgress・Pendingの時はエラー
|
||||
if (
|
||||
task.status === TASK_STATUS.IN_PROGRESS ||
|
||||
task.status === TASK_STATUS.PENDING
|
||||
) {
|
||||
throw new StatusNotMatchError(
|
||||
`task status is InProgress. audio_file_id:${audioFileId}`,
|
||||
`task status is InProgress or Pending. status:${task.status} , audio_file_id:${audioFileId}`,
|
||||
);
|
||||
}
|
||||
|
||||
// タスクに紐づくオプションアイテムを削除
|
||||
const optionItemRepo = entityManager.getRepository(AudioOptionItem);
|
||||
await deleteEntity(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user