Merged PR 899: 階層構造変更API修正
## 概要 [Task4179: 階層構造変更API修正](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/4179) - 階層構造変更API修正 - 第四⇔第五の切り替え処理の時は国・リージョンの一致を確認しない - 不要なエラーコード・エラーハンドリングを削除 - テスト修正 ## レビューポイント - 修正箇所の認識は合っているか - テストケースは足りているか ## 動作確認状況 - ローカルで確認 - 国の違うDealerに付け替える処理を行い成功した - 行った修正がデグレを発生させていないことを確認できるか - 具体的にどのような確認をしたか - 国の違う第四⇔第五間の付け替えのテストが成功することを確認 - ほかのテストが成功することを確認 ## 補足 - 相談、参考資料などがあれば
This commit is contained in:
parent
4dac420bed
commit
5860da285e
@ -80,7 +80,6 @@ export const errorCodes = [
|
||||
"E017001", // 親アカウント変更不可エラー(指定したアカウントが存在しない)
|
||||
"E017002", // 親アカウント変更不可エラー(階層関係が不正)
|
||||
"E017003", // 親アカウント変更不可エラー(リージョンが同一でない)
|
||||
"E017004", // 親アカウント変更不可エラー(国が同一でない)
|
||||
"E018001", // パートナーアカウント削除エラー(削除条件を満たしていない)
|
||||
"E019001", // パートナーアカウント取得不可エラー(階層構造が不正)
|
||||
"E020001", // パートナーアカウント変更エラー(変更条件を満たしていない)
|
||||
|
||||
@ -174,12 +174,6 @@ export const switchParentAsync = createAsyncThunk<
|
||||
);
|
||||
}
|
||||
|
||||
if (error.code === "E017004") {
|
||||
errorMessage = getTranslationID(
|
||||
"changeOwnerPopup.message.countryMismatchError"
|
||||
);
|
||||
}
|
||||
|
||||
thunkApi.dispatch(
|
||||
openSnackbar({
|
||||
level: "error",
|
||||
|
||||
@ -85,7 +85,6 @@ export const ErrorCodes = [
|
||||
'E017001', // 親アカウント変更不可エラー(指定したアカウントが存在しない)
|
||||
'E017002', // 親アカウント変更不可エラー(階層関係が不正)
|
||||
'E017003', // 親アカウント変更不可エラー(リージョンが同一でない)
|
||||
'E017004', // 親アカウント変更不可エラー(国が同一でない)
|
||||
'E018001', // パートナーアカウント削除エラー(削除条件を満たしていない)
|
||||
'E019001', // パートナーアカウント取得不可エラー(階層構造が不正)
|
||||
'E020001', // パートナーアカウント変更エラー(変更条件を満たしていない)
|
||||
|
||||
@ -75,7 +75,6 @@ export const errors: Errors = {
|
||||
E017001: 'Parent account switch failed Error: account not found',
|
||||
E017002: 'Parent account switch failed Error: hierarchy mismatch',
|
||||
E017003: 'Parent account switch failed Error: region mismatch',
|
||||
E017004: 'Parent account switch failed Error: country mismatch',
|
||||
E018001: 'Partner account delete failed Error: not satisfied conditions',
|
||||
E019001: 'Partner account get failed Error: hierarchy mismatch',
|
||||
E020001: 'Partner account change failed Error: not satisfied conditions',
|
||||
|
||||
@ -8220,6 +8220,65 @@ describe('switchParent', () => {
|
||||
expect(child2LicenseOrderStatuses).toBeTruthy();
|
||||
});
|
||||
|
||||
it('第四<->第五の切り替えで、親子で国が異なる場合でも階層構造変更処理ができる', async () => {
|
||||
if (!source) fail();
|
||||
const module = await makeTestingModule(source);
|
||||
if (!module) fail();
|
||||
// 新規親アカウントのアカウントを作成する
|
||||
const { account: newParent } = await makeTestAccount(source, {
|
||||
tier: 4,
|
||||
country: `AU`,
|
||||
});
|
||||
|
||||
// 子アカウントを作成する
|
||||
const { account: child1 } = await makeTestAccount(source, {
|
||||
tier: 5,
|
||||
country: `NZ`,
|
||||
parent_account_id: undefined,
|
||||
delegation_permission: true,
|
||||
});
|
||||
|
||||
const { account: child2 } = await makeTestAccount(source, {
|
||||
tier: 5,
|
||||
country: `GB`,
|
||||
parent_account_id: undefined,
|
||||
delegation_permission: true,
|
||||
});
|
||||
|
||||
// ライセンス注文作成
|
||||
await createLicenseOrder(source, child1.id, 10, 1); // 注文先アカウントは何でもいいため適当
|
||||
await createLicenseOrder(source, child1.id, 10, 1); // 親アカウントは何でもいいため適当
|
||||
await createLicenseOrder(source, child2.id, 10, 1); // 親アカウントは何でもいいため適当
|
||||
|
||||
// テスト実行
|
||||
const context = makeContext(`external_id`, 'requestId');
|
||||
const service = module.get<AccountsService>(AccountsService);
|
||||
await service.switchParent(context, newParent.id, [child1.id, child2.id]);
|
||||
|
||||
const child1Result = await getAccount(source, child1.id);
|
||||
const child2Result = await getAccount(source, child2.id);
|
||||
const child1LicenseOrderResult = await getLicenseOrders(source, child1.id);
|
||||
const child2LicenseOrderResult = await getLicenseOrders(source, child2.id);
|
||||
|
||||
// アカウントテーブルの更新確認
|
||||
expect(child1Result?.parent_account_id).toBe(newParent.id);
|
||||
expect(child1Result?.delegation_permission).toBe(false);
|
||||
expect(child2Result?.parent_account_id).toBe(newParent.id);
|
||||
expect(child2Result?.delegation_permission).toBe(false);
|
||||
|
||||
// ライセンス注文が全てcancelされていることの確認
|
||||
expect(child1LicenseOrderResult.length).toBe(2);
|
||||
const child1LicenseOrderStatuses = child1LicenseOrderResult.every(
|
||||
(x) => x.status === LICENSE_ISSUE_STATUS.CANCELED,
|
||||
);
|
||||
expect(child1LicenseOrderStatuses).toBeTruthy();
|
||||
expect(child2LicenseOrderResult.length).toBe(1);
|
||||
const child2LicenseOrderStatuses = child2LicenseOrderResult.every(
|
||||
(x) => x.status === LICENSE_ISSUE_STATUS.CANCELED,
|
||||
);
|
||||
expect(child2LicenseOrderStatuses).toBeTruthy();
|
||||
});
|
||||
|
||||
it('切り替え先親アカウントが存在しない場合は400エラー(親アカウント不在エラー)を返す', async () => {
|
||||
if (!source) fail();
|
||||
const module = await makeTestingModule(source);
|
||||
@ -8403,50 +8462,6 @@ describe('switchParent', () => {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it('第四<->第五の切り替えで、親子で国が異なる場合は400エラー(国関係不一致エラー)を返す', async () => {
|
||||
if (!source) fail();
|
||||
const module = await makeTestingModule(source);
|
||||
if (!module) fail();
|
||||
|
||||
const accountsRepositoryService = module.get<AccountsRepositoryService>(
|
||||
AccountsRepositoryService,
|
||||
);
|
||||
const child1 = new Account();
|
||||
child1.id = 1;
|
||||
child1.tier = 5;
|
||||
child1.country = 'AU';
|
||||
|
||||
const child2 = new Account();
|
||||
child2.id = 2;
|
||||
child2.tier = 5;
|
||||
child2.country = 'NZ'; // このアカウントだけ国が異なるようにしておく
|
||||
|
||||
accountsRepositoryService.findAccountsById = jest
|
||||
.fn()
|
||||
.mockResolvedValue([child1, child2]);
|
||||
|
||||
const context = makeContext('external_id', 'requestId');
|
||||
const service = module.get<AccountsService>(AccountsService);
|
||||
|
||||
const parent = new Account();
|
||||
parent.id = 10;
|
||||
parent.tier = 4;
|
||||
parent.country = 'AU';
|
||||
try {
|
||||
accountsRepositoryService.findAccountById = jest
|
||||
.fn()
|
||||
.mockResolvedValue(parent);
|
||||
await service.switchParent(context, parent.id, [child1.id, child2.id]);
|
||||
} catch (e) {
|
||||
if (e instanceof HttpException) {
|
||||
expect(e.getStatus()).toEqual(HttpStatus.BAD_REQUEST);
|
||||
expect(e.getResponse()).toEqual(makeErrorResponse('E017004'));
|
||||
} else {
|
||||
fail();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('deletePartnerAccount', () => {
|
||||
|
||||
@ -51,7 +51,6 @@ import { LicensesRepositoryService } from '../../repositories/licenses/licenses.
|
||||
import {
|
||||
AccountNotFoundError,
|
||||
AdminUserNotFoundError,
|
||||
CountryMismatchError,
|
||||
DealerAccountNotFoundError,
|
||||
HierarchyMismatchError,
|
||||
RegionMismatchError,
|
||||
@ -2769,11 +2768,6 @@ export class AccountsService {
|
||||
makeErrorResponse('E017003'),
|
||||
HttpStatus.BAD_REQUEST,
|
||||
);
|
||||
case CountryMismatchError:
|
||||
throw new HttpException(
|
||||
makeErrorResponse('E017004'),
|
||||
HttpStatus.BAD_REQUEST,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2825,9 +2819,10 @@ export class AccountsService {
|
||||
children: Account[],
|
||||
): {
|
||||
success: boolean;
|
||||
errorType: null | RegionMismatchError | CountryMismatchError;
|
||||
errorType: null | RegionMismatchError;
|
||||
} {
|
||||
// 第三<->第四の切り替えはリージョンの一致を確認し、第四<->第五の切り替えは国の一致を確認する。
|
||||
// 「プロダクト バックログ項目 4171: 階層構造切り替えのリージョンの制約を修正する」の対応で第五階層の親(第四階層)を切り替えるときはリージョン・国の制約をなくす。 2024年5月16日
|
||||
// 第三<->第四の切り替えはリージョンの一致を確認する。
|
||||
if (parent.tier === TIERS.TIER3) {
|
||||
if (
|
||||
!children.every(
|
||||
@ -2843,13 +2838,7 @@ export class AccountsService {
|
||||
|
||||
return { success: true, errorType: null };
|
||||
} else if (parent.tier === TIERS.TIER4) {
|
||||
if (!children.every((child) => child.country === parent.country)) {
|
||||
return {
|
||||
success: false,
|
||||
errorType: new CountryMismatchError('Invalid country relation'),
|
||||
};
|
||||
}
|
||||
|
||||
// 第四<->第五の切り替えは国・リージョンの一致を確認しない。
|
||||
return { success: true, errorType: null };
|
||||
} else {
|
||||
// 親アカウントの階層が想定外の場合、本関数の使い方が間違っているので例外を投げる
|
||||
|
||||
@ -52,12 +52,3 @@ export class RegionMismatchError extends Error {
|
||||
this.name = 'RegionMismatchError';
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 所属国不一致エラー
|
||||
*/
|
||||
export class CountryMismatchError extends Error {
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
this.name = 'CountryMismatchError';
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user