From cab7a75ec1e4a6977b7193b4b141f5e6751adaa2 Mon Sep 17 00:00:00 2001 From: "maruyama.t" Date: Fri, 15 Mar 2024 12:19:16 +0000 Subject: [PATCH] =?UTF-8?q?Merged=20PR=20849:=20=E6=9C=89=E5=8A=B9?= =?UTF-8?q?=E3=81=AA=E3=82=A2=E3=82=AB=E3=82=A6=E3=83=B3=E3=83=88=E5=86=85?= =?UTF-8?q?=E3=81=AE=E5=89=8A=E9=99=A4=E3=81=95=E3=82=8C=E3=81=9F=E3=83=A6?= =?UTF-8?q?=E3=83=BC=E3=82=B6=E3=83=BC=E3=81=AE=E5=89=B2=E3=82=8A=E5=BD=93?= =?UTF-8?q?=E3=81=A6=E5=B1=A5=E6=AD=B4=E3=81=8C=E9=9B=86=E8=A8=88=E3=81=95?= =?UTF-8?q?=E3=82=8C=E3=81=AA=E3=81=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task3929: 有効なアカウント内の削除されたユーザーの割り当て履歴が集計されない](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/3929) - 元PBI or タスクへのリンク(内容・目的などはそちらにあるはず) - 何をどう変更したか、追加したライブラリなど - このPull Requestでの対象/対象外 - 影響範囲(他の機能にも影響があるか) ## レビューポイント - 特にレビューしてほしい箇所 - 軽微なものや自明なものは記載不要 - 修正範囲が大きい場合などに記載 - 全体的にや仕様を満たしているか等は本当に必要な時のみ記載 ## UIの変更 - Before/Afterのスクショなど - スクショ置き場 ## 動作確認状況 - ローカルで確認、develop環境で確認など ## 補足 - 相談、参考資料などがあれば --- .../verification/verification.service.ts | 36 +- dictation_client/src/translation/de.json | 6 +- dictation_client/src/translation/en.json | 6 +- dictation_client/src/translation/es.json | 6 +- dictation_client/src/translation/fr.json | 6 +- .../src/functions/analysisLicenses.ts | 106 +- .../src/test/analysisLicenses.spec.ts | 1880 +++++++++++++++-- 7 files changed, 1814 insertions(+), 232 deletions(-) diff --git a/data_migration_tools/server/src/features/verification/verification.service.ts b/data_migration_tools/server/src/features/verification/verification.service.ts index 10733f5..97194b6 100644 --- a/data_migration_tools/server/src/features/verification/verification.service.ts +++ b/data_migration_tools/server/src/features/verification/verification.service.ts @@ -382,18 +382,26 @@ function compareCardLicenses( } */ - const formattedActivated = getFormattedDate( - filterdCardLicenses[0].activated_at, - `yyyy/MM/dd hh:mm:ss` + const formattedFileActivated = getFormattedDate( + cardlicensesInputFile.activated_at + ? new Date(cardlicensesInputFile.activated_at) + : null, + `yyyy/MM/dd hh:mm:ss`, + true ); - if (cardlicensesInputFile.activated_at !== formattedActivated) { + const formattedDbActivated = getFormattedDate( + filterdCardLicenses[0].activated_at, + `yyyy/MM/dd hh:mm:ss`, + true + ); + if (formattedFileActivated !== formattedDbActivated) { const VerificationResultDetailsOne: VerificationResultDetails = { input: "cardLicenses", inputRow: row, diffTargetTable: "cardLicenses", columnName: "activated_at", - fileData: cardlicensesInputFile.activated_at, - databaseData: formattedActivated, + fileData: formattedFileActivated, + databaseData: formattedDbActivated, reason: "内容不一致", }; VerificationResultDetails.push(VerificationResultDetailsOne); @@ -574,7 +582,13 @@ function compareLicenses( // expiry_dateについて、時はゼロパディングした値で比較する(×01~09 ○1~9) if ( !licensesFromDatabase[i] || - licensesFromFile[i].expired_date !== + getFormattedDate( + licensesFromFile[i].expired_date + ? new Date(licensesFromFile[i].expired_date) + : null, + `yyyy/MM/dd hh:mm:ss`, + true + ) !== getFormattedDate( licensesFromDatabase[i].expiry_date, `yyyy/MM/dd hh:mm:ss`, @@ -586,7 +600,13 @@ function compareLicenses( inputRow: licensesFromFile[i].row, diffTargetTable: "licenses", columnName: "expired_date", - fileData: licensesFromFile[i].expired_date, + fileData: getFormattedDate( + licensesFromFile[i].expired_date + ? new Date(licensesFromFile[i].expired_date) + : null, + `yyyy/MM/dd hh:mm:ss`, + true + ), databaseData: licensesFromDatabase[i] ? getFormattedDate( licensesFromDatabase[i].expiry_date, diff --git a/dictation_client/src/translation/de.json b/dictation_client/src/translation/de.json index 5f65907..a96efdc 100644 --- a/dictation_client/src/translation/de.json +++ b/dictation_client/src/translation/de.json @@ -154,7 +154,7 @@ "status": "Status", "expiration": "Verfallsdatum", "remaining": "Verbleibender Zeitraum", - "autoRenew": "Automatische Erneuerung", + "autoRenew": "Automatisch zuweisen", "licenseAlert": "Lizenzalarm", "notification": "Benachrichtigung", "users": "Benutzer", @@ -436,7 +436,7 @@ "templateOptional": "Vorlage (Optional)", "editRule": "Regel bearbeiten", "selected": "Ausgewählter transkriptionist", - "pool": "Liste der Transkriptionisten", + "pool": "Transkriptionsliste", "selectAuthor": "Autoren-ID auswählen", "selectWorktypeId": "Aufgabentypkennung auswählen", "selectTemplate": "Vorlage auswählen" @@ -456,7 +456,7 @@ "addTypistGroup": "Transkriptionist Gruppe hinzufügen", "transcriptionist": "Transkriptionist", "selected": "Ausgewählter transkriptionist", - "pool": "Liste der Transkriptionisten", + "pool": "Transkriptionsliste", "add": "Hinzufügen", "remove": "Entfernen", "editTypistGroup": "Transkriptionistengruppe bearbeiten" diff --git a/dictation_client/src/translation/en.json b/dictation_client/src/translation/en.json index 6d1eba5..57615cc 100644 --- a/dictation_client/src/translation/en.json +++ b/dictation_client/src/translation/en.json @@ -154,7 +154,7 @@ "status": "Status", "expiration": "Expiration Date", "remaining": "Remaining Period", - "autoRenew": "Auto Renew", + "autoRenew": "Auto Assign", "licenseAlert": "License Alert", "notification": "Notification", "users": "Users", @@ -436,7 +436,7 @@ "templateOptional": "Template (Optional)", "editRule": "Edit Rule", "selected": "Selected Transcriptionist", - "pool": "Transcriptionist List", + "pool": "Transcription List", "selectAuthor": "Select Author ID", "selectWorktypeId": "Select Worktype ID", "selectTemplate": "Select Template" @@ -456,7 +456,7 @@ "addTypistGroup": "Add Transcriptionist Group", "transcriptionist": "Transcriptionist", "selected": "Selected Transcriptionist", - "pool": "Transcriptionist List", + "pool": "Transcription List", "add": "Add", "remove": "Remove", "editTypistGroup": "Edit Transcriptionist Group" diff --git a/dictation_client/src/translation/es.json b/dictation_client/src/translation/es.json index d0c183f..47200a8 100644 --- a/dictation_client/src/translation/es.json +++ b/dictation_client/src/translation/es.json @@ -154,7 +154,7 @@ "status": "Estado", "expiration": "Fecha de caducidad", "remaining": "Período restante", - "autoRenew": "Renovación Automática", + "autoRenew": "Asignación automática", "licenseAlert": "Alerta de licencia", "notification": "Notificación", "users": "Usuarios", @@ -436,7 +436,7 @@ "templateOptional": "Plantilla (Opcional)", "editRule": "Editar regla", "selected": "Transcriptor seleccionado", - "pool": "Lista de transcriptores", + "pool": "Lista de transcriptor", "selectAuthor": "Seleccionar ID de autor", "selectWorktypeId": "Seleccionar ID de tipo de trabajo", "selectTemplate": "Seleccionar Plantilla" @@ -456,7 +456,7 @@ "addTypistGroup": "Agregar grupo transcriptor", "transcriptionist": "Transcriptor", "selected": "Transcriptor seleccionado", - "pool": "Lista de transcriptores", + "pool": "Lista de transcriptor", "add": "Añadir", "remove": "Eliminar", "editTypistGroup": "Editar grupo transcriptor" diff --git a/dictation_client/src/translation/fr.json b/dictation_client/src/translation/fr.json index 0e801cf..4560e2a 100644 --- a/dictation_client/src/translation/fr.json +++ b/dictation_client/src/translation/fr.json @@ -154,7 +154,7 @@ "status": "État", "expiration": "Date d'expiration", "remaining": "Période restante", - "autoRenew": "Renouvellement automatique", + "autoRenew": "Assignation automatique", "licenseAlert": "Alerte de licence", "notification": "Notification", "users": "Utilisateurs", @@ -436,7 +436,7 @@ "templateOptional": "Masque (Facultatif)", "editRule": "Modifier la règle", "selected": "Transcriptionniste sélectionné", - "pool": "Liste des transcripteurs", + "pool": "Liste de transcriptionniste", "selectAuthor": "Sélectionner le Identifiant Auteur", "selectWorktypeId": "Sélectionner le Identifiant du Type de travail", "selectTemplate": "Sélectionner le Masque" @@ -456,7 +456,7 @@ "addTypistGroup": "Ajouter un groupe de transcripteurs", "transcriptionist": "Transcriptionniste", "selected": "Transcriptionniste sélectionné", - "pool": "Liste des transcripteurs", + "pool": "Liste de transcriptionniste", "add": "Ajouter", "remove": "Supprimer", "editTypistGroup": "Modifier le groupe de transcripteurs" diff --git a/dictation_function/src/functions/analysisLicenses.ts b/dictation_function/src/functions/analysisLicenses.ts index ac3403d..22f4709 100644 --- a/dictation_function/src/functions/analysisLicenses.ts +++ b/dictation_function/src/functions/analysisLicenses.ts @@ -27,6 +27,7 @@ import { } from "../constants"; import { DateWithDayEndTime } from "../common/types/types"; import { initializeDataSource } from "../database/initializeDataSource"; +import { bigintTransformer } from "../common/entity"; /** * ライセンス数分析処理のメイン処理:ここから各処理を呼び出す @@ -166,8 +167,11 @@ export async function getBaseData( ); const switchedlicensesInTargetMonth = await licenseAllocationHistory .createQueryBuilder("licenseAllocationHistory") - .innerJoinAndSelect("licenseAllocationHistory.user", "user") - .innerJoin("user.account", "account") + .innerJoin( + "accounts", + "account", + "licenseAllocationHistory.account_id = account.id" + ) .where("account.tier = :tier", { tier: TIERS.TIER5 }) .andWhere("licenseAllocationHistory.switch_from_type IN (:...types)", { types: [SWITCH_FROM_TYPE.CARD, SWITCH_FROM_TYPE.TRIAL], @@ -408,10 +412,6 @@ export async function transferData( targetMonthYYYYMM: string ): Promise { context.log("[IN]transferData"); - class userIdAndRoles { - id: number; - role: string; - } const accountsAndUsersFromTier5 = baseData.accountsAndUsersFromTier5; const validLicenses = baseData.avairableLicenses; const currentMonthIssuedLicenses = baseData.licensesIssuedInTargetMonth; @@ -448,7 +448,7 @@ export async function transferData( outputDataAU.push(...header); // ユーザーIDとロールを格納する配列(型が違う為新たに作成する) - let tier5userIdAndRoles: userIdAndRoles[] = []; + let tier5userIdAndRoles: { id: number; role: string }[] = []; try { // 第五階層のアカウントごとにループ for (const account of accountsAndUsersFromTier5) { @@ -464,13 +464,20 @@ export async function transferData( // ユーザーとユーザーアーカイブからユーザーIDとロールを取得する if (account.user) { tier5userIdAndRoles = account.user.map((user) => { - return { id: user.id, role: user.role }; + // XXX entityを修正すべきだが、時期的に影響範囲が大きいため、ここで変換する + // 本対応は#3928で行う + return { id: bigintTransformer.from(user.id), role: user.role }; }); } if (account.userArchive) { tier5userIdAndRoles = tier5userIdAndRoles.concat( account.userArchive.map((userArchive) => { - return { id: userArchive.id, role: userArchive.role }; + // XXX entityを修正すべきだが、時期的に影響範囲が大きいため、ここで変換する + // 本対応は#3928で行う + return { + id: bigintTransformer.from(userArchive.id), + role: userArchive.role, + }; }) ); } @@ -735,40 +742,59 @@ export async function transferData( (license) => tier5userIdAndRoles.find( (user) => - user.id === license.user_id && user.role === USER_ROLES.TYPIST + // XXX entityを修正すべきだが、時期的に影響範囲が大きいため、ここで変換する + // 本対応は#3928で行う + user.id === bigintTransformer.from(license.user_id) && + user.role === USER_ROLES.TYPIST ) ); const switchedTypistLicensesAuthor = switchedTrialLicenses.filter( (license) => tier5userIdAndRoles.find( (user) => - user.id === license.user_id && user.role === USER_ROLES.AUTHOR + // XXX entityを修正すべきだが、時期的に影響範囲が大きいため、ここで変換する + // 本対応は#3928で行う + user.id === bigintTransformer.from(license.user_id) && + user.role === USER_ROLES.AUTHOR ) ); const switchedTypistLicensesNone = switchedTrialLicenses.filter( (license) => tier5userIdAndRoles.find( (user) => - user.id === license.user_id && user.role === USER_ROLES.NONE + // XXX entityを修正すべきだが、時期的に影響範囲が大きいため、ここで変換する + // 本対応は#3928で行う + user.id === bigintTransformer.from(license.user_id) && + user.role === USER_ROLES.NONE ) ); const switchedCardLicensesTypist = switchedCardLicenses.filter( (license) => tier5userIdAndRoles.find( (user) => - user.id === license.user_id && user.role === USER_ROLES.TYPIST + // XXX entityを修正すべきだが、時期的に影響範囲が大きいため、ここで変換する + // 本対応は#3928で行う + user.id === bigintTransformer.from(license.user_id) && + user.role === USER_ROLES.TYPIST ) ); const switchedCardLicensesAuthor = switchedCardLicenses.filter( (license) => tier5userIdAndRoles.find( (user) => - user.id === license.user_id && user.role === USER_ROLES.AUTHOR + // XXX entityを修正すべきだが、時期的に影響範囲が大きいため、ここで変換する + // 本対応は#3928で行う + user.id === bigintTransformer.from(license.user_id) && + user.role === USER_ROLES.AUTHOR ) ); const switchedCardLicensesNone = switchedCardLicenses.filter((license) => tier5userIdAndRoles.find( - (user) => user.id === license.user_id && user.role === USER_ROLES.NONE + (user) => + // XXX entityを修正すべきだが、時期的に影響範囲が大きいため、ここで変換する + // 本対応は#3928で行う + user.id === bigintTransformer.from(license.user_id) && + user.role === USER_ROLES.NONE ) ); // 切り替えライセンスの数をカウント @@ -920,7 +946,12 @@ export async function transferData( // アカウントに紐づくユーザーを取得 if (account.userArchive) { tier5userIdAndRoles = account.userArchive.map((userArchive) => { - return { id: userArchive.id, role: userArchive.role }; + return { + // XXX entityを修正すべきだが、時期的に影響範囲が大きいため、ここで変換する + // 本対応は#3928で行う + id: bigintTransformer.from(userArchive.id), + role: userArchive.role, + }; }); } // アカウントに紐づくライセンスを取得 @@ -1159,33 +1190,51 @@ export async function transferData( //(Typist・Author・None) const switchedTypistLicensesTypist = switchedTrialLicenses.filter( (license) => - tier5userIdAndRoles?.find((user) => user.id === license.user_id) - ?.role === USER_ROLES.TYPIST + // XXX entityを修正すべきだが、時期的に影響範囲が大きいため、ここで変換する + // 本対応は#3928で行う + tier5userIdAndRoles?.find( + (user) => user.id === bigintTransformer.from(license.user_id) + )?.role === USER_ROLES.TYPIST ); const switchedTypistLicensesAuthor = switchedTrialLicenses.filter( (license) => - tier5userIdAndRoles?.find((user) => user.id === license.user_id) - ?.role === USER_ROLES.AUTHOR + // XXX entityを修正すべきだが、時期的に影響範囲が大きいため、ここで変換する + // 本対応は#3928で行う + tier5userIdAndRoles?.find( + (user) => user.id === bigintTransformer.from(license.user_id) + )?.role === USER_ROLES.AUTHOR ); const switchedTypistLicensesNone = switchedTrialLicenses.filter( (license) => - tier5userIdAndRoles?.find((user) => user.id === license.user_id) - ?.role === USER_ROLES.NONE + // XXX entityを修正すべきだが、時期的に影響範囲が大きいため、ここで変換する + // 本対応は#3928で行う + tier5userIdAndRoles?.find( + (user) => user.id === bigintTransformer.from(license.user_id) + )?.role === USER_ROLES.NONE ); const switchedCardLicensesTypist = switchedCardLicenses.filter( (license) => - tier5userIdAndRoles?.find((user) => user.id === license.user_id) - ?.role === USER_ROLES.TYPIST + // XXX entityを修正すべきだが、時期的に影響範囲が大きいため、ここで変換する + // 本対応は#3928で行う + tier5userIdAndRoles?.find( + (user) => user.id === bigintTransformer.from(license.user_id) + )?.role === USER_ROLES.TYPIST ); const switchedCardLicensesAuthor = switchedCardLicenses.filter( (license) => - tier5userIdAndRoles?.find((user) => user.id === license.user_id) - ?.role === USER_ROLES.AUTHOR + // XXX entityを修正すべきだが、時期的に影響範囲が大きいため、ここで変換する + // 本対応は#3928で行う + tier5userIdAndRoles?.find( + (user) => user.id === bigintTransformer.from(license.user_id) + )?.role === USER_ROLES.AUTHOR ); const switchedCardLicensesNone = switchedCardLicenses.filter( (license) => - tier5userIdAndRoles?.find((user) => user.id === license.user_id) - ?.role === USER_ROLES.NONE + // XXX entityを修正すべきだが、時期的に影響範囲が大きいため、ここで変換する + // 本対応は#3928で行う + tier5userIdAndRoles?.find( + (user) => user.id === bigintTransformer.from(license.user_id) + )?.role === USER_ROLES.NONE ); // 切り替えライセンスの数をカウント const switchedTypistLicensesTypistCount = @@ -1819,7 +1868,6 @@ export async function outputAnalysisLicensesData( outputFileNameUS, csvContentUS ); - context.log("resultUS: " + resultUS); const resultEU = await blobstorageService.uploadFileAnalysisLicensesCSV( context, outputFileNameEU, diff --git a/dictation_function/src/test/analysisLicenses.spec.ts b/dictation_function/src/test/analysisLicenses.spec.ts index 0330d68..e2cfb0b 100644 --- a/dictation_function/src/test/analysisLicenses.spec.ts +++ b/dictation_function/src/test/analysisLicenses.spec.ts @@ -26,9 +26,11 @@ import { LICENSE_COUNT_ANALYSIS_CATEGORY_1, LICENSE_COUNT_ANALYSIS_CATEGORY_2, LICENSE_COUNT_ANALYSIS_LICENSE_TYPE, + LICENSE_COUNT_ANALYSIS_ROLE, SWITCH_FROM_TYPE, } from "../constants"; import { BlobstorageService } from "../blobstorage/blobstorage.service"; +import { User, UserArchive } from "../entity/user.entity"; describe("analysisLicenses", () => { dotenv.config({ path: ".env" }); dotenv.config({ path: ".env.local", override: true }); @@ -790,65 +792,54 @@ describe("analysisLicenses", () => { } ); // 第五アカウントに紐づくユーザーを作成する - const user5_1_2 = await makeTestUser(source, { - account_id: account5_1.id, - role: "typist", - }); - const user5_1_3 = await makeTestUser(source, { - account_id: account5_1.id, - role: "typist", - }); - const user5_1_4 = await makeTestUser(source, { - account_id: account5_1.id, - role: "typist", - }); - const user5_1_5 = await makeTestUser(source, { - account_id: account5_1.id, - role: "none", - }); - const user5_1_6 = await makeTestUser(source, { - account_id: account5_1.id, - role: "author", - }); - const user5_1_7 = await makeTestUser(source, { - account_id: account5_1.id, - role: "typist", - }); - const user5_1_8 = await makeTestUser(source, { - account_id: account5_1.id, - role: "none", - }); - const user5_1_9 = await makeTestUser(source, { - account_id: account5_1.id, - role: "none", - }); - const user5_1_10 = await makeTestUser(source, { - account_id: account5_1.id, - role: "typist", - }); + // 各ロール33人作成 + // users[0]~users[32] // author + // users[33]~users[65] // typist + // users[66]~users[98] // none + // author + const numberOfUsers = 33; + let users: User[] = []; - // 削除ユーザを作成する - const userArchive5_1_4 = await makeTestUserArchive(source, { - account_id: account5_1.id, - }); - // 第五階層以外だとヒットしないことの確認 - const userArchive4 = await makeTestUserArchive(source, { - account_id: account4.id, - }); + for (let i = 1; i <= numberOfUsers; i++) { + const user = await makeTestUser(source, { + account_id: account5_1.id, + role: "author", + }); + if (user) { + users.push(user); + } + } + // typist + for (let i = 1; i <= numberOfUsers; i++) { + const user = await makeTestUser(source, { + account_id: account5_1.id, + role: "typist", + }); + if (user) { + users.push(user); + } + } + // none + for (let i = 1; i <= numberOfUsers; i++) { + const user = await makeTestUser(source, { + account_id: account5_1.id, + role: "none", + }); + if (user) { + users.push(user); + } + } // 所有ライセンス - // trialLicensesCount 3件 - // normalLicensesCount 5件 - // cardLicensesCount 4件 // usedTrialLicensesAuthorCount 1件 await createLicense( source, 1, - null, + expiringSoonDate, account5_1.id, "TRIAL", LICENSE_ALLOCATED_STATUS.ALLOCATED, - admin5_1_1.id, + users[0].id, null, null, null, @@ -862,7 +853,7 @@ describe("analysisLicenses", () => { account5_1.id, "TRIAL", LICENSE_ALLOCATED_STATUS.ALLOCATED, - user5_1_2.id, + users[33].id, null, null, null, @@ -875,65 +866,208 @@ describe("analysisLicenses", () => { account5_1.id, "TRIAL", LICENSE_ALLOCATED_STATUS.ALLOCATED, - user5_1_3.id, + users[34].id, null, null, null, last2Month ); - // usedTrialLicensesNoneCount 0件 - // usedNormalLicensesAuthorCount 0件 - // usedNormalLicensesTypistCount 1件 + // usedTrialLicensesNoneCount 3件 await createLicense( source, 4, expiringSoonDate, account5_1.id, - "NORMAL", + "TRIAL", LICENSE_ALLOCATED_STATUS.ALLOCATED, - user5_1_4.id, + users[66].id, null, null, null, last2Month ); - // usedNormalLicensesNoneCount 1件 await createLicense( source, 5, expiringSoonDate, account5_1.id, - "NORMAL", + "TRIAL", LICENSE_ALLOCATED_STATUS.ALLOCATED, - user5_1_5.id, + users[67].id, null, null, null, last2Month ); - // usedCardLicensesAuthorCount 1件 await createLicense( source, 6, expiringSoonDate, account5_1.id, - "CARD", + "TRIAL", LICENSE_ALLOCATED_STATUS.ALLOCATED, - user5_1_6.id, + users[68].id, null, null, null, last2Month ); - // usedCardLicensesTypistCount 1件 + // usedNormalLicensesAuthorCount 4件 await createLicense( source, 7, expiringSoonDate, account5_1.id, + "NORMAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[1].id, + null, + null, + null, + last2Month + ); + await createLicense( + source, + 8, + expiringSoonDate, + account5_1.id, + "NORMAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[2].id, + null, + null, + null, + last2Month + ); + await createLicense( + source, + 9, + expiringSoonDate, + account5_1.id, + "NORMAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[3].id, + null, + null, + null, + last2Month + ); + await createLicense( + source, + 10, + expiringSoonDate, + account5_1.id, + "NORMAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[4].id, + null, + null, + null, + last2Month + ); + // usedNormalLicensesTypistCount 1件 + await createLicense( + source, + 11, + expiringSoonDate, + account5_1.id, + "NORMAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[35].id, + null, + null, + null, + last2Month + ); + // usedNormalLicensesNoneCount 2件 + await createLicense( + source, + 12, + expiringSoonDate, + account5_1.id, + "NORMAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[69].id, + null, + null, + null, + last2Month + ); + await createLicense( + source, + 13, + expiringSoonDate, + account5_1.id, + "NORMAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[70].id, + null, + null, + null, + last2Month + ); + // usedCardLicensesAuthorCount 2件 + await createLicense( + source, + 14, + expiringSoonDate, + account5_1.id, "CARD", LICENSE_ALLOCATED_STATUS.ALLOCATED, - user5_1_7.id, + users[5].id, + null, + null, + null, + last2Month + ); + await createLicense( + source, + 15, + expiringSoonDate, + account5_1.id, + "CARD", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[6].id, + null, + null, + null, + last2Month + ); + // usedCardLicensesTypistCount 3件 + await createLicense( + source, + 16, + expiringSoonDate, + account5_1.id, + "CARD", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[36].id, + null, + null, + null, + last2Month + ); + await createLicense( + source, + 17, + expiringSoonDate, + account5_1.id, + "CARD", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[37].id, + null, + null, + null, + last2Month + ); + await createLicense( + source, + 18, + expiringSoonDate, + account5_1.id, + "CARD", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[38].id, null, null, null, @@ -942,26 +1076,12 @@ describe("analysisLicenses", () => { // usedCardLicensesNoneCount 1件 await createLicense( source, - 8, + 19, expiringSoonDate, account5_1.id, "CARD", LICENSE_ALLOCATED_STATUS.ALLOCATED, - user5_1_8.id, - null, - null, - null, - last2Month - ); - // deleteはヒットしないことの確認 - await createLicense( - source, - 100, - expiringSoonDate, - account5_1.id, - "NORMAL", - LICENSE_ALLOCATED_STATUS.DELETED, - null, + users[71].id, null, null, null, @@ -973,11 +1093,50 @@ describe("analysisLicenses", () => { // ・ステータス:ALLOCATED/REUSABLE/UNALLOCATED // ・作成日:今日から1か月前 // ・期限:14日後 - // currentMonthIssuedTrialLicensesCount 0件 - // currentMonthIssuedNormalLicensesCount 3件 + // currentMonthIssuedTrialLicensesCount 3件 await createLicense( source, - 11, + 21, + expiringSoonDate, + account5_1.id, + "TRIAL", + LICENSE_ALLOCATED_STATUS.UNALLOCATED, + null, + null, + null, + null, + lastMonth + ); + await createLicense( + source, + 22, + expiringSoonDate, + account5_1.id, + "TRIAL", + LICENSE_ALLOCATED_STATUS.UNALLOCATED, + null, + null, + null, + null, + lastMonth + ); + await createLicense( + source, + 23, + expiringSoonDate, + account5_1.id, + "TRIAL", + LICENSE_ALLOCATED_STATUS.UNALLOCATED, + null, + null, + null, + null, + lastMonth + ); + // currentMonthIssuedNormalLicensesCount 2件 + await createLicense( + source, + 24, expiringSoonDate, account5_1.id, "NORMAL", @@ -990,20 +1149,7 @@ describe("analysisLicenses", () => { ); await createLicense( source, - 12, - expiringSoonDate, - account5_1.id, - "NORMAL", - LICENSE_ALLOCATED_STATUS.UNALLOCATED, - null, - null, - null, - null, - lastMonth - ); - await createLicense( - source, - 13, + 25, expiringSoonDate, account5_1.id, "NORMAL", @@ -1017,7 +1163,7 @@ describe("analysisLicenses", () => { // currentMonthIssuedCardLicensesCount 1件 await createLicense( source, - 14, + 26, expiringSoonDate, account5_1.id, "CARD", @@ -1028,63 +1174,232 @@ describe("analysisLicenses", () => { null, lastMonth ); - // deleteはヒットしないことの確認 - await createLicense( - source, - 101, - expiringSoonDate, - account5_1.id, - "NORMAL", - LICENSE_ALLOCATED_STATUS.DELETED, - null, - null, - null, - null, - lastMonth - ); + // その月に失効したライセンスを作成 // 条件: // ・第五アカウント // ・ステータス:ALLOCATED/REUSABLE/UNALLOCATED // ・作成日:今日から2か月前 // ・期限:先月 - // invalidTrialLicensesAuthorCount 0件 - // invalidTrialLicensesTypistCount 0件 - // invalidTrialLicensesNoneCount 1件 + // invalidTrialLicensesAuthorCount 5件 await createLicense( source, - 22, + 27, lastMonth, account5_1.id, "TRIAL", LICENSE_ALLOCATED_STATUS.ALLOCATED, - user5_1_9.id, + users[7].id, null, null, null, last2Month ); - // invalidTrialLicensesUnallocatedCount 0件 - // invalidNormalLicensesAuthorCount 0件 - // invalidNormalLicensesTypistCount 1件 await createLicense( source, - 23, + 28, + lastMonth, + account5_1.id, + "TRIAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[8].id, + null, + null, + null, + last2Month + ); + await createLicense( + source, + 29, + lastMonth, + account5_1.id, + "TRIAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[9].id, + null, + null, + null, + last2Month + ); + await createLicense( + source, + 30, + lastMonth, + account5_1.id, + "TRIAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[10].id, + null, + null, + null, + last2Month + ); + await createLicense( + source, + 31, + lastMonth, + account5_1.id, + "TRIAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[11].id, + null, + null, + null, + last2Month + ); + // invalidTrialLicensesTypistCount 3件 + await createLicense( + source, + 32, + lastMonth, + account5_1.id, + "TRIAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[40].id, + null, + null, + null, + last2Month + ); + await createLicense( + source, + 33, + lastMonth, + account5_1.id, + "TRIAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[41].id, + null, + null, + null, + last2Month + ); + await createLicense( + source, + 34, + lastMonth, + account5_1.id, + "TRIAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[42].id, + null, + null, + null, + last2Month + ); + // invalidTrialLicensesNoneCount 2件 + await createLicense( + source, + 35, + lastMonth, + account5_1.id, + "TRIAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[74].id, + null, + null, + null, + last2Month + ); + await createLicense( + source, + 36, + lastMonth, + account5_1.id, + "TRIAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[75].id, + null, + null, + null, + last2Month + ); + // invalidTrialLicensesUnallocatedCount 1件 + await createLicense( + source, + 37, + lastMonth, + account5_1.id, + "TRIAL", + LICENSE_ALLOCATED_STATUS.UNALLOCATED, + null, + null, + null, + null, + last2Month + ); + // invalidNormalLicensesAuthorCount 2件 + await createLicense( + source, + 38, lastMonth, account5_1.id, "NORMAL", LICENSE_ALLOCATED_STATUS.ALLOCATED, - user5_1_10.id, + users[12].id, null, null, null, last2Month ); - // invalidNormalLicensesNoneCount 0件 - // invalidNormalLicensesUnallocatedCount 1件 await createLicense( source, - 24, + 39, + lastMonth, + account5_1.id, + "NORMAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[13].id, + null, + null, + null, + last2Month + ); + // invalidNormalLicensesTypistCount 1件 + await createLicense( + source, + 40, + lastMonth, + account5_1.id, + "NORMAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[43].id, + null, + null, + null, + last2Month + ); + // invalidNormalLicensesNoneCount 2件 + await createLicense( + source, + 41, + lastMonth, + account5_1.id, + "NORMAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[76].id, + null, + null, + null, + last2Month + ); + await createLicense( + source, + 42, + lastMonth, + account5_1.id, + "NORMAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[77].id, + null, + null, + null, + last2Month + ); + // invalidNormalLicensesUnallocatedCount 2件 + await createLicense( + source, + 43, lastMonth, account5_1.id, "NORMAL", @@ -1095,32 +1410,159 @@ describe("analysisLicenses", () => { null, last2Month ); - - // invalidCardLicensesAuthorCount 0件 - // invalidCardLicensesTypistCount 0件 - // invalidCardLicensesNoneCount 0件 - // invalidCardLicensesUnallocatedCount 0件 - // deleteはヒットしないことの確認 await createLicense( source, - 102, + 44, lastMonth, account5_1.id, "NORMAL", - LICENSE_ALLOCATED_STATUS.DELETED, + LICENSE_ALLOCATED_STATUS.UNALLOCATED, null, null, null, null, last2Month ); - // 先々月はヒットしないことの確認 + // invalidCardLicensesAuthorCount 1件 await createLicense( source, - 103, - last2Month, + 45, + lastMonth, account5_1.id, - "NORMAL", + "CARD", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[14].id, + null, + null, + null, + last2Month + ); + // invalidCardLicensesTypistCount 2件 + await createLicense( + source, + 46, + lastMonth, + account5_1.id, + "CARD", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[44].id, + null, + null, + null, + last2Month + ); + await createLicense( + source, + 47, + lastMonth, + account5_1.id, + "CARD", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[45].id, + null, + null, + null, + last2Month + ); + // invalidCardLicensesNoneCount 3件 + await createLicense( + source, + 48, + lastMonth, + account5_1.id, + "CARD", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[78].id, + null, + null, + null, + last2Month + ); + await createLicense( + source, + 49, + lastMonth, + account5_1.id, + "CARD", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[79].id, + null, + null, + null, + last2Month + ); + await createLicense( + source, + 50, + lastMonth, + account5_1.id, + "CARD", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[80].id, + null, + null, + null, + last2Month + ); + // invalidCardLicensesUnallocatedCount 5件 + await createLicense( + source, + 51, + lastMonth, + account5_1.id, + "CARD", + LICENSE_ALLOCATED_STATUS.UNALLOCATED, + null, + null, + null, + null, + last2Month + ); + await createLicense( + source, + 52, + lastMonth, + account5_1.id, + "CARD", + LICENSE_ALLOCATED_STATUS.UNALLOCATED, + null, + null, + null, + null, + last2Month + ); + await createLicense( + source, + 53, + lastMonth, + account5_1.id, + "CARD", + LICENSE_ALLOCATED_STATUS.UNALLOCATED, + null, + null, + null, + null, + last2Month + ); + await createLicense( + source, + 54, + lastMonth, + account5_1.id, + "CARD", + LICENSE_ALLOCATED_STATUS.UNALLOCATED, + null, + null, + null, + null, + last2Month + ); + await createLicense( + source, + 55, + lastMonth, + account5_1.id, + "CARD", LICENSE_ALLOCATED_STATUS.UNALLOCATED, null, null, @@ -1138,52 +1580,1011 @@ describe("analysisLicenses", () => { await createLicenseAllocationHistory( source, 1, - admin5_1_1.id, + users[1].id, 1, true, account5_1.id, lastMonth, SWITCH_FROM_TYPE.TRIAL ); - // switchedTypistLicensesTypistCount 0件 - // switchedTypistLicensesNoneCount 0件 - // switchedCardLicensesAuthorCount 1件 + // switchedTypistLicensesTypistCount 2件 await createLicenseAllocationHistory( source, 2, - admin5_1_1.id, - 1, + users[34].id, + 2, + true, + account5_1.id, + lastMonth, + SWITCH_FROM_TYPE.TRIAL + ); + await createLicenseAllocationHistory( + source, + 3, + users[35].id, + 3, + true, + account5_1.id, + lastMonth, + SWITCH_FROM_TYPE.TRIAL + ); + // switchedTypistLicensesNoneCount 1件 + await createLicenseAllocationHistory( + source, + 4, + users[66].id, + 4, + true, + account5_1.id, + lastMonth, + SWITCH_FROM_TYPE.TRIAL + ); + // switchedNormalLicensesAuthorCount 1件 + await createLicenseAllocationHistory( + source, + 6, + users[5].id, + 6, true, account5_1.id, lastMonth, SWITCH_FROM_TYPE.CARD ); - // switchedCardLicensesTypistCount 0件 - // switchedCardLicensesNoneCount 0件 - // SWITCH_FROM_TYPE.NONEではヒットしないことの確認 + // switchedNormalLicensesTypistCount 2件 await createLicenseAllocationHistory( source, - 3, - admin5_1_1.id, - 1, + 7, + users[36].id, + 7, true, account5_1.id, lastMonth, - SWITCH_FROM_TYPE.NONE + SWITCH_FROM_TYPE.CARD ); - // 先々月の登録ではヒットしないことの確認 await createLicenseAllocationHistory( source, - 4, - admin5_1_1.id, - 1, + 8, + users[37].id, + 8, true, account5_1.id, - last2Month, - SWITCH_FROM_TYPE.TRIAL + lastMonth, + SWITCH_FROM_TYPE.CARD + ); + await createLicenseAllocationHistory( + source, + 5, + users[67].id, + 5, + true, + account5_1.id, + lastMonth, + SWITCH_FROM_TYPE.CARD + ); + await createLicenseAllocationHistory( + source, + 9, + users[69].id, + 9, + true, + account5_1.id, + lastMonth, + SWITCH_FROM_TYPE.CARD + ); + await createLicenseAllocationHistory( + source, + 10, + users[70].id, + 10, + true, + account5_1.id, + lastMonth, + SWITCH_FROM_TYPE.CARD ); const result = await getBaseData(context, lastMonthYYYYMM, source); + + // 削除されたアカウントとユーザーの情報を作成する + const { account: account5_1_D } = await makeTestAccountArchive( + source, + { + tier: 5, + parent_account_id: account4.id, + }, + { + external_id: "external_id_tier5admin1", + role: "author", + } + ); + + // 第五アカウントに紐づくユーザーを作成する + // 各ロール33人作成 + // users[0]~users[32] // author + // users[33]~users[65] // typist + // users[66]~users[98] // none + // author + let deleteUsers: UserArchive[] = []; + + for (let i = 1; i <= numberOfUsers; i++) { + const user = await makeTestUserArchive(source, { + account_id: account5_1_D.id, + role: "author", + }); + if (user) { + deleteUsers.push(user); + } + } + // typist + for (let i = 1; i <= numberOfUsers; i++) { + const user = await makeTestUserArchive(source, { + account_id: account5_1_D.id, + role: "typist", + }); + if (user) { + deleteUsers.push(user); + } + } + // none + for (let i = 1; i <= numberOfUsers; i++) { + const user = await makeTestUserArchive(source, { + account_id: account5_1_D.id, + role: "none", + }); + if (user) { + deleteUsers.push(user); + } + } + // 所有ライセンス + // usedTrialLicensesAuthorCount 1件 + await createLicenseArchive( + source, + 1, + expiringSoonDate, + account5_1_D.id, + "TRIAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[0].id, + null, + null, + null, + last2Month + ); + // usedTrialLicensesTypistCount 2件 + await createLicenseArchive( + source, + 2, + expiringSoonDate, + account5_1_D.id, + "TRIAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[33].id, + null, + null, + null, + last2Month + ); + await createLicenseArchive( + source, + 3, + expiringSoonDate, + account5_1_D.id, + "TRIAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[34].id, + null, + null, + null, + last2Month + ); + // usedTrialLicensesNoneCount 3件 + await createLicenseArchive( + source, + 4, + expiringSoonDate, + account5_1_D.id, + "TRIAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[66].id, + null, + null, + null, + last2Month + ); + await createLicenseArchive( + source, + 5, + expiringSoonDate, + account5_1_D.id, + "TRIAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[67].id, + null, + null, + null, + last2Month + ); + await createLicenseArchive( + source, + 6, + expiringSoonDate, + account5_1_D.id, + "TRIAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[68].id, + null, + null, + null, + last2Month + ); + // usedNormalLicensesAuthorCount 4件 + await createLicenseArchive( + source, + 7, + expiringSoonDate, + account5_1_D.id, + "NORMAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[1].id, + null, + null, + null, + last2Month + ); + await createLicenseArchive( + source, + 8, + expiringSoonDate, + account5_1_D.id, + "NORMAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[2].id, + null, + null, + null, + last2Month + ); + await createLicenseArchive( + source, + 9, + expiringSoonDate, + account5_1_D.id, + "NORMAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[3].id, + null, + null, + null, + last2Month + ); + await createLicenseArchive( + source, + 10, + expiringSoonDate, + account5_1_D.id, + "NORMAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[4].id, + null, + null, + null, + last2Month + ); + // usedNormalLicensesTypistCount 1件 + await createLicenseArchive( + source, + 11, + expiringSoonDate, + account5_1_D.id, + "NORMAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[35].id, + null, + null, + null, + last2Month + ); + // usedNormalLicensesNoneCount 2件 + await createLicenseArchive( + source, + 12, + expiringSoonDate, + account5_1_D.id, + "NORMAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[69].id, + null, + null, + null, + last2Month + ); + await createLicenseArchive( + source, + 13, + expiringSoonDate, + account5_1_D.id, + "NORMAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[70].id, + null, + null, + null, + last2Month + ); + // usedCardLicensesAuthorCount 2件 + await createLicenseArchive( + source, + 14, + expiringSoonDate, + account5_1_D.id, + "CARD", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[5].id, + null, + null, + null, + last2Month + ); + await createLicenseArchive( + source, + 15, + expiringSoonDate, + account5_1_D.id, + "CARD", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[6].id, + null, + null, + null, + last2Month + ); + // usedCardLicensesTypistCount 3件 + await createLicenseArchive( + source, + 16, + expiringSoonDate, + account5_1_D.id, + "CARD", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[36].id, + null, + null, + null, + last2Month + ); + await createLicenseArchive( + source, + 17, + expiringSoonDate, + account5_1_D.id, + "CARD", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[37].id, + null, + null, + null, + last2Month + ); + await createLicenseArchive( + source, + 18, + expiringSoonDate, + account5_1_D.id, + "CARD", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[38].id, + null, + null, + null, + last2Month + ); + // usedCardLicensesNoneCount 1件 + await createLicenseArchive( + source, + 19, + expiringSoonDate, + account5_1_D.id, + "CARD", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[71].id, + null, + null, + null, + last2Month + ); + // その月に発行したライセンスを作成 + // 条件: + // ・第五アカウント + // ・ステータス:ALLOCATED/REUSABLE/UNALLOCATED + // ・作成日:今日から1か月前 + // ・期限:14日後 + // currentMonthIssuedTrialLicensesCount 3件 + await createLicenseArchive( + source, + 21, + expiringSoonDate, + account5_1_D.id, + "TRIAL", + LICENSE_ALLOCATED_STATUS.UNALLOCATED, + null, + null, + null, + null, + lastMonth + ); + await createLicenseArchive( + source, + 22, + expiringSoonDate, + account5_1_D.id, + "TRIAL", + LICENSE_ALLOCATED_STATUS.UNALLOCATED, + null, + null, + null, + null, + lastMonth + ); + await createLicenseArchive( + source, + 23, + expiringSoonDate, + account5_1_D.id, + "TRIAL", + LICENSE_ALLOCATED_STATUS.UNALLOCATED, + null, + null, + null, + null, + lastMonth + ); + // currentMonthIssuedNormalLicensesCount 2件 + await createLicenseArchive( + source, + 24, + expiringSoonDate, + account5_1_D.id, + "NORMAL", + LICENSE_ALLOCATED_STATUS.UNALLOCATED, + null, + null, + null, + null, + lastMonth + ); + await createLicenseArchive( + source, + 25, + expiringSoonDate, + account5_1_D.id, + "NORMAL", + LICENSE_ALLOCATED_STATUS.UNALLOCATED, + null, + null, + null, + null, + lastMonth + ); + // currentMonthIssuedCardLicensesCount 1件 + await createLicenseArchive( + source, + 26, + expiringSoonDate, + account5_1_D.id, + "CARD", + LICENSE_ALLOCATED_STATUS.UNALLOCATED, + null, + null, + null, + null, + lastMonth + ); + + // その月に失効したライセンスを作成 + // 条件: + // ・第五アカウント + // ・ステータス:ALLOCATED/REUSABLE/UNALLOCATED + // ・作成日:今日から2か月前 + // ・期限:先月 + // invalidTrialLicensesAuthorCount 5件 + await createLicenseArchive( + source, + 27, + lastMonth, + account5_1_D.id, + "TRIAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[7].id, + null, + null, + null, + last2Month + ); + await createLicenseArchive( + source, + 28, + lastMonth, + account5_1_D.id, + "TRIAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[8].id, + null, + null, + null, + last2Month + ); + await createLicenseArchive( + source, + 29, + lastMonth, + account5_1_D.id, + "TRIAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[9].id, + null, + null, + null, + last2Month + ); + await createLicenseArchive( + source, + 30, + lastMonth, + account5_1_D.id, + "TRIAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[10].id, + null, + null, + null, + last2Month + ); + await createLicenseArchive( + source, + 31, + lastMonth, + account5_1_D.id, + "TRIAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[11].id, + null, + null, + null, + last2Month + ); + // invalidTrialLicensesTypistCount 3件 + await createLicenseArchive( + source, + 32, + lastMonth, + account5_1_D.id, + "TRIAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[40].id, + null, + null, + null, + last2Month + ); + await createLicenseArchive( + source, + 33, + lastMonth, + account5_1_D.id, + "TRIAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[41].id, + null, + null, + null, + last2Month + ); + await createLicenseArchive( + source, + 34, + lastMonth, + account5_1_D.id, + "TRIAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[42].id, + null, + null, + null, + last2Month + ); + // invalidTrialLicensesNoneCount 2件 + await createLicenseArchive( + source, + 35, + lastMonth, + account5_1_D.id, + "TRIAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[74].id, + null, + null, + null, + last2Month + ); + await createLicenseArchive( + source, + 36, + lastMonth, + account5_1_D.id, + "TRIAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[75].id, + null, + null, + null, + last2Month + ); + // invalidTrialLicensesUnallocatedCount 1件 + await createLicenseArchive( + source, + 37, + lastMonth, + account5_1_D.id, + "TRIAL", + LICENSE_ALLOCATED_STATUS.UNALLOCATED, + null, + null, + null, + null, + last2Month + ); + // invalidNormalLicensesAuthorCount 2件 + await createLicenseArchive( + source, + 38, + lastMonth, + account5_1_D.id, + "NORMAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[12].id, + null, + null, + null, + last2Month + ); + await createLicenseArchive( + source, + 39, + lastMonth, + account5_1_D.id, + "NORMAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[13].id, + null, + null, + null, + last2Month + ); + // invalidNormalLicensesTypistCount 1件 + await createLicenseArchive( + source, + 40, + lastMonth, + account5_1_D.id, + "NORMAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[43].id, + null, + null, + null, + last2Month + ); + // invalidNormalLicensesNoneCount 2件 + await createLicenseArchive( + source, + 41, + lastMonth, + account5_1_D.id, + "NORMAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[76].id, + null, + null, + null, + last2Month + ); + await createLicenseArchive( + source, + 42, + lastMonth, + account5_1_D.id, + "NORMAL", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[77].id, + null, + null, + null, + last2Month + ); + // invalidNormalLicensesUnallocatedCount 2件 + await createLicenseArchive( + source, + 43, + lastMonth, + account5_1_D.id, + "NORMAL", + LICENSE_ALLOCATED_STATUS.UNALLOCATED, + null, + null, + null, + null, + last2Month + ); + await createLicenseArchive( + source, + 44, + lastMonth, + account5_1_D.id, + "NORMAL", + LICENSE_ALLOCATED_STATUS.UNALLOCATED, + null, + null, + null, + null, + last2Month + ); + // invalidCardLicensesAuthorCount 1件 + await createLicenseArchive( + source, + 45, + lastMonth, + account5_1_D.id, + "CARD", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[14].id, + null, + null, + null, + last2Month + ); + // invalidCardLicensesTypistCount 2件 + await createLicenseArchive( + source, + 46, + lastMonth, + account5_1_D.id, + "CARD", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[44].id, + null, + null, + null, + last2Month + ); + await createLicenseArchive( + source, + 47, + lastMonth, + account5_1_D.id, + "CARD", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[45].id, + null, + null, + null, + last2Month + ); + // invalidCardLicensesNoneCount 3件 + await createLicenseArchive( + source, + 48, + lastMonth, + account5_1_D.id, + "CARD", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[78].id, + null, + null, + null, + last2Month + ); + await createLicenseArchive( + source, + 49, + lastMonth, + account5_1_D.id, + "CARD", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[79].id, + null, + null, + null, + last2Month + ); + await createLicenseArchive( + source, + 50, + lastMonth, + account5_1_D.id, + "CARD", + LICENSE_ALLOCATED_STATUS.ALLOCATED, + users[80].id, + null, + null, + null, + last2Month + ); + // invalidCardLicensesUnallocatedCount 5件 + await createLicenseArchive( + source, + 51, + lastMonth, + account5_1_D.id, + "CARD", + LICENSE_ALLOCATED_STATUS.UNALLOCATED, + null, + null, + null, + null, + last2Month + ); + await createLicenseArchive( + source, + 52, + lastMonth, + account5_1_D.id, + "CARD", + LICENSE_ALLOCATED_STATUS.UNALLOCATED, + null, + null, + null, + null, + last2Month + ); + await createLicenseArchive( + source, + 53, + lastMonth, + account5_1_D.id, + "CARD", + LICENSE_ALLOCATED_STATUS.UNALLOCATED, + null, + null, + null, + null, + last2Month + ); + await createLicenseArchive( + source, + 54, + lastMonth, + account5_1_D.id, + "CARD", + LICENSE_ALLOCATED_STATUS.UNALLOCATED, + null, + null, + null, + null, + last2Month + ); + await createLicenseArchive( + source, + 55, + lastMonth, + account5_1_D.id, + "CARD", + LICENSE_ALLOCATED_STATUS.UNALLOCATED, + null, + null, + null, + null, + last2Month + ); + + // 第五階層がその月におこなったライセンス切り替え情報を作成 + // 条件: + // ・第五アカウント + // ・実行日時:先月 + // ・切り替えタイプ:CARD/TRIAL + // switchedTypistLicensesAuthorCount 1件 + await createLicenseAllocationHistoryArchive( + source, + 1, + users[1].id, + 1, + true, + account5_1_D.id, + lastMonth, + SWITCH_FROM_TYPE.TRIAL + ); + // switchedTypistLicensesTypistCount 2件 + await createLicenseAllocationHistoryArchive( + source, + 2, + users[34].id, + 2, + true, + account5_1_D.id, + lastMonth, + SWITCH_FROM_TYPE.TRIAL + ); + await createLicenseAllocationHistoryArchive( + source, + 3, + users[35].id, + 3, + true, + account5_1_D.id, + lastMonth, + SWITCH_FROM_TYPE.TRIAL + ); + // switchedTypistLicensesNoneCount 1件 + await createLicenseAllocationHistoryArchive( + source, + 4, + users[66].id, + 4, + true, + account5_1_D.id, + lastMonth, + SWITCH_FROM_TYPE.TRIAL + ); + // switchedNormalLicensesAuthorCount 1件 + await createLicenseAllocationHistoryArchive( + source, + 6, + users[5].id, + 6, + true, + account5_1_D.id, + lastMonth, + SWITCH_FROM_TYPE.CARD + ); + // switchedNormalLicensesTypistCount 2件 + await createLicenseAllocationHistoryArchive( + source, + 7, + users[36].id, + 7, + true, + account5_1_D.id, + lastMonth, + SWITCH_FROM_TYPE.CARD + ); + await createLicenseAllocationHistoryArchive( + source, + 8, + users[37].id, + 8, + true, + account5_1_D.id, + lastMonth, + SWITCH_FROM_TYPE.CARD + ); + await createLicenseAllocationHistoryArchive( + source, + 5, + users[67].id, + 5, + true, + account5_1_D.id, + lastMonth, + SWITCH_FROM_TYPE.CARD + ); + await createLicenseAllocationHistoryArchive( + source, + 9, + users[69].id, + 9, + true, + account5_1_D.id, + lastMonth, + SWITCH_FROM_TYPE.CARD + ); + await createLicenseAllocationHistoryArchive( + source, + 10, + users[70].id, + 10, + true, + account5_1_D.id, + lastMonth, + SWITCH_FROM_TYPE.CARD + ); const result_D = await getBaseDataFromDeletedAccounts( context, lastMonthYYYYMM, @@ -1195,33 +2596,147 @@ describe("analysisLicenses", () => { result_D, lastMonthYYYYMM ); - // ヘッダー行 - // "アカウント", "対象年月", "カテゴリー1", "カテゴリー2", "ライセンス種別", "役割", "数量" - expect(transferDataResult.outputDataUS[0]).toEqual('"アカウント",'); - expect(transferDataResult.outputDataUS[1]).toEqual('"対象年月",'); - expect(transferDataResult.outputDataUS[2]).toEqual(`"カテゴリー1",`); - expect(transferDataResult.outputDataUS[3]).toEqual(`"カテゴリー2",`); - expect(transferDataResult.outputDataUS[4]).toEqual(`"ライセンス種別",`); - expect(transferDataResult.outputDataUS[5]).toEqual(`"役割",`); - expect(transferDataResult.outputDataUS[6]).toEqual(`"数量"` + "\r\n"); - // データ行 - // "アカウント", "対象年月", "カテゴリー1", "カテゴリー2", "ライセンス種別", "役割", "数量" - // 1行目だけ確認する - expect(transferDataResult.outputDataUS[7]).toEqual( - `"${account5_1.company_name}",` + let csvContentUS = ""; + for (let i = 0; i < transferDataResult.outputDataUS.length; i++) { + //カンマ区切りの文字列を作成 + csvContentUS += transferDataResult.outputDataUS[i]; + } + expect(csvContentUS).toBe( + '"アカウント","対象年月","カテゴリー1","カテゴリー2","ライセンス種別","役割","数量"' + + "\r\n" + + '"test inc.","202402","有効ライセンス数","所有ライセンス数","Trial","","9"' + + "\r\n" + + '"test inc.","202402","有効ライセンス数","所有ライセンス数","Standard","","9"' + + "\r\n" + + '"test inc.","202402","有効ライセンス数","所有ライセンス数","Card","","7"' + + "\r\n" + + '"test inc.","202402","有効ライセンス数","使用中ライセンス数","Trial","Author","1"' + + "\r\n" + + '"test inc.","202402","有効ライセンス数","使用中ライセンス数","Trial","Typist","2"' + + "\r\n" + + '"test inc.","202402","有効ライセンス数","使用中ライセンス数","Trial","None","3"' + + "\r\n" + + '"test inc.","202402","有効ライセンス数","使用中ライセンス数","Standard","Author","4"' + + "\r\n" + + '"test inc.","202402","有効ライセンス数","使用中ライセンス数","Standard","Typist","1"' + + "\r\n" + + '"test inc.","202402","有効ライセンス数","使用中ライセンス数","Standard","None","2"' + + "\r\n" + + '"test inc.","202402","有効ライセンス数","使用中ライセンス数","Card","Author","2"' + + "\r\n" + + '"test inc.","202402","有効ライセンス数","使用中ライセンス数","Card","Typist","3"' + + "\r\n" + + '"test inc.","202402","有効ライセンス数","使用中ライセンス数","Card","None","1"' + + "\r\n" + + '"test inc.","202402","新規発行ライセンス数","","Trial","","3"' + + "\r\n" + + '"test inc.","202402","新規発行ライセンス数","","Standard","","2"' + + "\r\n" + + '"test inc.","202402","新規発行ライセンス数","","Card","","1"' + + "\r\n" + + '"test inc.","202402","失効ライセンス数","","Trial","Author","5"' + + "\r\n" + + '"test inc.","202402","失効ライセンス数","","Trial","Typist","3"' + + "\r\n" + + '"test inc.","202402","失効ライセンス数","","Trial","None","2"' + + "\r\n" + + '"test inc.","202402","失効ライセンス数","","Trial","Unallocated","1"' + + "\r\n" + + '"test inc.","202402","失効ライセンス数","","Standard","Author","2"' + + "\r\n" + + '"test inc.","202402","失効ライセンス数","","Standard","Typist","1"' + + "\r\n" + + '"test inc.","202402","失効ライセンス数","","Standard","None","2"' + + "\r\n" + + '"test inc.","202402","失効ライセンス数","","Standard","Unallocated","2"' + + "\r\n" + + '"test inc.","202402","失効ライセンス数","","Card","Author","1"' + + "\r\n" + + '"test inc.","202402","失効ライセンス数","","Card","Typist","2"' + + "\r\n" + + '"test inc.","202402","失効ライセンス数","","Card","None","3"' + + "\r\n" + + '"test inc.","202402","失効ライセンス数","","Card","Unallocated","5"' + + "\r\n" + + '"test inc.","202402","有効ライセンス数","","トライアルから切り替え","Author","1"' + + "\r\n" + + '"test inc.","202402","有効ライセンス数","","トライアルから切り替え","Typist","2"' + + "\r\n" + + '"test inc.","202402","有効ライセンス数","","トライアルから切り替え","None","1"' + + "\r\n" + + '"test inc.","202402","有効ライセンス数","","カードから切り替え","Author","1"' + + "\r\n" + + '"test inc.","202402","有効ライセンス数","","カードから切り替え","Typist","2"' + + "\r\n" + + '"test inc.","202402","有効ライセンス数","","カードから切り替え","None","3"' + + "\r\n" + + '"1","202402","有効ライセンス数","所有ライセンス数","Trial","","9"' + + "\r\n" + + '"1","202402","有効ライセンス数","所有ライセンス数","Standard","","9"' + + "\r\n" + + '"1","202402","有効ライセンス数","所有ライセンス数","Card","","7"' + + "\r\n" + + '"1","202402","有効ライセンス数","使用中ライセンス数","Trial","Author","1"' + + "\r\n" + + '"1","202402","有効ライセンス数","使用中ライセンス数","Trial","Typist","2"' + + "\r\n" + + '"1","202402","有効ライセンス数","使用中ライセンス数","Trial","None","3"' + + "\r\n" + + '"1","202402","有効ライセンス数","使用中ライセンス数","Standard","Author","4"' + + "\r\n" + + '"1","202402","有効ライセンス数","使用中ライセンス数","Standard","Typist","1"' + + "\r\n" + + '"1","202402","有効ライセンス数","使用中ライセンス数","Standard","None","2"' + + "\r\n" + + '"1","202402","有効ライセンス数","使用中ライセンス数","Card","Author","2"' + + "\r\n" + + '"1","202402","有効ライセンス数","使用中ライセンス数","Card","Typist","3"' + + "\r\n" + + '"1","202402","有効ライセンス数","使用中ライセンス数","Card","None","1"' + + "\r\n" + + '"1","202402","新規発行ライセンス数","","Trial","","3"' + + "\r\n" + + '"1","202402","新規発行ライセンス数","","Standard","","2"' + + "\r\n" + + '"1","202402","新規発行ライセンス数","","Card","","1"' + + "\r\n" + + '"1","202402","失効ライセンス数","","Trial","Author","5"' + + "\r\n" + + '"1","202402","失効ライセンス数","","Trial","Typist","3"' + + "\r\n" + + '"1","202402","失効ライセンス数","","Trial","None","2"' + + "\r\n" + + '"1","202402","失効ライセンス数","","Trial","Unallocated","1"' + + "\r\n" + + '"1","202402","失効ライセンス数","","Standard","Author","2"' + + "\r\n" + + '"1","202402","失効ライセンス数","","Standard","Typist","1"' + + "\r\n" + + '"1","202402","失効ライセンス数","","Standard","None","2"' + + "\r\n" + + '"1","202402","失効ライセンス数","","Standard","Unallocated","2"' + + "\r\n" + + '"1","202402","失効ライセンス数","","Card","Author","1"' + + "\r\n" + + '"1","202402","失効ライセンス数","","Card","Typist","2"' + + "\r\n" + + '"1","202402","失効ライセンス数","","Card","None","3"' + + "\r\n" + + '"1","202402","失効ライセンス数","","Card","Unallocated","5"' + + "\r\n" + + '"1","202402","有効ライセンス数","","トライアルから切り替え","Author","1"' + + "\r\n" + + '"1","202402","有効ライセンス数","","トライアルから切り替え","Typist","2"' + + "\r\n" + + '"1","202402","有効ライセンス数","","トライアルから切り替え","None","1"' + + "\r\n" + + '"1","202402","有効ライセンス数","","カードから切り替え","Author","1"' + + "\r\n" + + '"1","202402","有効ライセンス数","","カードから切り替え","Typist","2"' + + "\r\n" + + '"1","202402","有効ライセンス数","","カードから切り替え","None","3"' + + "\r\n" ); - expect(transferDataResult.outputDataUS[8]).toEqual(`"${lastMonthYYYYMM}",`); - expect(transferDataResult.outputDataUS[9]).toEqual( - `"${LICENSE_COUNT_ANALYSIS_CATEGORY_1.VALID_LICENSES}",` - ); - expect(transferDataResult.outputDataUS[10]).toEqual( - `"${LICENSE_COUNT_ANALYSIS_CATEGORY_2.OWNER_LICENSES}",` - ); - expect(transferDataResult.outputDataUS[11]).toEqual( - `"${LICENSE_COUNT_ANALYSIS_LICENSE_TYPE.TRIAL}",` - ); - expect(transferDataResult.outputDataUS[12]).toEqual(`"",`); - expect(transferDataResult.outputDataUS[13]).toEqual(`"3"` + "\r\n"); }); it("outputDataの確認(Mock)", async () => { @@ -1231,7 +2746,6 @@ describe("analysisLicenses", () => { const context = new InvocationContext(); const currentDate = new DateWithZeroTime(); - const expiringSoonDate = new ExpirationThresholdDate(currentDate.getTime()); // 現在の日付を取得 const nowDate = new Date();