import { DataSource } from "typeorm"; import { getBaseData, getBaseDataFromDeletedAccounts, outputAnalysisLicensesData, transferData, } from "../functions/analysisLicenses"; import { makeTestAccount, makeTestUserArchive, createLicense, createLicenseAllocationHistory, makeTestAccountArchive, createLicenseArchive, createLicenseAllocationHistoryArchive, makeTestUser, } from "./common/utility"; import * as dotenv from "dotenv"; import { DateWithZeroTime, ExpirationThresholdDate, } from "../common/types/types"; import { InvocationContext } from "@azure/functions"; import { LICENSE_ALLOCATED_STATUS, 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.test", override: true }); let source: DataSource | null = null; beforeEach(async () => { source = new DataSource({ type: "sqlite", database: ":memory:", logging: false, entities: [__dirname + "/../../**/*.entity{.ts,.js}"], synchronize: true, // trueにすると自動的にmigrationが行われるため注意 }); return source.initialize(); }); afterEach(async () => { if (!source) return; await source.destroy(); source = null; }); it("getBaseData取得情報の確認", async () => { if (!source) fail(); const context = new InvocationContext(); const currentDate = new DateWithZeroTime(); const expiringSoonDate = new ExpirationThresholdDate(currentDate.getTime()); // 現在の日付を取得 const nowDate = new Date(); // 先月の日付を取得 const lastMonth = new Date(nowDate); lastMonth.setMonth(nowDate.getMonth() - 1); const lastMonthYYYYMM = `${lastMonth.getFullYear()}${( lastMonth.getMonth() + 1 ) .toString() .padStart(2, "0")}`; // 先々月の日付を取得 const last2Month = new Date(nowDate); last2Month.setMonth(nowDate.getMonth() - 2); // tier4とtier5のアカウント+管理者を作る(tier4は対象外確認用) // 第五アカウント:2件 // 第五ユーザー:2件 const { account: account4, admin: admin4 } = await makeTestAccount( source, { tier: 4 }, { external_id: "external_id_tier4admin" } ); const { account: account5_1, admin: admin5_1 } = await makeTestAccount( source, { tier: 5, parent_account_id: account4.id, }, { external_id: "external_id_tier5admin1" } ); const { account: account5_2, admin: admin5_2 } = await makeTestAccount( source, { tier: 5, parent_account_id: account4.id, }, { external_id: "external_id_tier5admin2" } ); // 削除ユーザを作成する const userArchive5 = await makeTestUserArchive(source, { account_id: account5_1.id, }); // 第五階層以外だとヒットしないことの確認 const userArchive4 = await makeTestUserArchive(source, { account_id: account4.id, }); // 所有ライセンス // 条件: // ・第五アカウント // ・ステータス:ALLOCATED/REUSABLE/UNALLOCATED // ・作成日:2か月前 // ・期限:null or 14日後 await createLicense( source, 1, null, account5_1.id, "NORMAL", LICENSE_ALLOCATED_STATUS.ALLOCATED, null, null, null, null, last2Month ); await createLicense( source, 2, expiringSoonDate, account5_1.id, "NORMAL", LICENSE_ALLOCATED_STATUS.REUSABLE, null, null, null, null, last2Month ); await createLicense( source, 3, expiringSoonDate, account5_1.id, "NORMAL", LICENSE_ALLOCATED_STATUS.UNALLOCATED, null, null, null, null, last2Month ); // deleteはヒットしないことの確認 await createLicense( source, 4, expiringSoonDate, account5_1.id, "NORMAL", LICENSE_ALLOCATED_STATUS.DELETED, null, null, null, null, last2Month ); // その月に発行したライセンスを作成 // 条件: // ・第五アカウント // ・ステータス:ALLOCATED/REUSABLE/UNALLOCATED // ・作成日:今日から1か月前 // ・期限:14日後 // ※条件的に「所有ライセンス」にもカウントされる(+3) await createLicense( source, 11, expiringSoonDate, account5_1.id, "NORMAL", LICENSE_ALLOCATED_STATUS.ALLOCATED, null, null, null, null, lastMonth ); await createLicense( source, 12, expiringSoonDate, account5_1.id, "NORMAL", LICENSE_ALLOCATED_STATUS.REUSABLE, null, null, null, null, lastMonth ); await createLicense( source, 13, expiringSoonDate, account5_1.id, "NORMAL", LICENSE_ALLOCATED_STATUS.UNALLOCATED, null, null, null, null, lastMonth ); // deleteはヒットしないことの確認 await createLicense( source, 14, expiringSoonDate, account5_1.id, "NORMAL", LICENSE_ALLOCATED_STATUS.DELETED, null, null, null, null, lastMonth ); // その月に失効したライセンスを作成 // 条件: // ・第五アカウント // ・ステータス:ALLOCATED/REUSABLE/UNALLOCATED // ・作成日:今日から2か月前 // ・期限:先月 await createLicense( source, 21, lastMonth, account5_1.id, "NORMAL", LICENSE_ALLOCATED_STATUS.ALLOCATED, null, null, null, null, last2Month ); await createLicense( source, 22, lastMonth, account5_1.id, "NORMAL", LICENSE_ALLOCATED_STATUS.REUSABLE, null, null, null, null, last2Month ); await createLicense( source, 23, lastMonth, account5_1.id, "NORMAL", LICENSE_ALLOCATED_STATUS.UNALLOCATED, null, null, null, null, last2Month ); // deleteはヒットしないことの確認 await createLicense( source, 24, lastMonth, account5_1.id, "NORMAL", LICENSE_ALLOCATED_STATUS.DELETED, null, null, null, null, last2Month ); // 先々月はヒットしないことの確認 await createLicense( source, 25, last2Month, account5_1.id, "NORMAL", LICENSE_ALLOCATED_STATUS.UNALLOCATED, null, null, null, null, last2Month ); // 第五階層がその月におこなったライセンス切り替え情報を作成 // 条件: // ・第五アカウント // ・実行日時:先月 // ・切り替えタイプ:CARD/TRIAL await createLicenseAllocationHistory( source, 1, admin5_1.id, 1, true, account5_1.id, lastMonth, SWITCH_FROM_TYPE.CARD ); await createLicenseAllocationHistory( source, 2, admin5_1.id, 1, true, account5_1.id, lastMonth, SWITCH_FROM_TYPE.TRIAL ); // SWITCH_FROM_TYPE.NONEではヒットしないことの確認 await createLicenseAllocationHistory( source, 3, admin5_1.id, 1, true, account5_1.id, lastMonth, SWITCH_FROM_TYPE.NONE ); // 先々月の登録ではヒットしないことの確認 await createLicenseAllocationHistory( source, 4, admin5_1.id, 1, true, account5_1.id, last2Month, SWITCH_FROM_TYPE.TRIAL ); const result = await getBaseData(context, lastMonthYYYYMM, source); expect(result.accountsAndUsersFromTier5).toHaveLength(2); expect(result.accountsAndUsersFromTier5[0].id).toBe(account5_1.id); expect(result.accountsAndUsersFromTier5[1].id).toBe(account5_2.id); expect(result.accountsAndUsersFromTier5[0].user).toHaveLength(1); expect(result.accountsAndUsersFromTier5[1].user).toHaveLength(1); if ( result.accountsAndUsersFromTier5[0].user && result.accountsAndUsersFromTier5[1].user ) { expect(result.accountsAndUsersFromTier5[0].user[0].id).toBe(admin5_1.id); expect(result.accountsAndUsersFromTier5[1].user[0].id).toBe(admin5_2.id); } else { throw new Error("ユーザー取得できていないので失敗"); } expect(result.accountsAndUsersFromTier5[0].userArchive).toHaveLength(1); if (result.accountsAndUsersFromTier5[0].userArchive) { expect(result.accountsAndUsersFromTier5[0].userArchive[0].id).toBe( userArchive5.id ); } else { throw new Error("ユーザー取得できていないので失敗"); } expect(result.avairableLicenses).toHaveLength(6); expect(result.avairableLicenses[0].id).toBe(1); expect(result.avairableLicenses[1].id).toBe(2); expect(result.avairableLicenses[2].id).toBe(3); expect(result.avairableLicenses[3].id).toBe(11); expect(result.avairableLicenses[4].id).toBe(12); expect(result.avairableLicenses[5].id).toBe(13); expect(result.licensesIssuedInTargetMonth).toHaveLength(3); expect(result.licensesIssuedInTargetMonth[0].id).toBe(11); expect(result.licensesIssuedInTargetMonth[1].id).toBe(12); expect(result.licensesIssuedInTargetMonth[2].id).toBe(13); expect(result.licensesExpiredInTargetMonth).toHaveLength(3); expect(result.licensesExpiredInTargetMonth[0].id).toBe(21); expect(result.licensesExpiredInTargetMonth[1].id).toBe(22); expect(result.licensesExpiredInTargetMonth[2].id).toBe(23); expect(result.switchedlicensesInTargetMonth).toHaveLength(2); expect(result.switchedlicensesInTargetMonth[0].id).toBe(1); expect(result.switchedlicensesInTargetMonth[1].id).toBe(2); }); it("getBaseDataFromDeletedAccounts取得情報の確認", async () => { if (!source) fail(); const context = new InvocationContext(); const currentDate = new DateWithZeroTime(); const expiringSoonDate = new ExpirationThresholdDate(currentDate.getTime()); // 現在の日付を取得 const nowDate = new Date(); // 先月の日付を取得 const lastMonth = new Date(nowDate); lastMonth.setMonth(nowDate.getMonth() - 1); const lastMonthYYYYMM = `${lastMonth.getFullYear()}${( lastMonth.getMonth() + 1 ) .toString() .padStart(2, "0")}`; // 先々月の日付を取得 const last2Month = new Date(nowDate); last2Month.setMonth(nowDate.getMonth() - 2); // tier4とtier5のアカウント+管理者を作る(tier4は対象外確認用) // 第五アカウント:2件 // 第五ユーザー:2件 const { account: account4, admin: admin4 } = await makeTestAccountArchive( source, { tier: 4 }, { external_id: "external_id_tier4admin" } ); const { account: account5_1, admin: admin5_1 } = await makeTestAccountArchive( source, { tier: 5, parent_account_id: account4.id, }, { external_id: "external_id_tier5admin1" } ); const { account: account5_2, admin: admin5_2 } = await makeTestAccountArchive( source, { tier: 5, parent_account_id: account4.id, }, { external_id: "external_id_tier5admin2" } ); // 所有ライセンス // 条件: // ・第五アカウント // ・ステータス:ALLOCATED/REUSABLE/UNALLOCATED // ・作成日:2か月前 // ・期限:null or 14日後 await createLicenseArchive( source, 1, null, account5_1.id, "NORMAL", LICENSE_ALLOCATED_STATUS.ALLOCATED, null, null, null, null, last2Month ); await createLicenseArchive( source, 2, expiringSoonDate, account5_1.id, "NORMAL", LICENSE_ALLOCATED_STATUS.REUSABLE, null, null, null, null, last2Month ); await createLicenseArchive( source, 3, expiringSoonDate, account5_1.id, "NORMAL", LICENSE_ALLOCATED_STATUS.UNALLOCATED, null, null, null, null, last2Month ); // deleteはヒットしないことの確認 await createLicenseArchive( source, 4, expiringSoonDate, account5_1.id, "NORMAL", LICENSE_ALLOCATED_STATUS.DELETED, null, null, null, null, last2Month ); // その月に発行したライセンスを作成 // 条件: // ・第五アカウント // ・ステータス:ALLOCATED/REUSABLE/UNALLOCATED // ・作成日:今日から1か月前 // ・期限:14日後 // ※条件的に「所有ライセンス」にもカウントされる(+3) await createLicenseArchive( source, 11, expiringSoonDate, account5_1.id, "NORMAL", LICENSE_ALLOCATED_STATUS.ALLOCATED, null, null, null, null, lastMonth ); await createLicenseArchive( source, 12, expiringSoonDate, account5_1.id, "NORMAL", LICENSE_ALLOCATED_STATUS.REUSABLE, null, null, null, null, lastMonth ); await createLicenseArchive( source, 13, expiringSoonDate, account5_1.id, "NORMAL", LICENSE_ALLOCATED_STATUS.UNALLOCATED, null, null, null, null, lastMonth ); // deleteはヒットしないことの確認 await createLicenseArchive( source, 14, expiringSoonDate, account5_1.id, "NORMAL", LICENSE_ALLOCATED_STATUS.DELETED, null, null, null, null, lastMonth ); // その月に失効したライセンスを作成 // 条件: // ・第五アカウント // ・ステータス:ALLOCATED/REUSABLE/UNALLOCATED // ・作成日:今日から2か月前 // ・期限:先月 await createLicenseArchive( source, 21, lastMonth, account5_1.id, "NORMAL", LICENSE_ALLOCATED_STATUS.ALLOCATED, null, null, null, null, last2Month ); await createLicenseArchive( source, 22, lastMonth, account5_1.id, "NORMAL", LICENSE_ALLOCATED_STATUS.REUSABLE, null, null, null, null, last2Month ); await createLicenseArchive( source, 23, lastMonth, account5_1.id, "NORMAL", LICENSE_ALLOCATED_STATUS.UNALLOCATED, null, null, null, null, last2Month ); // deleteはヒットしないことの確認 await createLicenseArchive( source, 24, lastMonth, account5_1.id, "NORMAL", LICENSE_ALLOCATED_STATUS.DELETED, null, null, null, null, last2Month ); // 先々月はヒットしないことの確認 await createLicenseArchive( source, 25, last2Month, account5_1.id, "NORMAL", LICENSE_ALLOCATED_STATUS.UNALLOCATED, null, null, null, null, last2Month ); // 第五階層がその月におこなったライセンス切り替え情報を作成 // 条件: // ・第五アカウント // ・実行日時:先月 // ・切り替えタイプ:CARD/TRIAL await createLicenseAllocationHistoryArchive( source, 1, admin5_1.id, 1, true, account5_1.id, lastMonth, SWITCH_FROM_TYPE.CARD ); await createLicenseAllocationHistoryArchive( source, 2, admin5_1.id, 1, true, account5_1.id, lastMonth, SWITCH_FROM_TYPE.TRIAL ); // SWITCH_FROM_TYPE.NONEではヒットしないことの確認 await createLicenseAllocationHistoryArchive( source, 3, admin5_1.id, 1, true, account5_1.id, lastMonth, SWITCH_FROM_TYPE.NONE ); // 先々月の登録ではヒットしないことの確認 await createLicenseAllocationHistoryArchive( source, 4, admin5_1.id, 1, true, account5_1.id, last2Month, SWITCH_FROM_TYPE.TRIAL ); const result = await getBaseDataFromDeletedAccounts( context, lastMonthYYYYMM, source ); expect(result.deletedAccountsAndUsersFromTier5).toHaveLength(2); expect(result.deletedAccountsAndUsersFromTier5[0].id).toBe(account5_1.id); expect(result.deletedAccountsAndUsersFromTier5[1].id).toBe(account5_2.id); expect(result.deletedAccountsAndUsersFromTier5[0].userArchive).toHaveLength( 1 ); expect(result.deletedAccountsAndUsersFromTier5[1].userArchive).toHaveLength( 1 ); if ( result.deletedAccountsAndUsersFromTier5[0].userArchive && result.deletedAccountsAndUsersFromTier5[1].userArchive ) { expect(result.deletedAccountsAndUsersFromTier5[0].userArchive[0].id).toBe( admin5_1.id ); expect(result.deletedAccountsAndUsersFromTier5[1].userArchive[0].id).toBe( admin5_2.id ); } expect(result.deletedAvairableLicenses).toHaveLength(6); expect(result.deletedAvairableLicenses[0].id).toBe(1); expect(result.deletedAvairableLicenses[1].id).toBe(2); expect(result.deletedAvairableLicenses[2].id).toBe(3); expect(result.deletedAvairableLicenses[3].id).toBe(11); expect(result.deletedAvairableLicenses[4].id).toBe(12); expect(result.deletedAvairableLicenses[5].id).toBe(13); expect(result.deletedLicensesIssuedInTargetMonth).toHaveLength(3); expect(result.deletedLicensesIssuedInTargetMonth[0].id).toBe(11); expect(result.deletedLicensesIssuedInTargetMonth[1].id).toBe(12); expect(result.deletedLicensesIssuedInTargetMonth[2].id).toBe(13); expect(result.deletedLicensesExpiredInTargetMonth).toHaveLength(3); expect(result.deletedLicensesExpiredInTargetMonth[0].id).toBe(21); expect(result.deletedLicensesExpiredInTargetMonth[1].id).toBe(22); expect(result.deletedLicensesExpiredInTargetMonth[2].id).toBe(23); expect(result.deletedSwitchedlicensesInTargetMonth).toHaveLength(2); expect(result.deletedSwitchedlicensesInTargetMonth[0].id).toBe(1); expect(result.deletedSwitchedlicensesInTargetMonth[1].id).toBe(2); }); it("transferDataの確認", async () => { // getBaseData取得情報の確認とgetBaseDataFromDeletedAccounts取得情報の確認 if (!source) fail(); const context = new InvocationContext(); const currentDate = new DateWithZeroTime(); const expiringSoonDate = new ExpirationThresholdDate(currentDate.getTime()); // 現在の日付を取得 const nowDate = new Date(); // 先月の日付を取得 const lastMonth = new Date(nowDate); lastMonth.setMonth(nowDate.getMonth() - 1); const lastMonthYYYYMM = `${lastMonth.getFullYear()}${( lastMonth.getMonth() + 1 ) .toString() .padStart(2, "0")}`; // 先々月の日付を取得 const last2Month = new Date(nowDate); last2Month.setMonth(nowDate.getMonth() - 2); const last2MonthYYYYMM = `${last2Month.getFullYear()}${( last2Month.getMonth() + 1 ) .toString() .padStart(2, "0")}`; // tier4とtier5のアカウント+管理者を作る const { account: account4, admin: admin4 } = await makeTestAccount( source, { tier: 4 }, { external_id: "external_id_tier4admin" } ); const { account: account5_1, admin: admin5_1_1 } = await makeTestAccount( 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 const numberOfUsers = 33; let users: User[] = []; 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); } } // 所有ライセンス // usedTrialLicensesAuthorCount 1件 await createLicense( source, 1, expiringSoonDate, account5_1.id, "TRIAL", LICENSE_ALLOCATED_STATUS.ALLOCATED, users[0].id, null, null, null, last2Month ); // usedTrialLicensesTypistCount 2件 await createLicense( source, 2, expiringSoonDate, account5_1.id, "TRIAL", LICENSE_ALLOCATED_STATUS.ALLOCATED, users[33].id, null, null, null, last2Month ); await createLicense( source, 3, expiringSoonDate, account5_1.id, "TRIAL", LICENSE_ALLOCATED_STATUS.ALLOCATED, users[34].id, null, null, null, last2Month ); // usedTrialLicensesNoneCount 3件 await createLicense( source, 4, expiringSoonDate, account5_1.id, "TRIAL", LICENSE_ALLOCATED_STATUS.ALLOCATED, users[66].id, null, null, null, last2Month ); await createLicense( source, 5, expiringSoonDate, account5_1.id, "TRIAL", LICENSE_ALLOCATED_STATUS.ALLOCATED, users[67].id, null, null, null, last2Month ); await createLicense( source, 6, expiringSoonDate, account5_1.id, "TRIAL", LICENSE_ALLOCATED_STATUS.ALLOCATED, users[68].id, null, null, null, last2Month ); // 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, 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, last2Month ); // usedCardLicensesNoneCount 1件 await createLicense( source, 19, expiringSoonDate, account5_1.id, "CARD", LICENSE_ALLOCATED_STATUS.ALLOCATED, users[71].id, null, null, null, last2Month ); // その月に発行したライセンスを作成 // 条件: // ・第五アカウント // ・ステータス:ALLOCATED/REUSABLE/UNALLOCATED // ・作成日:今日から1か月前 // ・期限:14日後 // currentMonthIssuedTrialLicensesCount 3件 await createLicense( source, 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", LICENSE_ALLOCATED_STATUS.UNALLOCATED, null, null, null, null, lastMonth ); await createLicense( source, 25, expiringSoonDate, account5_1.id, "NORMAL", LICENSE_ALLOCATED_STATUS.UNALLOCATED, null, null, null, null, lastMonth ); // currentMonthIssuedCardLicensesCount 1件 await createLicense( source, 26, expiringSoonDate, account5_1.id, "CARD", LICENSE_ALLOCATED_STATUS.UNALLOCATED, null, null, null, null, lastMonth ); // その月に失効したライセンスを作成 // 条件: // ・第五アカウント // ・ステータス:ALLOCATED/REUSABLE/UNALLOCATED // ・作成日:今日から2か月前 // ・期限:先月 // invalidTrialLicensesAuthorCount 5件 await createLicense( source, 27, lastMonth, account5_1.id, "TRIAL", LICENSE_ALLOCATED_STATUS.ALLOCATED, users[7].id, null, null, null, last2Month ); await createLicense( source, 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, users[12].id, null, null, null, last2Month ); await createLicense( source, 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", LICENSE_ALLOCATED_STATUS.UNALLOCATED, null, null, null, null, last2Month ); await createLicense( source, 44, lastMonth, account5_1.id, "NORMAL", LICENSE_ALLOCATED_STATUS.UNALLOCATED, null, null, null, null, last2Month ); // invalidCardLicensesAuthorCount 1件 await createLicense( source, 45, lastMonth, account5_1.id, "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, null, null, last2Month ); // 第五階層がその月におこなったライセンス切り替え情報を作成 // 条件: // ・第五アカウント // ・実行日時:先月 // ・切り替えタイプ:CARD/TRIAL // switchedTypistLicensesAuthorCount 1件 await createLicenseAllocationHistory( source, 1, users[1].id, 1, true, account5_1.id, lastMonth, SWITCH_FROM_TYPE.TRIAL ); // switchedTypistLicensesTypistCount 2件 await createLicenseAllocationHistory( source, 2, 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 ); // switchedNormalLicensesTypistCount 2件 await createLicenseAllocationHistory( source, 7, users[36].id, 7, true, account5_1.id, lastMonth, SWITCH_FROM_TYPE.CARD ); await createLicenseAllocationHistory( source, 8, users[37].id, 8, true, account5_1.id, 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, source ); const transferDataResult = await transferData( context, result, result_D, lastMonthYYYYMM ); let csvContentUS = ""; for (let i = 0; i < transferDataResult.outputDataUS.length; i++) { //カンマ区切りの文字列を作成 csvContentUS += transferDataResult.outputDataUS[i]; } expect(csvContentUS).toBe( '"アカウント","対象年月","カテゴリー1","カテゴリー2","ライセンス種別","役割","数量"' + "\r\n" + `"test inc.","${lastMonthYYYYMM}","有効ライセンス数","所有ライセンス数","Trial","","9"` + "\r\n" + `"test inc.","${lastMonthYYYYMM}","有効ライセンス数","所有ライセンス数","Standard","","9"` + "\r\n" + `"test inc.","${lastMonthYYYYMM}","有効ライセンス数","所有ライセンス数","Card","","7"` + "\r\n" + `"test inc.","${lastMonthYYYYMM}","有効ライセンス数","使用中ライセンス数","Trial","Author","1"` + "\r\n" + `"test inc.","${lastMonthYYYYMM}","有効ライセンス数","使用中ライセンス数","Trial","Typist","2"` + "\r\n" + `"test inc.","${lastMonthYYYYMM}","有効ライセンス数","使用中ライセンス数","Trial","None","3"` + "\r\n" + `"test inc.","${lastMonthYYYYMM}","有効ライセンス数","使用中ライセンス数","Standard","Author","4"` + "\r\n" + `"test inc.","${lastMonthYYYYMM}","有効ライセンス数","使用中ライセンス数","Standard","Typist","1"` + "\r\n" + `"test inc.","${lastMonthYYYYMM}","有効ライセンス数","使用中ライセンス数","Standard","None","2"` + "\r\n" + `"test inc.","${lastMonthYYYYMM}","有効ライセンス数","使用中ライセンス数","Card","Author","2"` + "\r\n" + `"test inc.","${lastMonthYYYYMM}","有効ライセンス数","使用中ライセンス数","Card","Typist","3"` + "\r\n" + `"test inc.","${lastMonthYYYYMM}","有効ライセンス数","使用中ライセンス数","Card","None","1"` + "\r\n" + `"test inc.","${lastMonthYYYYMM}","新規発行ライセンス数","","Trial","","3"` + "\r\n" + `"test inc.","${lastMonthYYYYMM}","新規発行ライセンス数","","Standard","","2"` + "\r\n" + `"test inc.","${lastMonthYYYYMM}","新規発行ライセンス数","","Card","","1"` + "\r\n" + `"test inc.","${lastMonthYYYYMM}","失効ライセンス数","","Trial","Author","5"` + "\r\n" + `"test inc.","${lastMonthYYYYMM}","失効ライセンス数","","Trial","Typist","3"` + "\r\n" + `"test inc.","${lastMonthYYYYMM}","失効ライセンス数","","Trial","None","2"` + "\r\n" + `"test inc.","${lastMonthYYYYMM}","失効ライセンス数","","Trial","Unallocated","1"` + "\r\n" + `"test inc.","${lastMonthYYYYMM}","失効ライセンス数","","Standard","Author","2"` + "\r\n" + `"test inc.","${lastMonthYYYYMM}","失効ライセンス数","","Standard","Typist","1"` + "\r\n" + `"test inc.","${lastMonthYYYYMM}","失効ライセンス数","","Standard","None","2"` + "\r\n" + `"test inc.","${lastMonthYYYYMM}","失効ライセンス数","","Standard","Unallocated","2"` + "\r\n" + `"test inc.","${lastMonthYYYYMM}","失効ライセンス数","","Card","Author","1"` + "\r\n" + `"test inc.","${lastMonthYYYYMM}","失効ライセンス数","","Card","Typist","2"` + "\r\n" + `"test inc.","${lastMonthYYYYMM}","失効ライセンス数","","Card","None","3"` + "\r\n" + `"test inc.","${lastMonthYYYYMM}","失効ライセンス数","","Card","Unallocated","5"` + "\r\n" + `"test inc.","${lastMonthYYYYMM}","有効ライセンス数","","トライアルから切り替え","Author","1"` + "\r\n" + `"test inc.","${lastMonthYYYYMM}","有効ライセンス数","","トライアルから切り替え","Typist","2"` + "\r\n" + `"test inc.","${lastMonthYYYYMM}","有効ライセンス数","","トライアルから切り替え","None","1"` + "\r\n" + `"test inc.","${lastMonthYYYYMM}","有効ライセンス数","","カードから切り替え","Author","1"` + "\r\n" + `"test inc.","${lastMonthYYYYMM}","有効ライセンス数","","カードから切り替え","Typist","2"` + "\r\n" + `"test inc.","${lastMonthYYYYMM}","有効ライセンス数","","カードから切り替え","None","3"` + "\r\n" + `"1","${lastMonthYYYYMM}","有効ライセンス数","所有ライセンス数","Trial","","9"` + "\r\n" + `"1","${lastMonthYYYYMM}","有効ライセンス数","所有ライセンス数","Standard","","9"` + "\r\n" + `"1","${lastMonthYYYYMM}","有効ライセンス数","所有ライセンス数","Card","","7"` + "\r\n" + `"1","${lastMonthYYYYMM}","有効ライセンス数","使用中ライセンス数","Trial","Author","1"` + "\r\n" + `"1","${lastMonthYYYYMM}","有効ライセンス数","使用中ライセンス数","Trial","Typist","2"` + "\r\n" + `"1","${lastMonthYYYYMM}","有効ライセンス数","使用中ライセンス数","Trial","None","3"` + "\r\n" + `"1","${lastMonthYYYYMM}","有効ライセンス数","使用中ライセンス数","Standard","Author","4"` + "\r\n" + `"1","${lastMonthYYYYMM}","有効ライセンス数","使用中ライセンス数","Standard","Typist","1"` + "\r\n" + `"1","${lastMonthYYYYMM}","有効ライセンス数","使用中ライセンス数","Standard","None","2"` + "\r\n" + `"1","${lastMonthYYYYMM}","有効ライセンス数","使用中ライセンス数","Card","Author","2"` + "\r\n" + `"1","${lastMonthYYYYMM}","有効ライセンス数","使用中ライセンス数","Card","Typist","3"` + "\r\n" + `"1","${lastMonthYYYYMM}","有効ライセンス数","使用中ライセンス数","Card","None","1"` + "\r\n" + `"1","${lastMonthYYYYMM}","新規発行ライセンス数","","Trial","","3"` + "\r\n" + `"1","${lastMonthYYYYMM}","新規発行ライセンス数","","Standard","","2"` + "\r\n" + `"1","${lastMonthYYYYMM}","新規発行ライセンス数","","Card","","1"` + "\r\n" + `"1","${lastMonthYYYYMM}","失効ライセンス数","","Trial","Author","5"` + "\r\n" + `"1","${lastMonthYYYYMM}","失効ライセンス数","","Trial","Typist","3"` + "\r\n" + `"1","${lastMonthYYYYMM}","失効ライセンス数","","Trial","None","2"` + "\r\n" + `"1","${lastMonthYYYYMM}","失効ライセンス数","","Trial","Unallocated","1"` + "\r\n" + `"1","${lastMonthYYYYMM}","失効ライセンス数","","Standard","Author","2"` + "\r\n" + `"1","${lastMonthYYYYMM}","失効ライセンス数","","Standard","Typist","1"` + "\r\n" + `"1","${lastMonthYYYYMM}","失効ライセンス数","","Standard","None","2"` + "\r\n" + `"1","${lastMonthYYYYMM}","失効ライセンス数","","Standard","Unallocated","2"` + "\r\n" + `"1","${lastMonthYYYYMM}","失効ライセンス数","","Card","Author","1"` + "\r\n" + `"1","${lastMonthYYYYMM}","失効ライセンス数","","Card","Typist","2"` + "\r\n" + `"1","${lastMonthYYYYMM}","失効ライセンス数","","Card","None","3"` + "\r\n" + `"1","${lastMonthYYYYMM}","失効ライセンス数","","Card","Unallocated","5"` + "\r\n" + `"1","${lastMonthYYYYMM}","有効ライセンス数","","トライアルから切り替え","Author","1"` + "\r\n" + `"1","${lastMonthYYYYMM}","有効ライセンス数","","トライアルから切り替え","Typist","2"` + "\r\n" + `"1","${lastMonthYYYYMM}","有効ライセンス数","","トライアルから切り替え","None","1"` + "\r\n" + `"1","${lastMonthYYYYMM}","有効ライセンス数","","カードから切り替え","Author","1"` + "\r\n" + `"1","${lastMonthYYYYMM}","有効ライセンス数","","カードから切り替え","Typist","2"` + "\r\n" + `"1","${lastMonthYYYYMM}","有効ライセンス数","","カードから切り替え","None","3"` + "\r\n" ); }); it("outputDataの確認(Mock)", async () => { const blobService = new BlobstorageService(); if (!source) fail(); const context = new InvocationContext(); const currentDate = new DateWithZeroTime(); // 現在の日付を取得 const nowDate = new Date(); // 先月の日付を取得 const lastMonth = new Date(nowDate); lastMonth.setMonth(nowDate.getMonth() - 1); const lastMonthYYYYMM = `${lastMonth.getFullYear()}${( lastMonth.getMonth() + 1 ) .toString() .padStart(2, "0")}`; // 先々月の日付を取得 const last2Month = new Date(nowDate); last2Month.setMonth(nowDate.getMonth() - 2); const last2MonthYYYYMM = `${last2Month.getFullYear()}${( last2Month.getMonth() + 1 ) .toString() .padStart(2, "0")}`; // tier4とtier5のアカウント+管理者を作る const { account: account4, admin: admin4 } = await makeTestAccount( source, { tier: 4 }, { external_id: "external_id_tier4admin" } ); const { account: account5_1, admin: admin5_1_1 } = await makeTestAccount( source, { tier: 5, parent_account_id: account4.id, }, { external_id: "external_id_tier5admin1", role: "author", } ); // 所有ライセンス // usedTrialLicensesAuthorCount 1件 await createLicense( source, 1, null, account5_1.id, "TRIAL", LICENSE_ALLOCATED_STATUS.ALLOCATED, admin5_1_1.id, null, null, null, last2Month ); const result = await getBaseData(context, lastMonthYYYYMM, source); const result_D = await getBaseDataFromDeletedAccounts( context, lastMonthYYYYMM, source ); const transferDataResult = await transferData( context, result, result_D, lastMonthYYYYMM ); const mockUploadFileAnalysisLicensesCSV = jest.fn().mockReturnValue(true); const mockCreateContainerAnalysis = jest.fn().mockReturnValue(true); blobService.uploadFileAnalysisLicensesCSV = mockUploadFileAnalysisLicensesCSV; blobService.createContainerAnalysis = mockCreateContainerAnalysis; const resultOutputData = await outputAnalysisLicensesData( context, blobService, transferDataResult ); expect(resultOutputData).toEqual(true); }); });