From 5860da285eb073faa32531444dd50313de937a51 Mon Sep 17 00:00:00 2001 From: "saito.k" Date: Fri, 17 May 2024 06:49:26 +0000 Subject: [PATCH] =?UTF-8?q?Merged=20PR=20899:=20=E9=9A=8E=E5=B1=A4?= =?UTF-8?q?=E6=A7=8B=E9=80=A0=E5=A4=89=E6=9B=B4API=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task4179: 階層構造変更API修正](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/4179) - 階層構造変更API修正 - 第四⇔第五の切り替え処理の時は国・リージョンの一致を確認しない - 不要なエラーコード・エラーハンドリングを削除 - テスト修正 ## レビューポイント - 修正箇所の認識は合っているか - テストケースは足りているか ## 動作確認状況 - ローカルで確認 - 国の違うDealerに付け替える処理を行い成功した - 行った修正がデグレを発生させていないことを確認できるか - 具体的にどのような確認をしたか - 国の違う第四⇔第五間の付け替えのテストが成功することを確認 - ほかのテストが成功することを確認 ## 補足 - 相談、参考資料などがあれば --- dictation_client/src/common/errors/code.ts | 1 - .../license/partnerLicense/operations.ts | 6 - dictation_server/src/common/error/code.ts | 1 - dictation_server/src/common/error/message.ts | 1 - .../accounts/accounts.service.spec.ts | 103 ++++++++++-------- .../src/features/accounts/accounts.service.ts | 19 +--- .../src/repositories/accounts/errors/types.ts | 9 -- 7 files changed, 63 insertions(+), 77 deletions(-) diff --git a/dictation_client/src/common/errors/code.ts b/dictation_client/src/common/errors/code.ts index fcef6f2..b1a366f 100644 --- a/dictation_client/src/common/errors/code.ts +++ b/dictation_client/src/common/errors/code.ts @@ -80,7 +80,6 @@ export const errorCodes = [ "E017001", // 親アカウント変更不可エラー(指定したアカウントが存在しない) "E017002", // 親アカウント変更不可エラー(階層関係が不正) "E017003", // 親アカウント変更不可エラー(リージョンが同一でない) - "E017004", // 親アカウント変更不可エラー(国が同一でない) "E018001", // パートナーアカウント削除エラー(削除条件を満たしていない) "E019001", // パートナーアカウント取得不可エラー(階層構造が不正) "E020001", // パートナーアカウント変更エラー(変更条件を満たしていない) diff --git a/dictation_client/src/features/license/partnerLicense/operations.ts b/dictation_client/src/features/license/partnerLicense/operations.ts index 8ceb0a8..84b5e73 100644 --- a/dictation_client/src/features/license/partnerLicense/operations.ts +++ b/dictation_client/src/features/license/partnerLicense/operations.ts @@ -174,12 +174,6 @@ export const switchParentAsync = createAsyncThunk< ); } - if (error.code === "E017004") { - errorMessage = getTranslationID( - "changeOwnerPopup.message.countryMismatchError" - ); - } - thunkApi.dispatch( openSnackbar({ level: "error", diff --git a/dictation_server/src/common/error/code.ts b/dictation_server/src/common/error/code.ts index 0b5902e..740e842 100644 --- a/dictation_server/src/common/error/code.ts +++ b/dictation_server/src/common/error/code.ts @@ -85,7 +85,6 @@ export const ErrorCodes = [ 'E017001', // 親アカウント変更不可エラー(指定したアカウントが存在しない) 'E017002', // 親アカウント変更不可エラー(階層関係が不正) 'E017003', // 親アカウント変更不可エラー(リージョンが同一でない) - 'E017004', // 親アカウント変更不可エラー(国が同一でない) 'E018001', // パートナーアカウント削除エラー(削除条件を満たしていない) 'E019001', // パートナーアカウント取得不可エラー(階層構造が不正) 'E020001', // パートナーアカウント変更エラー(変更条件を満たしていない) diff --git a/dictation_server/src/common/error/message.ts b/dictation_server/src/common/error/message.ts index 6731596..89e51c0 100644 --- a/dictation_server/src/common/error/message.ts +++ b/dictation_server/src/common/error/message.ts @@ -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', diff --git a/dictation_server/src/features/accounts/accounts.service.spec.ts b/dictation_server/src/features/accounts/accounts.service.spec.ts index 1dc617b..d185c6e 100644 --- a/dictation_server/src/features/accounts/accounts.service.spec.ts +++ b/dictation_server/src/features/accounts/accounts.service.spec.ts @@ -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); + 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, - ); - 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); - - 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', () => { diff --git a/dictation_server/src/features/accounts/accounts.service.ts b/dictation_server/src/features/accounts/accounts.service.ts index 6547f1c..3277dc9 100644 --- a/dictation_server/src/features/accounts/accounts.service.ts +++ b/dictation_server/src/features/accounts/accounts.service.ts @@ -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 { // 親アカウントの階層が想定外の場合、本関数の使い方が間違っているので例外を投げる diff --git a/dictation_server/src/repositories/accounts/errors/types.ts b/dictation_server/src/repositories/accounts/errors/types.ts index 4b59a1b..2c661e3 100644 --- a/dictation_server/src/repositories/accounts/errors/types.ts +++ b/dictation_server/src/repositories/accounts/errors/types.ts @@ -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'; - } -}