Merged PR 694: テスト対応

## 概要
[Task3504: テスト対応](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/3504)

- ユーザー取得APIで取得するユーザーの順序をAuthor、Typist、Noneの順になるようにしました。

## レビューポイント
- 単純なorderの指定ではうまくいかないようでしたのでDBからの取得後にソートするようにしていますが処理として適切でしょうか?

## UIの変更
- なし

## 動作確認状況
- ローカルで確認
This commit is contained in:
makabe.t 2024-01-23 00:21:17 +00:00
parent d23336a065
commit 6e931c5afb
3 changed files with 35 additions and 13 deletions

View File

@ -88,6 +88,16 @@ export const USER_ROLES = {
TYPIST: 'typist', TYPIST: 'typist',
} as const; } as const;
/**
*
* @const {string[]}
*/
export const USER_ROLE_ORDERS = [
USER_ROLES.AUTHOR,
USER_ROLES.TYPIST,
USER_ROLES.NONE,
] as string[];
/** /**
* *
* @const {string[]} * @const {string[]}

View File

@ -1,5 +1,4 @@
import { HttpException, HttpStatus } from '@nestjs/common'; import { HttpException, HttpStatus } from '@nestjs/common';
import { AccessToken } from '../../common/token';
import { makeErrorResponse } from '../../common/error/makeErrorResponse'; import { makeErrorResponse } from '../../common/error/makeErrorResponse';
import { import {
makeDefaultAdB2cMockValue, makeDefaultAdB2cMockValue,
@ -1389,6 +1388,16 @@ describe('UsersService.getUsers', () => {
if (!module) fail(); if (!module) fail();
const { id: accountId } = await makeTestSimpleAccount(source); const { id: accountId } = await makeTestSimpleAccount(source);
const { id: typistUserId } = await makeTestUser(source, {
account_id: accountId,
external_id: 'external_id2',
role: 'typist',
author_id: undefined,
auto_renew: true,
encryption: false,
encryption_password: undefined,
prompt: false,
});
const { external_id: externalId_author, id: authorUserId } = const { external_id: externalId_author, id: authorUserId } =
await makeTestUser(source, { await makeTestUser(source, {
account_id: accountId, account_id: accountId,
@ -1401,17 +1410,6 @@ describe('UsersService.getUsers', () => {
prompt: false, prompt: false,
}); });
const { id: typistUserId } = await makeTestUser(source, {
account_id: accountId,
external_id: 'external_id2',
role: 'typist',
author_id: undefined,
auto_renew: true,
encryption: false,
encryption_password: undefined,
prompt: false,
});
await createUserGroup(source, accountId, 'group1', [typistUserId]); await createUserGroup(source, accountId, 'group1', [typistUserId]);
const { id: noneUserId } = await makeTestUser(source, { const { id: noneUserId } = await makeTestUser(source, {

View File

@ -29,6 +29,7 @@ import {
TIERS, TIERS,
TRIAL_LICENSE_ISSUE_NUM, TRIAL_LICENSE_ISSUE_NUM,
USER_ROLES, USER_ROLES,
USER_ROLE_ORDERS,
} from '../../constants'; } from '../../constants';
import { License } from '../licenses/entity/license.entity'; import { License } from '../licenses/entity/license.entity';
import { NewTrialLicenseExpirationDate } from '../../features/licenses/types/types'; import { NewTrialLicenseExpirationDate } from '../../features/licenses/types/types';
@ -496,10 +497,23 @@ export class UsersRepositoryService {
license: true, license: true,
}, },
where: { account_id: accountId }, where: { account_id: accountId },
comment: `${context.getTrackingId()}_${new Date().toUTCString()}`, comment: `${context.getTrackingId()}_${new Date().toUTCString()}`,
}); });
return dbUsers; // RoleのAuthor、Typist、Noneの順に並び替える
const roleSortedUsers = dbUsers.sort((a, b) => {
// Roleが同じ場合はIDの昇順で並び替える
if (a.role === b.role) {
return a.id - b.id;
}
return (
USER_ROLE_ORDERS.indexOf(a.role) - USER_ROLE_ORDERS.indexOf(b.role)
);
});
return roleSortedUsers;
}); });
} }