Merged PR 354: テスト用関数を作成する(Sprint16)
## 概要 [Task2383: テスト用関数を作成する(Sprint16)](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/2383) - WIPレビューで指摘された関数名等を修正 - 汎用関数で問題があった部分を修正 - データ構築ミスしていた箇所を修正 - DB的にnullableな所をテスト用関数でも省略できるよう修正 - 各種Account、User作成関数を汎用関数に置き換え ## レビューポイント - 情報共有 ## 動作確認状況 - npm run test 成功
This commit is contained in:
parent
c4848eb007
commit
89751396bf
363
dictation_server/src/common/test/utility.ts
Normal file
363
dictation_server/src/common/test/utility.ts
Normal file
@ -0,0 +1,363 @@
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { DataSource } from 'typeorm';
|
||||
import { User } from '../../repositories/users/entity/user.entity';
|
||||
import { Account } from '../../repositories/accounts/entity/account.entity';
|
||||
import { ADMIN_ROLES, USER_ROLES } from '../../constants';
|
||||
|
||||
type InitialTestDBState = {
|
||||
tier1Accounts: { account: Account; users: User[] }[];
|
||||
tier2Accounts: { account: Account; users: User[] }[];
|
||||
tier3Accounts: { account: Account; users: User[] }[];
|
||||
tier4Accounts: { account: Account; users: User[] }[];
|
||||
tier5Accounts: { account: Account; users: User[] }[];
|
||||
};
|
||||
|
||||
// 上書きされたら困る項目を除外したAccount型
|
||||
type OverrideAccount = Omit<
|
||||
Account,
|
||||
'id' | 'primary_admin_user_id' | 'secondary_admin_user_id' | 'user'
|
||||
>;
|
||||
|
||||
// 上書きされたら困る項目を除外したUser型
|
||||
type OverrideUser = Omit<
|
||||
User,
|
||||
'id' | 'account' | 'license' | 'userGroupMembers'
|
||||
>;
|
||||
|
||||
type AccountDefault = { [K in keyof OverrideAccount]?: OverrideAccount[K] };
|
||||
type UserDefault = { [K in keyof OverrideUser]?: OverrideUser[K] };
|
||||
|
||||
/**
|
||||
* テスト ユーティリティ: 1~4階層のアカウントとその管理者ユーザーを作成します
|
||||
* @param dataSource データソース
|
||||
* @returns 作成されたデータセット
|
||||
*/
|
||||
export const makeHierarchicalAccounts = async (
|
||||
datasource: DataSource,
|
||||
): Promise<InitialTestDBState> => {
|
||||
const state: InitialTestDBState = {
|
||||
tier1Accounts: [],
|
||||
tier2Accounts: [],
|
||||
tier3Accounts: [],
|
||||
tier4Accounts: [],
|
||||
tier5Accounts: [],
|
||||
};
|
||||
|
||||
// 第1階層を作成
|
||||
{
|
||||
const { account, admin } = await makeTestAccount(datasource, {
|
||||
tier: 1,
|
||||
company_name: 'OMDS',
|
||||
});
|
||||
|
||||
state.tier1Accounts.push({
|
||||
account: account,
|
||||
users: [admin],
|
||||
});
|
||||
}
|
||||
// 第2階層を作成
|
||||
{
|
||||
const { account: tier1 } = state.tier1Accounts.slice().shift();
|
||||
{
|
||||
const { account, admin } = await makeTestAccount(datasource, {
|
||||
tier: 2,
|
||||
parent_account_id: tier1.id,
|
||||
company_name: 'OMDS_US',
|
||||
});
|
||||
state.tier2Accounts.push({
|
||||
account: account,
|
||||
users: [admin],
|
||||
});
|
||||
}
|
||||
{
|
||||
const { account, admin } = await makeTestAccount(datasource, {
|
||||
tier: 2,
|
||||
parent_account_id: tier1.id,
|
||||
company_name: 'OMDS_EU',
|
||||
});
|
||||
state.tier2Accounts.push({
|
||||
account: account,
|
||||
users: [admin],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 第3階層を作成
|
||||
{
|
||||
for (const v of state.tier2Accounts) {
|
||||
{
|
||||
const { account, admin } = await makeTestAccount(datasource, {
|
||||
tier: 3,
|
||||
parent_account_id: v.account.id,
|
||||
company_name: `Agency_${v.account.id}_01`,
|
||||
});
|
||||
state.tier3Accounts.push({
|
||||
account: account,
|
||||
users: [admin],
|
||||
});
|
||||
}
|
||||
{
|
||||
const { account, admin } = await makeTestAccount(datasource, {
|
||||
tier: 3,
|
||||
parent_account_id: v.account.id,
|
||||
company_name: `Agency_${v.account.id}_02`,
|
||||
});
|
||||
state.tier3Accounts.push({
|
||||
account: account,
|
||||
users: [admin],
|
||||
});
|
||||
}
|
||||
}
|
||||
// 第4階層を作成
|
||||
for (const v of state.tier3Accounts) {
|
||||
{
|
||||
const { account, admin } = await makeTestAccount(datasource, {
|
||||
tier: 4,
|
||||
parent_account_id: v.account.id,
|
||||
company_name: `Distributor_${v.account.id}_01`,
|
||||
});
|
||||
state.tier4Accounts.push({
|
||||
account: account,
|
||||
users: [admin],
|
||||
});
|
||||
}
|
||||
{
|
||||
const { account, admin } = await makeTestAccount(datasource, {
|
||||
tier: 4,
|
||||
parent_account_id: v.account.id,
|
||||
company_name: `Distributor_${v.account.id}_02`,
|
||||
});
|
||||
state.tier4Accounts.push({
|
||||
account: account,
|
||||
users: [admin],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return state;
|
||||
};
|
||||
|
||||
/**
|
||||
* テスト ユーティリティ: 指定したプロパティを上書きしたアカウントとその管理者ユーザーを作成する
|
||||
* @param dataSource データソース
|
||||
* @param defaultUserValue Account型と同等かつoptionalなプロパティを持つ上書き箇所指定用オブジェクト
|
||||
* @param defaultAdminUserValue User型と同等かつoptionalなプロパティを持つ上書き箇所指定用オブジェクト(account_id等の所属関係が破壊される上書きは無視する)
|
||||
* @returns 作成したアカウント
|
||||
*/
|
||||
export const makeTestAccount = async (
|
||||
datasource: DataSource,
|
||||
defaultAccountValue?: AccountDefault,
|
||||
defaultAdminUserValue?: UserDefault,
|
||||
): Promise<{ account: Account; admin: User }> => {
|
||||
let accountId: number;
|
||||
let userId: number;
|
||||
{
|
||||
const d = defaultAccountValue;
|
||||
const { identifiers } = await datasource.getRepository(Account).insert({
|
||||
tier: d?.tier ?? 1,
|
||||
parent_account_id: d?.parent_account_id ?? undefined,
|
||||
country: d?.country ?? 'US',
|
||||
delegation_permission: d?.delegation_permission ?? false,
|
||||
locked: d?.locked ?? false,
|
||||
company_name: d?.company_name ?? 'test inc.',
|
||||
verified: d?.verified ?? true,
|
||||
deleted_at: d?.deleted_at ?? '',
|
||||
created_by: d?.created_by ?? 'test_runner',
|
||||
created_at: d?.created_at ?? new Date(),
|
||||
updated_by: d?.updated_by ?? 'updater',
|
||||
updated_at: d?.updated_at ?? new Date(),
|
||||
});
|
||||
const result = identifiers.pop() as Account;
|
||||
accountId = result.id;
|
||||
}
|
||||
{
|
||||
const d = defaultAdminUserValue;
|
||||
const { identifiers } = await datasource.getRepository(User).insert({
|
||||
external_id: d?.external_id ?? uuidv4(),
|
||||
account_id: accountId,
|
||||
role: d?.role ?? 'admin none',
|
||||
author_id: d?.author_id ?? undefined,
|
||||
accepted_terms_version: d?.accepted_terms_version ?? '1.0',
|
||||
email_verified: d?.email_verified ?? true,
|
||||
auto_renew: d?.auto_renew ?? true,
|
||||
license_alert: d?.license_alert ?? true,
|
||||
notification: d?.notification ?? true,
|
||||
encryption: d?.encryption ?? true,
|
||||
encryption_password: d?.encryption_password ?? 'password',
|
||||
prompt: d?.prompt ?? true,
|
||||
deleted_at: d?.deleted_at ?? '',
|
||||
created_by: d?.created_by ?? 'test_runner',
|
||||
created_at: d?.created_at ?? new Date(),
|
||||
updated_by: d?.updated_by ?? 'updater',
|
||||
updated_at: d?.updated_at ?? new Date(),
|
||||
});
|
||||
|
||||
const result = identifiers.pop() as User;
|
||||
userId = result.id;
|
||||
}
|
||||
|
||||
// Accountの管理者を設定する
|
||||
await datasource.getRepository(Account).update(
|
||||
{ id: accountId },
|
||||
{
|
||||
primary_admin_user_id: userId,
|
||||
},
|
||||
);
|
||||
|
||||
const account = await datasource.getRepository(Account).findOne({
|
||||
where: {
|
||||
id: accountId,
|
||||
},
|
||||
});
|
||||
|
||||
const admin = await datasource.getRepository(User).findOne({
|
||||
where: {
|
||||
id: userId,
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
account: account,
|
||||
admin: admin,
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* テスト ユーティリティ: 指定したプロパティを上書きした管理者ユーザーの存在しないアカウントを作成する
|
||||
* @param dataSource データソース
|
||||
* @param defaultUserValue Account型と同等かつoptionalなプロパティを持つ上書き箇所指定用オブジェクト
|
||||
* @returns 作成したアカウント
|
||||
*/
|
||||
export const makeTestSimpleAccount = async (
|
||||
datasource: DataSource,
|
||||
defaultAccountValue?: AccountDefault,
|
||||
): Promise<Account> => {
|
||||
const d = defaultAccountValue;
|
||||
const { identifiers } = await datasource.getRepository(Account).insert({
|
||||
tier: d?.tier ?? 1,
|
||||
parent_account_id: d?.parent_account_id ?? undefined,
|
||||
country: d?.country ?? 'US',
|
||||
delegation_permission: d?.delegation_permission ?? false,
|
||||
locked: d?.locked ?? false,
|
||||
company_name: d?.company_name ?? 'test inc.',
|
||||
verified: d?.verified ?? true,
|
||||
deleted_at: d?.deleted_at ?? '',
|
||||
created_by: d?.created_by ?? 'test_runner',
|
||||
created_at: d?.created_at ?? new Date(),
|
||||
updated_by: d?.updated_by ?? 'updater',
|
||||
updated_at: d?.updated_at ?? new Date(),
|
||||
});
|
||||
const result = identifiers.pop() as Account;
|
||||
|
||||
const account = await datasource.getRepository(Account).findOne({
|
||||
where: {
|
||||
id: result.id,
|
||||
},
|
||||
});
|
||||
|
||||
return account;
|
||||
};
|
||||
|
||||
/**
|
||||
* テスト ユーティリティ: 指定したプロパティを上書きしたユーザーを作成する
|
||||
* @param dataSource データソース
|
||||
* @param defaultUserValue User型と同等かつoptionalなプロパティを持つ上書き箇所指定用オブジェクト
|
||||
* @returns 作成したユーザー
|
||||
*/
|
||||
export const makeTestUser = async (
|
||||
datasource: DataSource,
|
||||
defaultUserValue?: UserDefault,
|
||||
): Promise<User> => {
|
||||
const d = defaultUserValue;
|
||||
const { identifiers } = await datasource.getRepository(User).insert({
|
||||
account_id: d?.account_id ?? -1,
|
||||
external_id: d?.external_id ?? uuidv4(),
|
||||
role: d?.role ?? `${ADMIN_ROLES.STANDARD} ${USER_ROLES.NONE}`,
|
||||
author_id: d?.author_id,
|
||||
accepted_terms_version: d?.accepted_terms_version,
|
||||
email_verified: d?.email_verified ?? true,
|
||||
auto_renew: d?.auto_renew ?? true,
|
||||
license_alert: d?.license_alert ?? true,
|
||||
notification: d?.notification ?? true,
|
||||
encryption: d?.encryption ?? true,
|
||||
encryption_password: d?.encryption_password,
|
||||
prompt: d?.prompt ?? true,
|
||||
created_by: d?.created_by ?? 'test_runner',
|
||||
created_at: d?.created_at ?? new Date(),
|
||||
updated_by: d?.updated_by ?? 'updater',
|
||||
updated_at: d?.updated_at ?? new Date(),
|
||||
});
|
||||
const result = identifiers.pop() as User;
|
||||
|
||||
return await datasource.getRepository(User).findOne({
|
||||
where: {
|
||||
id: result.id,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* テスト ユーティリティ: 指定IDのアカウントを取得する
|
||||
* @param dataSource データソース
|
||||
* @param id アカウントID
|
||||
* @returns 該当アカウント
|
||||
*/
|
||||
export const getAccount = async (dataSource: DataSource, id: number) => {
|
||||
return await dataSource.getRepository(Account).findOne({
|
||||
where: { id: id },
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* テスト ユーティリティ: すべてのアカウントを取得する
|
||||
* @param dataSource データソース
|
||||
* @returns 該当アカウント一覧
|
||||
*/
|
||||
export const getAccounts = async (
|
||||
dataSource: DataSource,
|
||||
): Promise<Account[]> => {
|
||||
return await dataSource.getRepository(Account).find();
|
||||
};
|
||||
|
||||
/**
|
||||
* テスト ユーティリティ: 指定ExternalIdのユーザーを取得する
|
||||
* @param dataSource データソース
|
||||
* @param externalId 外部ID
|
||||
* @returns 該当ユーザー
|
||||
*/
|
||||
export const getUserFromExternalId = async (
|
||||
dataSource: DataSource,
|
||||
externalId: string,
|
||||
) => {
|
||||
return await dataSource.getRepository(User).findOne({
|
||||
where: { external_id: externalId },
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* テスト ユーティリティ: 指定Idのユーザーを取得する
|
||||
* @param dataSource データソース
|
||||
* @param externalId 外部ID
|
||||
* @returns 該当ユーザー
|
||||
*/
|
||||
export const getUser = async (
|
||||
datasource: DataSource,
|
||||
id: number,
|
||||
): Promise<User> => {
|
||||
const user = await datasource.getRepository(User).findOne({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
});
|
||||
return user;
|
||||
};
|
||||
|
||||
/**
|
||||
* テスト ユーティリティ: すべてのユーザーを取得する
|
||||
* @param dataSource データソース
|
||||
* @returns 該当ユーザー一覧
|
||||
*/
|
||||
export const getUsers = async (dataSource: DataSource): Promise<User[]> => {
|
||||
return await dataSource.getRepository(User).find();
|
||||
};
|
||||
@ -12,23 +12,23 @@ import {
|
||||
} from './test/accounts.service.mock';
|
||||
import { makeDefaultConfigValue } from '../users/test/users.service.mock';
|
||||
import {
|
||||
createAccount,
|
||||
createLicense,
|
||||
createLicenseOrder,
|
||||
createUser,
|
||||
createLicenseSetExpiryDateAndStatus,
|
||||
getAccount,
|
||||
getUserFromExternalID,
|
||||
getAccounts,
|
||||
getUsers,
|
||||
getSortCriteria,
|
||||
createAccountAndAdminUser,
|
||||
createAccountAndAdminUserForTier5,
|
||||
getTypistGroup,
|
||||
getTypistGroupMember,
|
||||
} from './test/utility';
|
||||
import { DataSource } from 'typeorm';
|
||||
import { makeTestingModule } from '../../common/test/modules';
|
||||
import {
|
||||
makeTestAccount,
|
||||
getAccount,
|
||||
getAccounts,
|
||||
getUserFromExternalId,
|
||||
getUsers,
|
||||
makeTestUser,
|
||||
} from '../../common/test/utility';
|
||||
import { AccountsService } from './accounts.service';
|
||||
import { Context, makeContext } from '../../common/log';
|
||||
import { TIERS } from '../../constants';
|
||||
@ -113,7 +113,7 @@ describe('createAccount', () => {
|
||||
|
||||
// DB内が想定通りになっているか確認
|
||||
const account = await getAccount(source, accountId);
|
||||
const user = await getUserFromExternalID(source, externalUserId);
|
||||
const user = await getUserFromExternalId(source, externalUserId);
|
||||
expect(account.company_name).toBe(companyName);
|
||||
expect(account.country).toBe(country);
|
||||
expect(account.parent_account_id).toBe(dealerAccountId);
|
||||
@ -717,8 +717,11 @@ describe('createPartnerAccount', () => {
|
||||
const adminExternalId = 'ADMIN0001';
|
||||
|
||||
// 第一階層のアカウントを作成
|
||||
const { accountId: parentAccountId, tier } =
|
||||
await createAccountAndAdminUser(source, adminExternalId);
|
||||
const { account: parent } = await makeTestAccount(
|
||||
source,
|
||||
{ tier: 1 },
|
||||
{ external_id: adminExternalId },
|
||||
);
|
||||
|
||||
const context = makeContext('uuid');
|
||||
const companyName = 'test_company_name';
|
||||
@ -761,7 +764,7 @@ describe('createPartnerAccount', () => {
|
||||
email,
|
||||
adminName,
|
||||
adminExternalId,
|
||||
tier,
|
||||
parent.tier,
|
||||
);
|
||||
|
||||
// DB上に作成されたデータが想定通りであるか確認
|
||||
@ -769,14 +772,14 @@ describe('createPartnerAccount', () => {
|
||||
const accounts = await getAccounts(source);
|
||||
expect(accounts.length).toBe(2);
|
||||
|
||||
const createdUser = await getUserFromExternalID(
|
||||
const createdUser = await getUserFromExternalId(
|
||||
source,
|
||||
pertnerExternalId,
|
||||
);
|
||||
const createdAccount = await getAccount(source, accountId);
|
||||
expect(createdAccount.company_name).toBe(companyName);
|
||||
expect(createdAccount.country).toBe(country);
|
||||
expect(createdAccount.parent_account_id).toBe(parentAccountId);
|
||||
expect(createdAccount.parent_account_id).toBe(parent.id);
|
||||
expect(createdAccount.tier).toBe(2);
|
||||
expect(createdAccount.primary_admin_user_id).toBe(createdUser.id);
|
||||
expect(createdAccount.secondary_admin_user_id).toBe(null);
|
||||
@ -789,7 +792,11 @@ describe('createPartnerAccount', () => {
|
||||
const adminExternalId = 'ADMIN0001';
|
||||
|
||||
// 第一階層のアカウントを作成
|
||||
const { tier } = await createAccountAndAdminUser(source, adminExternalId);
|
||||
const { account: parent } = await makeTestAccount(
|
||||
source,
|
||||
{ tier: 1 },
|
||||
{ external_id: adminExternalId },
|
||||
);
|
||||
|
||||
const context = makeContext('uuid');
|
||||
const companyName = 'test_company_name';
|
||||
@ -834,7 +841,7 @@ describe('createPartnerAccount', () => {
|
||||
email,
|
||||
adminName,
|
||||
adminExternalId,
|
||||
tier,
|
||||
parent.tier,
|
||||
);
|
||||
} catch (e) {
|
||||
if (e instanceof HttpException) {
|
||||
@ -861,7 +868,11 @@ describe('createPartnerAccount', () => {
|
||||
const adminExternalId = 'ADMIN0001';
|
||||
|
||||
// 第一階層のアカウントを作成
|
||||
const { tier } = await createAccountAndAdminUser(source, adminExternalId);
|
||||
const { account: parent } = await makeTestAccount(
|
||||
source,
|
||||
{ tier: 1 },
|
||||
{ external_id: adminExternalId },
|
||||
);
|
||||
|
||||
const context = makeContext('uuid');
|
||||
const companyName = 'test_company_name';
|
||||
@ -913,7 +924,7 @@ describe('createPartnerAccount', () => {
|
||||
email,
|
||||
adminName,
|
||||
adminExternalId,
|
||||
tier,
|
||||
parent.tier,
|
||||
);
|
||||
} catch (e) {
|
||||
if (e instanceof HttpException) {
|
||||
@ -944,7 +955,11 @@ describe('createPartnerAccount', () => {
|
||||
const adminExternalId = 'ADMIN0001';
|
||||
|
||||
// 第一階層のアカウントを作成
|
||||
const { tier } = await createAccountAndAdminUser(source, adminExternalId);
|
||||
const { account: parent } = await makeTestAccount(
|
||||
source,
|
||||
{ tier: 1 },
|
||||
{ external_id: adminExternalId },
|
||||
);
|
||||
|
||||
const context = makeContext('uuid');
|
||||
const companyName = 'test_company_name';
|
||||
@ -996,7 +1011,7 @@ describe('createPartnerAccount', () => {
|
||||
email,
|
||||
adminName,
|
||||
adminExternalId,
|
||||
tier,
|
||||
parent.tier,
|
||||
);
|
||||
} catch (e) {
|
||||
if (e instanceof HttpException) {
|
||||
@ -1027,7 +1042,12 @@ describe('createPartnerAccount', () => {
|
||||
|
||||
const parentExternalId = 'parent_external_id';
|
||||
|
||||
await createAccountAndAdminUser(source, parentExternalId);
|
||||
// 第一階層のアカウントを作成
|
||||
const { account: parent } = await makeTestAccount(
|
||||
source,
|
||||
{ tier: 1 },
|
||||
{ external_id: parentExternalId },
|
||||
);
|
||||
|
||||
const context = makeContext(parentExternalId);
|
||||
const partnerExternalId = 'partner_external_id';
|
||||
@ -1086,7 +1106,7 @@ describe('createPartnerAccount', () => {
|
||||
{
|
||||
const accounts = await getAccounts(source);
|
||||
expect(accounts.length).toBe(1);
|
||||
expect(accounts[0].tier).toBe(1);
|
||||
expect(accounts[0].tier).toBe(parent.tier);
|
||||
const users = await getUsers(source);
|
||||
expect(users.length).toBe(1);
|
||||
expect(users[0].external_id).toBe(parentExternalId);
|
||||
@ -1102,7 +1122,12 @@ describe('createPartnerAccount', () => {
|
||||
|
||||
const parentExternalId = 'parent_external_id';
|
||||
|
||||
await createAccountAndAdminUser(source, parentExternalId);
|
||||
// 第一階層のアカウントを作成
|
||||
const { account: parent } = await makeTestAccount(
|
||||
source,
|
||||
{ tier: 1 },
|
||||
{ external_id: parentExternalId },
|
||||
);
|
||||
|
||||
const context = makeContext(parentExternalId);
|
||||
const partnerExternalId = 'partner_external_id';
|
||||
@ -1167,8 +1192,8 @@ describe('createPartnerAccount', () => {
|
||||
// リカバリ処理が失敗した場合、DB上のデータは削除されない
|
||||
const accounts = await getAccounts(source);
|
||||
expect(accounts.length).toBe(2);
|
||||
expect(accounts[0].tier).toBe(1);
|
||||
expect(accounts[1].tier).toBe(2);
|
||||
expect(accounts[0].tier).toBe(parent.tier);
|
||||
expect(accounts[1].tier).toBe(parent.tier + 1);
|
||||
const users = await getUsers(source);
|
||||
expect(users.length).toBe(2);
|
||||
expect(users[0].external_id).toBe(parentExternalId);
|
||||
@ -1187,7 +1212,12 @@ describe('createPartnerAccount', () => {
|
||||
|
||||
const parentExternalId = 'parent_external_id';
|
||||
|
||||
await createAccountAndAdminUser(source, parentExternalId);
|
||||
// 第一階層のアカウントを作成
|
||||
const { account: parent } = await makeTestAccount(
|
||||
source,
|
||||
{ tier: 1 },
|
||||
{ external_id: parentExternalId },
|
||||
);
|
||||
|
||||
const context = makeContext(parentExternalId);
|
||||
const partnerExternalId = 'partner_external_id';
|
||||
@ -1248,7 +1278,7 @@ describe('createPartnerAccount', () => {
|
||||
// DB上に作成されたデータが想定通りであるか確認
|
||||
const accounts = await getAccounts(source);
|
||||
expect(accounts.length).toBe(1);
|
||||
expect(accounts[0].tier).toBe(1);
|
||||
expect(accounts[0].tier).toBe(parent.tier);
|
||||
const users = await getUsers(source);
|
||||
expect(users.length).toBe(1);
|
||||
expect(users[0].external_id).toBe(parentExternalId);
|
||||
@ -1272,7 +1302,12 @@ describe('createPartnerAccount', () => {
|
||||
|
||||
const parentExternalId = 'parent_external_id';
|
||||
|
||||
await createAccountAndAdminUser(source, parentExternalId);
|
||||
// 第一階層のアカウントを作成
|
||||
const { account: parent } = await makeTestAccount(
|
||||
source,
|
||||
{ tier: 1 },
|
||||
{ external_id: parentExternalId },
|
||||
);
|
||||
|
||||
const context = makeContext(parentExternalId);
|
||||
const partnerExternalId = 'partner_external_id';
|
||||
@ -1338,8 +1373,8 @@ describe('createPartnerAccount', () => {
|
||||
// リカバリ処理が失敗したため、DB上のデータは削除されていない
|
||||
const accounts = await getAccounts(source);
|
||||
expect(accounts.length).toBe(2);
|
||||
expect(accounts[0].tier).toBe(1);
|
||||
expect(accounts[1].tier).toBe(2);
|
||||
expect(accounts[0].tier).toBe(parent.tier);
|
||||
expect(accounts[1].tier).toBe(parent.tier + 1);
|
||||
const users = await getUsers(source);
|
||||
expect(users.length).toBe(2);
|
||||
expect(users[0].external_id).toBe(parentExternalId);
|
||||
@ -1361,7 +1396,11 @@ describe('createPartnerAccount', () => {
|
||||
const adminExternalId = 'ADMIN0001';
|
||||
|
||||
// 第一階層のアカウントを作成
|
||||
const { tier } = await createAccountAndAdminUser(source, adminExternalId);
|
||||
const { account: parent } = await makeTestAccount(
|
||||
source,
|
||||
{ tier: 1 },
|
||||
{ external_id: adminExternalId },
|
||||
);
|
||||
|
||||
const context = makeContext('uuid');
|
||||
const companyName = 'test_company_name';
|
||||
@ -1407,7 +1446,7 @@ describe('createPartnerAccount', () => {
|
||||
email,
|
||||
adminName,
|
||||
adminExternalId,
|
||||
tier,
|
||||
parent.tier,
|
||||
);
|
||||
} catch (e) {
|
||||
if (e instanceof HttpException) {
|
||||
@ -1712,38 +1751,45 @@ describe('getPartnerAccount', () => {
|
||||
const module = await makeTestingModule(source);
|
||||
|
||||
// 親アカウントと子アカウント2つ作成
|
||||
const { accountId: parentAccountId } = await createAccount(
|
||||
source,
|
||||
0,
|
||||
1,
|
||||
'PARENTCORP',
|
||||
);
|
||||
const { accountId: childAccountId1 } = await createAccount(
|
||||
source,
|
||||
parentAccountId,
|
||||
2,
|
||||
'CHILDCORP1',
|
||||
);
|
||||
const { accountId: childAccountId2 } = await createAccount(
|
||||
source,
|
||||
parentAccountId,
|
||||
2,
|
||||
'CHILDCORP2',
|
||||
);
|
||||
const { id: parentAccountId } = (
|
||||
await makeTestAccount(source, {
|
||||
parent_account_id: 0,
|
||||
tier: 1,
|
||||
company_name: 'PARENTCORP',
|
||||
})
|
||||
).account;
|
||||
|
||||
const { id: childAccountId1 } = (
|
||||
await makeTestAccount(source, {
|
||||
parent_account_id: parentAccountId,
|
||||
tier: 2,
|
||||
company_name: 'CHILDCORP1',
|
||||
})
|
||||
).account;
|
||||
|
||||
const { id: childAccountId2 } = (
|
||||
await makeTestAccount(source, {
|
||||
parent_account_id: parentAccountId,
|
||||
tier: 2,
|
||||
company_name: 'CHILDCORP2',
|
||||
})
|
||||
).account;
|
||||
|
||||
// 第二にリクエストを投げる用の第三を作成
|
||||
const { accountId: childAccountId3 } = await createAccount(
|
||||
source,
|
||||
childAccountId1,
|
||||
3,
|
||||
'CHILDCORP3',
|
||||
);
|
||||
const { accountId: childAccountId4 } = await createAccount(
|
||||
source,
|
||||
childAccountId2,
|
||||
3,
|
||||
'CHILDCORP4',
|
||||
);
|
||||
const { id: childAccountId3 } = (
|
||||
await makeTestAccount(source, {
|
||||
parent_account_id: childAccountId1,
|
||||
tier: 3,
|
||||
company_name: 'CHILDCORP3',
|
||||
})
|
||||
).account;
|
||||
const { id: childAccountId4 } = (
|
||||
await makeTestAccount(source, {
|
||||
parent_account_id: childAccountId2,
|
||||
tier: 3,
|
||||
company_name: 'CHILDCORP4',
|
||||
})
|
||||
).account;
|
||||
|
||||
// 所有ライセンスを追加(親:3、子1:1、子2:2)
|
||||
await createLicense(source, parentAccountId);
|
||||
@ -1819,30 +1865,34 @@ describe('getPartnerAccount', () => {
|
||||
const module = await makeTestingModule(source);
|
||||
|
||||
// 親アカウントと子アカウント2つ作成
|
||||
const { accountId: parentAccountId } = await createAccount(
|
||||
source,
|
||||
0,
|
||||
4,
|
||||
'PARENTCORP',
|
||||
);
|
||||
const { accountId: childAccountId1 } = await createAccount(
|
||||
source,
|
||||
parentAccountId,
|
||||
5,
|
||||
'CHILDCORP1',
|
||||
);
|
||||
const { accountId: childAccountId2 } = await createAccount(
|
||||
source,
|
||||
parentAccountId,
|
||||
5,
|
||||
'CHILDCORP2',
|
||||
);
|
||||
const { accountId: childAccountId3 } = await createAccount(
|
||||
source,
|
||||
parentAccountId,
|
||||
5,
|
||||
'CHILDCORP3',
|
||||
);
|
||||
const { id: parentAccountId } = (
|
||||
await makeTestAccount(source, {
|
||||
parent_account_id: 0,
|
||||
tier: 4,
|
||||
company_name: 'PARENTCORP',
|
||||
})
|
||||
).account;
|
||||
const { id: childAccountId1 } = (
|
||||
await makeTestAccount(source, {
|
||||
parent_account_id: parentAccountId,
|
||||
tier: 5,
|
||||
company_name: 'CHILDCORP1',
|
||||
})
|
||||
).account;
|
||||
const { id: childAccountId2 } = (
|
||||
await makeTestAccount(source, {
|
||||
parent_account_id: parentAccountId,
|
||||
tier: 5,
|
||||
company_name: 'CHILDCORP2',
|
||||
})
|
||||
).account;
|
||||
const { id: childAccountId3 } = (
|
||||
await makeTestAccount(source, {
|
||||
parent_account_id: parentAccountId,
|
||||
tier: 5,
|
||||
company_name: 'CHILDCORP3',
|
||||
})
|
||||
).account;
|
||||
|
||||
// 有効期限が14日後のライセンスを追加(5ライセンス)
|
||||
const expiryDate = new Date();
|
||||
@ -2062,25 +2112,26 @@ describe('issueLicense', () => {
|
||||
const service = module.get<AccountsService>(AccountsService);
|
||||
const now = new Date();
|
||||
// 親と子アカウントを作成する
|
||||
const { accountId: parentAccountId } = await createAccount(
|
||||
source,
|
||||
0,
|
||||
2,
|
||||
'PARENTCORP',
|
||||
);
|
||||
const { accountId: childAccountId } = await createAccount(
|
||||
source,
|
||||
parentAccountId,
|
||||
3,
|
||||
'CHILDCORP1',
|
||||
);
|
||||
const { id: parentAccountId } = (
|
||||
await makeTestAccount(source, {
|
||||
parent_account_id: 0,
|
||||
tier: 2,
|
||||
company_name: 'PARENTCORP',
|
||||
})
|
||||
).account;
|
||||
const { id: childAccountId } = (
|
||||
await makeTestAccount(source, {
|
||||
parent_account_id: parentAccountId,
|
||||
tier: 3,
|
||||
company_name: 'CHILDCORP1',
|
||||
})
|
||||
).account;
|
||||
// 親と子のユーザーを作成する
|
||||
const { externalId } = await createUser(
|
||||
source,
|
||||
parentAccountId,
|
||||
'userId-parent',
|
||||
'admin',
|
||||
);
|
||||
const { external_id: externalId } = await makeTestUser(source, {
|
||||
account_id: parentAccountId,
|
||||
external_id: 'userId-parent',
|
||||
role: 'admin',
|
||||
});
|
||||
|
||||
// 親のライセンスを作成する(3個)
|
||||
await createLicense(source, parentAccountId);
|
||||
@ -2121,26 +2172,26 @@ describe('issueLicense', () => {
|
||||
const service = module.get<AccountsService>(AccountsService);
|
||||
const now = new Date();
|
||||
// 親と子アカウントを作成する
|
||||
const { accountId: parentAccountId } = await createAccount(
|
||||
source,
|
||||
0,
|
||||
2,
|
||||
'PARENTCORP',
|
||||
);
|
||||
const { accountId: childAccountId } = await createAccount(
|
||||
source,
|
||||
parentAccountId,
|
||||
3,
|
||||
'CHILDCORP1',
|
||||
);
|
||||
const { id: parentAccountId } = (
|
||||
await makeTestAccount(source, {
|
||||
parent_account_id: 0,
|
||||
tier: 2,
|
||||
company_name: 'PARENTCORP',
|
||||
})
|
||||
).account;
|
||||
const { id: childAccountId } = (
|
||||
await makeTestAccount(source, {
|
||||
parent_account_id: parentAccountId,
|
||||
tier: 3,
|
||||
company_name: 'CHILDCORP1',
|
||||
})
|
||||
).account;
|
||||
// 親と子のユーザーを作成する
|
||||
const { externalId } = await createUser(
|
||||
source,
|
||||
parentAccountId,
|
||||
'userId-parent',
|
||||
'admin',
|
||||
);
|
||||
|
||||
const { external_id: externalId } = await makeTestUser(source, {
|
||||
account_id: parentAccountId,
|
||||
external_id: 'userId-parent',
|
||||
role: 'admin',
|
||||
});
|
||||
// 親のライセンスを作成する(3個)
|
||||
await createLicense(source, parentAccountId);
|
||||
await createLicense(source, parentAccountId);
|
||||
@ -2178,25 +2229,26 @@ describe('issueLicense', () => {
|
||||
const service = module.get<AccountsService>(AccountsService);
|
||||
const now = new Date();
|
||||
// 親と子アカウントを作成する
|
||||
const { accountId: parentAccountId } = await createAccount(
|
||||
source,
|
||||
0,
|
||||
2,
|
||||
'PARENTCORP',
|
||||
);
|
||||
const { accountId: childAccountId } = await createAccount(
|
||||
source,
|
||||
parentAccountId,
|
||||
3,
|
||||
'CHILDCORP1',
|
||||
);
|
||||
const { id: parentAccountId } = (
|
||||
await makeTestAccount(source, {
|
||||
parent_account_id: 0,
|
||||
tier: 2,
|
||||
company_name: 'PARENTCORP',
|
||||
})
|
||||
).account;
|
||||
const { id: childAccountId } = (
|
||||
await makeTestAccount(source, {
|
||||
parent_account_id: parentAccountId,
|
||||
tier: 3,
|
||||
company_name: 'CHILDCORP1',
|
||||
})
|
||||
).account;
|
||||
// 親と子のユーザーを作成する
|
||||
const { externalId } = await createUser(
|
||||
source,
|
||||
parentAccountId,
|
||||
'userId-parent',
|
||||
'admin',
|
||||
);
|
||||
const { external_id: externalId } = await makeTestUser(source, {
|
||||
account_id: parentAccountId,
|
||||
external_id: 'userId-parent',
|
||||
role: 'admin',
|
||||
});
|
||||
|
||||
// 親のライセンスを作成する(3個)
|
||||
await createLicense(source, parentAccountId);
|
||||
@ -2242,24 +2294,30 @@ describe('getDealers', () => {
|
||||
});
|
||||
it('Dealerを取得できる', async () => {
|
||||
const module = await makeTestingModule(source);
|
||||
const { accountId: accountId_1 } = await createAccount(
|
||||
source,
|
||||
1,
|
||||
TIERS.TIER4,
|
||||
'DEALER_1',
|
||||
);
|
||||
const { accountId: accountId_2 } = await createAccount(
|
||||
source,
|
||||
2,
|
||||
TIERS.TIER4,
|
||||
'DEALER_2',
|
||||
);
|
||||
const { accountId: accountId_3 } = await createAccount(
|
||||
source,
|
||||
3,
|
||||
TIERS.TIER4,
|
||||
'DEALER_3',
|
||||
);
|
||||
const { id: accountId_1 } = (
|
||||
await makeTestAccount(source, {
|
||||
parent_account_id: 1,
|
||||
tier: TIERS.TIER4,
|
||||
country: 'JP',
|
||||
company_name: 'DEALER_1',
|
||||
})
|
||||
).account;
|
||||
const { id: accountId_2 } = (
|
||||
await makeTestAccount(source, {
|
||||
parent_account_id: 2,
|
||||
tier: TIERS.TIER4,
|
||||
country: 'JP',
|
||||
company_name: 'DEALER_2',
|
||||
})
|
||||
).account;
|
||||
const { id: accountId_3 } = (
|
||||
await makeTestAccount(source, {
|
||||
parent_account_id: 3,
|
||||
tier: TIERS.TIER4,
|
||||
country: 'JP',
|
||||
company_name: 'DEALER_3',
|
||||
})
|
||||
).account;
|
||||
const service = module.get<AccountsService>(AccountsService);
|
||||
|
||||
expect(await service.getDealers()).toEqual({
|
||||
@ -2314,10 +2372,13 @@ describe('createTypistGroup', () => {
|
||||
const module = await makeTestingModule(source);
|
||||
const adminExternalId = 'admin-external-id';
|
||||
// 第五階層のアカウント作成
|
||||
const { accountId } = await createAccountAndAdminUserForTier5(
|
||||
source,
|
||||
adminExternalId,
|
||||
);
|
||||
const { id: accountId } = (
|
||||
await makeTestAccount(
|
||||
source,
|
||||
{ tier: 5 },
|
||||
{ external_id: adminExternalId },
|
||||
)
|
||||
).account;
|
||||
// 作成したアカウントにユーザーを3名追加する
|
||||
const typiptUserExternalIds = [
|
||||
'typist-user-external-id1',
|
||||
@ -2326,12 +2387,11 @@ describe('createTypistGroup', () => {
|
||||
];
|
||||
const userIds: number[] = [];
|
||||
for (const typiptUserExternalId of typiptUserExternalIds) {
|
||||
const { userId } = await createUser(
|
||||
source,
|
||||
accountId,
|
||||
typiptUserExternalId,
|
||||
'typist',
|
||||
);
|
||||
const { id: userId } = await makeTestUser(source, {
|
||||
account_id: accountId,
|
||||
external_id: typiptUserExternalId,
|
||||
role: 'typist',
|
||||
});
|
||||
userIds.push(userId);
|
||||
}
|
||||
//作成したデータを確認
|
||||
@ -2371,10 +2431,13 @@ describe('createTypistGroup', () => {
|
||||
const module = await makeTestingModule(source);
|
||||
const adminExternalId = 'admin-external-id';
|
||||
// 第五階層のアカウント作成
|
||||
const { accountId } = await createAccountAndAdminUserForTier5(
|
||||
source,
|
||||
adminExternalId,
|
||||
);
|
||||
const { id: accountId } = (
|
||||
await makeTestAccount(
|
||||
source,
|
||||
{ tier: 5 },
|
||||
{ external_id: adminExternalId },
|
||||
)
|
||||
).account;
|
||||
// 作成したアカウントにユーザーを3名追加する
|
||||
const typiptUserExternalIds = [
|
||||
'typist-user-external-id1',
|
||||
@ -2383,12 +2446,14 @@ describe('createTypistGroup', () => {
|
||||
];
|
||||
const userIds: number[] = [];
|
||||
for (const typiptUserExternalId of typiptUserExternalIds) {
|
||||
const { userId } = await createUser(
|
||||
source,
|
||||
accountId,
|
||||
typiptUserExternalId,
|
||||
typiptUserExternalId === 'typist-user-external-id3' ? 'none' : 'typist', //typist-user-external-id3のみRole:none
|
||||
);
|
||||
const { id: userId } = await makeTestUser(source, {
|
||||
account_id: accountId,
|
||||
external_id: typiptUserExternalId,
|
||||
role:
|
||||
typiptUserExternalId === 'typist-user-external-id3'
|
||||
? 'none'
|
||||
: 'typist', //typist-user-external-id3のみRole:none,
|
||||
});
|
||||
userIds.push(userId);
|
||||
}
|
||||
//作成したデータを確認
|
||||
@ -2419,10 +2484,13 @@ describe('createTypistGroup', () => {
|
||||
const module = await makeTestingModule(source);
|
||||
const adminExternalId = 'admin-external-id';
|
||||
// 第五階層のアカウント作成
|
||||
const { accountId } = await createAccountAndAdminUserForTier5(
|
||||
source,
|
||||
adminExternalId,
|
||||
);
|
||||
const { id: accountId } = (
|
||||
await makeTestAccount(
|
||||
source,
|
||||
{ tier: 5 },
|
||||
{ external_id: adminExternalId },
|
||||
)
|
||||
).account;
|
||||
// 作成したアカウントにユーザーを3名追加する
|
||||
const typiptUserExternalIds = [
|
||||
'typist-user-external-id1',
|
||||
@ -2431,12 +2499,11 @@ describe('createTypistGroup', () => {
|
||||
];
|
||||
const userIds: number[] = [];
|
||||
for (const typiptUserExternalId of typiptUserExternalIds) {
|
||||
const { userId } = await createUser(
|
||||
source,
|
||||
accountId,
|
||||
typiptUserExternalId,
|
||||
'typist',
|
||||
);
|
||||
const { id: userId } = await makeTestUser(source, {
|
||||
account_id: accountId,
|
||||
external_id: typiptUserExternalId,
|
||||
role: 'typist',
|
||||
});
|
||||
userIds.push(userId);
|
||||
}
|
||||
//作成したデータを確認
|
||||
@ -2466,10 +2533,13 @@ describe('createTypistGroup', () => {
|
||||
const module = await makeTestingModule(source);
|
||||
const adminExternalId = 'admin-external-id';
|
||||
// 第五階層のアカウント作成
|
||||
const { accountId } = await createAccountAndAdminUserForTier5(
|
||||
source,
|
||||
adminExternalId,
|
||||
);
|
||||
const { id: accountId } = (
|
||||
await makeTestAccount(
|
||||
source,
|
||||
{ tier: 5 },
|
||||
{ external_id: adminExternalId },
|
||||
)
|
||||
).account;
|
||||
// 作成したアカウントにユーザーを3名追加する
|
||||
const typiptUserExternalIds = [
|
||||
'typist-user-external-id1',
|
||||
@ -2478,12 +2548,11 @@ describe('createTypistGroup', () => {
|
||||
];
|
||||
const userIds: number[] = [];
|
||||
for (const typiptUserExternalId of typiptUserExternalIds) {
|
||||
const { userId } = await createUser(
|
||||
source,
|
||||
accountId,
|
||||
typiptUserExternalId,
|
||||
'typist',
|
||||
);
|
||||
const { id: userId } = await makeTestUser(source, {
|
||||
account_id: accountId,
|
||||
external_id: typiptUserExternalId,
|
||||
role: 'typist',
|
||||
});
|
||||
userIds.push(userId);
|
||||
}
|
||||
//作成したデータを確認
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
import { DataSource } from 'typeorm';
|
||||
import { User } from '../../../repositories/users/entity/user.entity';
|
||||
import { Account } from '../../../repositories/accounts/entity/account.entity';
|
||||
import {
|
||||
License,
|
||||
LicenseOrder,
|
||||
@ -9,162 +7,6 @@ import { SortCriteria } from '../../../repositories/sort_criteria/entity/sort_cr
|
||||
import { UserGroup } from '../../../repositories/user_groups/entity/user_group.entity';
|
||||
import { UserGroupMember } from '../../../repositories/user_groups/entity/user_group_member.entity';
|
||||
|
||||
// TODO: [PBI 2379] 他のUtilityからコピペしてきたもの。後日整理される前提。
|
||||
export const createAccountAndAdminUser = async (
|
||||
datasource: DataSource,
|
||||
adminExternalId: string,
|
||||
): Promise<{
|
||||
accountId: number;
|
||||
adminId: number;
|
||||
role: string;
|
||||
tier: number;
|
||||
}> => {
|
||||
const { identifiers: account_idf } = await datasource
|
||||
.getRepository(Account)
|
||||
.insert({
|
||||
tier: 1,
|
||||
country: 'JP',
|
||||
delegation_permission: false,
|
||||
locked: false,
|
||||
company_name: 'test inc.',
|
||||
verified: true,
|
||||
deleted_at: '',
|
||||
created_by: 'test_runner',
|
||||
created_at: new Date(),
|
||||
updated_by: 'updater',
|
||||
updated_at: new Date(),
|
||||
});
|
||||
const account = account_idf.pop() as Account;
|
||||
|
||||
const { identifiers: user_idf } = await datasource
|
||||
.getRepository(User)
|
||||
.insert({
|
||||
account_id: account.id,
|
||||
external_id: adminExternalId,
|
||||
role: 'admin none',
|
||||
accepted_terms_version: '1.0',
|
||||
email_verified: true,
|
||||
auto_renew: true,
|
||||
license_alert: true,
|
||||
notification: true,
|
||||
encryption: true,
|
||||
encryption_password: 'password',
|
||||
prompt: true,
|
||||
created_by: 'test_runner',
|
||||
created_at: new Date(),
|
||||
updated_by: 'updater',
|
||||
updated_at: new Date(),
|
||||
});
|
||||
const user = user_idf.pop() as User;
|
||||
|
||||
// Accountの管理者を設定する
|
||||
await datasource.getRepository(Account).update(
|
||||
{ id: user.account_id },
|
||||
{
|
||||
primary_admin_user_id: user.id,
|
||||
},
|
||||
);
|
||||
|
||||
const accountResult = await getAccount(datasource, account.id);
|
||||
const userResult = await getUser(datasource, user.id);
|
||||
|
||||
return {
|
||||
accountId: account.id,
|
||||
adminId: user.id,
|
||||
role: userResult.role,
|
||||
tier: accountResult.tier,
|
||||
};
|
||||
};
|
||||
|
||||
export const createAccount = async (
|
||||
datasource: DataSource,
|
||||
parentAccountId: number,
|
||||
tier: number,
|
||||
companyName: string,
|
||||
): Promise<{ accountId: number }> => {
|
||||
const { identifiers } = await datasource.getRepository(Account).insert({
|
||||
parent_account_id: parentAccountId,
|
||||
tier: tier,
|
||||
country: 'JP',
|
||||
delegation_permission: false,
|
||||
locked: false,
|
||||
company_name: companyName,
|
||||
verified: true,
|
||||
deleted_at: '',
|
||||
created_by: 'test_runner',
|
||||
created_at: new Date(),
|
||||
updated_by: 'updater',
|
||||
updated_at: new Date(),
|
||||
});
|
||||
const account = identifiers.pop() as Account;
|
||||
return { accountId: account.id };
|
||||
};
|
||||
|
||||
/**
|
||||
* テスト ユーティリティ: 指定IDのアカウントを取得する
|
||||
* @param dataSource データソース
|
||||
* @param id アカウントID
|
||||
* @returns 該当アカウント
|
||||
*/
|
||||
export const getAccount = async (dataSource: DataSource, id: number) => {
|
||||
return await dataSource.getRepository(Account).findOne({
|
||||
where: { id: id },
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* テスト ユーティリティ: すべてのアカウントを取得する
|
||||
* @param dataSource データソース
|
||||
* @returns 該当アカウント一覧
|
||||
*/
|
||||
export const getAccounts = async (
|
||||
dataSource: DataSource,
|
||||
): Promise<Account[]> => {
|
||||
return await dataSource.getRepository(Account).find();
|
||||
};
|
||||
|
||||
/**
|
||||
* テスト ユーティリティ: 指定ExternalIdのユーザーを取得する
|
||||
* @param dataSource データソース
|
||||
* @param externalId 外部ID
|
||||
* @returns 該当ユーザー
|
||||
*/
|
||||
export const getUserFromExternalID = async (
|
||||
dataSource: DataSource,
|
||||
externalId: string,
|
||||
) => {
|
||||
return await dataSource.getRepository(User).findOne({
|
||||
where: { external_id: externalId },
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* テスト ユーティリティ: 指定Idのユーザーを取得する
|
||||
* @param dataSource データソース
|
||||
* @param externalId 外部ID
|
||||
* @returns 該当ユーザー
|
||||
*/
|
||||
export const getUser = async (
|
||||
datasource: DataSource,
|
||||
id: number,
|
||||
): Promise<User> => {
|
||||
const user = await datasource.getRepository(User).findOne({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
});
|
||||
return user;
|
||||
};
|
||||
|
||||
/**
|
||||
* テスト ユーティリティ: すべてのユーザーを取得する
|
||||
* @param dataSource データソース
|
||||
* @returns 該当ユーザー一覧
|
||||
*/
|
||||
export const getUsers = async (dataSource: DataSource): Promise<User[]> => {
|
||||
return await dataSource.getRepository(User).find();
|
||||
};
|
||||
|
||||
/**
|
||||
* テスト ユーティリティ: すべてのソート条件を取得する
|
||||
* @param dataSource データソース
|
||||
@ -244,101 +86,6 @@ export const createLicenseOrder = async (
|
||||
identifiers.pop() as License;
|
||||
};
|
||||
|
||||
export const createUser = async (
|
||||
datasource: DataSource,
|
||||
accountId: number,
|
||||
external_id: string,
|
||||
role: string,
|
||||
author_id?: string | undefined,
|
||||
): Promise<{ userId: number; externalId: string; authorId: string }> => {
|
||||
const { identifiers } = await datasource.getRepository(User).insert({
|
||||
account_id: accountId,
|
||||
external_id: external_id,
|
||||
role: role,
|
||||
accepted_terms_version: '1.0',
|
||||
author_id: author_id,
|
||||
email_verified: true,
|
||||
auto_renew: true,
|
||||
license_alert: true,
|
||||
notification: true,
|
||||
encryption: false,
|
||||
prompt: false,
|
||||
created_by: 'test_runner',
|
||||
created_at: new Date(),
|
||||
updated_by: 'updater',
|
||||
updated_at: new Date(),
|
||||
});
|
||||
const user = identifiers.pop() as User;
|
||||
return { userId: user.id, externalId: external_id, authorId: author_id };
|
||||
};
|
||||
|
||||
// TODO: [PBI 2379] 第五階層のアカウント・管理者を作成する。後日整理される前提。
|
||||
export const createAccountAndAdminUserForTier5 = async (
|
||||
datasource: DataSource,
|
||||
adminExternalId: string,
|
||||
): Promise<{
|
||||
accountId: number;
|
||||
adminId: number;
|
||||
role: string;
|
||||
tier: number;
|
||||
}> => {
|
||||
const { identifiers: account_idf } = await datasource
|
||||
.getRepository(Account)
|
||||
.insert({
|
||||
tier: 5,
|
||||
country: 'JP',
|
||||
delegation_permission: false,
|
||||
locked: false,
|
||||
company_name: 'test inc.',
|
||||
verified: true,
|
||||
deleted_at: '',
|
||||
created_by: 'test_runner',
|
||||
created_at: new Date(),
|
||||
updated_by: 'updater',
|
||||
updated_at: new Date(),
|
||||
});
|
||||
const account = account_idf.pop() as Account;
|
||||
|
||||
const { identifiers: user_idf } = await datasource
|
||||
.getRepository(User)
|
||||
.insert({
|
||||
account_id: account.id,
|
||||
external_id: adminExternalId,
|
||||
role: 'none',
|
||||
accepted_terms_version: '1.0',
|
||||
email_verified: true,
|
||||
auto_renew: true,
|
||||
license_alert: true,
|
||||
notification: true,
|
||||
encryption: true,
|
||||
encryption_password: 'password',
|
||||
prompt: true,
|
||||
created_by: 'test_runner',
|
||||
created_at: new Date(),
|
||||
updated_by: 'updater',
|
||||
updated_at: new Date(),
|
||||
});
|
||||
const user = user_idf.pop() as User;
|
||||
|
||||
// Accountの管理者を設定する
|
||||
await datasource.getRepository(Account).update(
|
||||
{ id: user.account_id },
|
||||
{
|
||||
primary_admin_user_id: user.id,
|
||||
},
|
||||
);
|
||||
|
||||
const accountResult = await getAccount(datasource, account.id);
|
||||
const userResult = await getUser(datasource, user.id);
|
||||
|
||||
return {
|
||||
accountId: account.id,
|
||||
adminId: user.id,
|
||||
role: userResult.role,
|
||||
tier: accountResult.tier,
|
||||
};
|
||||
};
|
||||
|
||||
// タイピストグループを取得する
|
||||
export const getTypistGroup = async (
|
||||
datasource: DataSource,
|
||||
|
||||
@ -7,14 +7,10 @@ import {
|
||||
makeFilesServiceMock,
|
||||
} from './test/files.service.mock';
|
||||
import { DataSource } from 'typeorm';
|
||||
import {
|
||||
createAccount,
|
||||
createTask,
|
||||
createUser,
|
||||
makeTestingModuleWithBlob,
|
||||
} from './test/utility';
|
||||
import { createTask, makeTestingModuleWithBlob } from './test/utility';
|
||||
import { FilesService } from './files.service';
|
||||
import { makeContext } from '../../common/log';
|
||||
import { makeTestSimpleAccount, makeTestUser } from '../../common/test/utility';
|
||||
|
||||
describe('音声ファイルアップロードURL取得', () => {
|
||||
it('アップロードSASトークンが乗っているURLを返却する', async () => {
|
||||
@ -306,14 +302,17 @@ describe('音声ファイルダウンロードURL取得', () => {
|
||||
});
|
||||
|
||||
it('ダウンロードSASトークンが乗っているURLを取得できる', async () => {
|
||||
const { accountId } = await createAccount(source);
|
||||
const { externalId, userId, authorId } = await createUser(
|
||||
source,
|
||||
accountId,
|
||||
'author-user-external-id',
|
||||
'author',
|
||||
'AUTHOR_ID',
|
||||
);
|
||||
const { id: accountId } = await makeTestSimpleAccount(source);
|
||||
const {
|
||||
external_id: externalId,
|
||||
id: userId,
|
||||
author_id: authorId,
|
||||
} = await makeTestUser(source, {
|
||||
account_id: accountId,
|
||||
external_id: 'author-user-external-id',
|
||||
role: 'author',
|
||||
author_id: 'AUTHOR_ID',
|
||||
});
|
||||
const url = `https://saodmsusdev.blob.core.windows.net/account-${accountId}/${userId}`;
|
||||
|
||||
const { audioFileId } = await createTask(
|
||||
@ -343,20 +342,18 @@ describe('音声ファイルダウンロードURL取得', () => {
|
||||
});
|
||||
|
||||
it('Typistの場合、タスクのステータスが[Inprogress,Pending]以外でエラー', async () => {
|
||||
const { accountId } = await createAccount(source);
|
||||
const { externalId, userId } = await createUser(
|
||||
source,
|
||||
accountId,
|
||||
'typist-user-external-id',
|
||||
'typist',
|
||||
);
|
||||
const { userId: authorUserId } = await createUser(
|
||||
source,
|
||||
accountId,
|
||||
'author-user-external-id',
|
||||
'author',
|
||||
'AUTHOR_ID',
|
||||
);
|
||||
const { id: accountId } = await makeTestSimpleAccount(source);
|
||||
const { external_id: externalId, id: userId } = await makeTestUser(source, {
|
||||
account_id: accountId,
|
||||
external_id: 'typist-user-external-id',
|
||||
role: 'typist',
|
||||
});
|
||||
const { id: authorUserId } = await makeTestUser(source, {
|
||||
account_id: accountId,
|
||||
external_id: 'author-user-external-id',
|
||||
role: 'author',
|
||||
author_id: 'AUTHOR_ID',
|
||||
});
|
||||
|
||||
const url = `https://saodmsusdev.blob.core.windows.net/account-${accountId}/${authorUserId}`;
|
||||
|
||||
@ -388,26 +385,23 @@ describe('音声ファイルダウンロードURL取得', () => {
|
||||
});
|
||||
|
||||
it('Typistの場合、自身が担当するタスクでない場合エラー', async () => {
|
||||
const { accountId } = await createAccount(source);
|
||||
const { externalId } = await createUser(
|
||||
source,
|
||||
accountId,
|
||||
'typist-user-external-id',
|
||||
'typist',
|
||||
);
|
||||
const { userId: otherId } = await createUser(
|
||||
source,
|
||||
accountId,
|
||||
'other-typist-user-external-id',
|
||||
'typist',
|
||||
);
|
||||
const { userId: authorUserId } = await createUser(
|
||||
source,
|
||||
accountId,
|
||||
'author-user-external-id',
|
||||
'author',
|
||||
'AUTHOR_ID',
|
||||
);
|
||||
const { id: accountId } = await makeTestSimpleAccount(source);
|
||||
const { external_id: externalId } = await makeTestUser(source, {
|
||||
account_id: accountId,
|
||||
external_id: 'typist-user-external-id',
|
||||
role: 'typist',
|
||||
});
|
||||
const { id: otherId } = await makeTestUser(source, {
|
||||
account_id: accountId,
|
||||
external_id: 'other-typist-user-external-id',
|
||||
role: 'typist',
|
||||
});
|
||||
const { id: authorUserId } = await makeTestUser(source, {
|
||||
account_id: accountId,
|
||||
external_id: 'author-user-external-id',
|
||||
role: 'author',
|
||||
author_id: 'AUTHOR_ID',
|
||||
});
|
||||
const url = `https://saodmsusdev.blob.core.windows.net/account-${accountId}/${authorUserId}`;
|
||||
|
||||
const { audioFileId } = await createTask(
|
||||
@ -438,14 +432,13 @@ describe('音声ファイルダウンロードURL取得', () => {
|
||||
});
|
||||
|
||||
it('Authorの場合、自身が登録したタスクでない場合エラー', async () => {
|
||||
const { accountId } = await createAccount(source);
|
||||
const { externalId, userId } = await createUser(
|
||||
source,
|
||||
accountId,
|
||||
'author-user-external-id',
|
||||
'author',
|
||||
'AUTHOR_ID',
|
||||
);
|
||||
const { id: accountId } = await makeTestSimpleAccount(source);
|
||||
const { external_id: externalId, id: userId } = await makeTestUser(source, {
|
||||
account_id: accountId,
|
||||
external_id: 'author-user-external-id',
|
||||
role: 'author',
|
||||
author_id: 'AUTHOR_ID',
|
||||
});
|
||||
const url = `https://saodmsusdev.blob.core.windows.net/account-${accountId}/${userId}`;
|
||||
|
||||
const { audioFileId } = await createTask(
|
||||
@ -477,14 +470,13 @@ describe('音声ファイルダウンロードURL取得', () => {
|
||||
});
|
||||
|
||||
it('Taskが存在しない場合はエラーとなる', async () => {
|
||||
const { accountId } = await createAccount(source);
|
||||
const { externalId } = await createUser(
|
||||
source,
|
||||
accountId,
|
||||
'author-user-external-id',
|
||||
'author',
|
||||
'AUTHOR_ID',
|
||||
);
|
||||
const { id: accountId } = await makeTestSimpleAccount(source);
|
||||
const { external_id: externalId } = await makeTestUser(source, {
|
||||
account_id: accountId,
|
||||
external_id: 'author-user-external-id',
|
||||
role: 'author',
|
||||
author_id: 'AUTHOR_ID',
|
||||
});
|
||||
|
||||
const blobParam = makeBlobstorageServiceMockValue();
|
||||
|
||||
@ -503,14 +495,17 @@ describe('音声ファイルダウンロードURL取得', () => {
|
||||
});
|
||||
|
||||
it('blobストレージにファイルが存在しない場合はエラーとなる', async () => {
|
||||
const { accountId } = await createAccount(source);
|
||||
const { externalId, userId, authorId } = await createUser(
|
||||
source,
|
||||
accountId,
|
||||
'author-user-external-id',
|
||||
'author',
|
||||
'AUTHOR_ID',
|
||||
);
|
||||
const { id: accountId } = await makeTestSimpleAccount(source);
|
||||
const {
|
||||
external_id: externalId,
|
||||
id: userId,
|
||||
author_id: authorId,
|
||||
} = await makeTestUser(source, {
|
||||
account_id: accountId,
|
||||
external_id: 'author-user-external-id',
|
||||
role: 'author',
|
||||
author_id: 'AUTHOR_ID',
|
||||
});
|
||||
const url = `https://saodmsusdev.blob.core.windows.net/account-${accountId}/${userId}`;
|
||||
|
||||
const { audioFileId } = await createTask(
|
||||
@ -561,13 +556,15 @@ describe('テンプレートファイルダウンロードURL取得', () => {
|
||||
});
|
||||
|
||||
it('ダウンロードSASトークンが乗っているURLを取得できる', async () => {
|
||||
const { accountId } = await createAccount(source);
|
||||
const { externalId, authorId } = await createUser(
|
||||
const { id: accountId } = await makeTestSimpleAccount(source);
|
||||
const { external_id: externalId, author_id: authorId } = await makeTestUser(
|
||||
source,
|
||||
accountId,
|
||||
'author-user-external-id',
|
||||
'author',
|
||||
'AUTHOR_ID',
|
||||
{
|
||||
account_id: accountId,
|
||||
external_id: 'author-user-external-id',
|
||||
role: 'author',
|
||||
author_id: 'AUTHOR_ID',
|
||||
},
|
||||
);
|
||||
const url = `https://saodmsusdev.blob.core.windows.net/account-${accountId}/Templates`;
|
||||
|
||||
@ -598,14 +595,13 @@ describe('テンプレートファイルダウンロードURL取得', () => {
|
||||
});
|
||||
|
||||
it('Typistの場合、タスクのステータスが[Inprogress,Pending]以外でエラー', async () => {
|
||||
const { accountId } = await createAccount(source);
|
||||
const { externalId, userId } = await createUser(
|
||||
source,
|
||||
accountId,
|
||||
'typist-user-external-id',
|
||||
'typist',
|
||||
undefined,
|
||||
);
|
||||
const { id: accountId } = await makeTestSimpleAccount(source);
|
||||
const { external_id: externalId, id: userId } = await makeTestUser(source, {
|
||||
account_id: accountId,
|
||||
external_id: 'typist-user-external-id',
|
||||
role: 'typist',
|
||||
author_id: undefined,
|
||||
});
|
||||
const url = `https://saodmsusdev.blob.core.windows.net/account-${accountId}/Templates`;
|
||||
|
||||
const { audioFileId } = await createTask(
|
||||
@ -636,21 +632,19 @@ describe('テンプレートファイルダウンロードURL取得', () => {
|
||||
});
|
||||
|
||||
it('Typistの場合、自身が担当するタスクでない場合エラー', async () => {
|
||||
const { accountId } = await createAccount(source);
|
||||
const { externalId } = await createUser(
|
||||
source,
|
||||
accountId,
|
||||
'typist-user-external-id',
|
||||
'typist',
|
||||
undefined,
|
||||
);
|
||||
const { userId: otherId } = await createUser(
|
||||
source,
|
||||
accountId,
|
||||
'other-typist-user-external-id',
|
||||
'typist',
|
||||
undefined,
|
||||
);
|
||||
const { id: accountId } = await makeTestSimpleAccount(source);
|
||||
const { external_id: externalId } = await makeTestUser(source, {
|
||||
account_id: accountId,
|
||||
external_id: 'typist-user-external-id',
|
||||
role: 'typist',
|
||||
author_id: undefined,
|
||||
});
|
||||
const { id: otherId } = await makeTestUser(source, {
|
||||
account_id: accountId,
|
||||
external_id: 'other-typist-user-external-id',
|
||||
role: 'typist',
|
||||
author_id: undefined,
|
||||
});
|
||||
const url = `https://saodmsusdev.blob.core.windows.net/account-${accountId}/Templates`;
|
||||
|
||||
const { audioFileId } = await createTask(
|
||||
@ -681,14 +675,13 @@ describe('テンプレートファイルダウンロードURL取得', () => {
|
||||
});
|
||||
|
||||
it('Authorの場合、自身が登録したタスクでない場合エラー', async () => {
|
||||
const { accountId } = await createAccount(source);
|
||||
const { externalId } = await createUser(
|
||||
source,
|
||||
accountId,
|
||||
'author-user-external-id',
|
||||
'author',
|
||||
'AUTHOR_ID',
|
||||
);
|
||||
const { id: accountId } = await makeTestSimpleAccount(source);
|
||||
const { external_id: externalId } = await makeTestUser(source, {
|
||||
account_id: accountId,
|
||||
external_id: 'author-user-external-id',
|
||||
role: 'author',
|
||||
author_id: 'AUTHOR_ID',
|
||||
});
|
||||
const url = `https://saodmsusdev.blob.core.windows.net/account-${accountId}/Templates`;
|
||||
|
||||
const { audioFileId } = await createTask(
|
||||
@ -720,14 +713,13 @@ describe('テンプレートファイルダウンロードURL取得', () => {
|
||||
});
|
||||
|
||||
it('Taskが存在しない場合はエラーとなる', async () => {
|
||||
const { accountId } = await createAccount(source);
|
||||
const { externalId } = await createUser(
|
||||
source,
|
||||
accountId,
|
||||
'author-user-external-id',
|
||||
'author',
|
||||
'AUTHOR_ID',
|
||||
);
|
||||
const { id: accountId } = await makeTestSimpleAccount(source);
|
||||
const { external_id: externalId } = await makeTestUser(source, {
|
||||
account_id: accountId,
|
||||
external_id: 'author-user-external-id',
|
||||
role: 'author',
|
||||
author_id: 'AUTHOR_ID',
|
||||
});
|
||||
|
||||
const blobParam = makeBlobstorageServiceMockValue();
|
||||
|
||||
@ -746,13 +738,15 @@ describe('テンプレートファイルダウンロードURL取得', () => {
|
||||
});
|
||||
|
||||
it('blobストレージにファイルが存在しない場合はエラーとなる', async () => {
|
||||
const { accountId } = await createAccount(source);
|
||||
const { externalId, authorId } = await createUser(
|
||||
const { id: accountId } = await makeTestSimpleAccount(source);
|
||||
const { external_id: externalId, author_id: authorId } = await makeTestUser(
|
||||
source,
|
||||
accountId,
|
||||
'author-user-external-id',
|
||||
'author',
|
||||
'AUTHOR_ID',
|
||||
{
|
||||
account_id: accountId,
|
||||
external_id: 'author-user-external-id',
|
||||
role: 'author',
|
||||
author_id: 'AUTHOR_ID',
|
||||
},
|
||||
);
|
||||
const url = `https://saodmsusdev.blob.core.windows.net/account-${accountId}/Templates`;
|
||||
|
||||
|
||||
@ -36,58 +36,8 @@ import {
|
||||
BlobstorageServiceMockValue,
|
||||
makeBlobstorageServiceMock,
|
||||
} from './files.service.mock';
|
||||
import { User } from '../../../repositories/users/entity/user.entity';
|
||||
import { Account } from '../../../repositories/accounts/entity/account.entity';
|
||||
import { TemplateFile } from '../../../repositories/template_files/entity/template_file.entity';
|
||||
|
||||
export const createAccount = async (
|
||||
datasource: DataSource,
|
||||
): Promise<{ accountId: number }> => {
|
||||
const { identifiers } = await datasource.getRepository(Account).insert({
|
||||
tier: 5,
|
||||
country: 'US',
|
||||
delegation_permission: false,
|
||||
locked: false,
|
||||
company_name: 'test inc.',
|
||||
verified: true,
|
||||
deleted_at: '',
|
||||
created_by: 'test_runner',
|
||||
created_at: new Date(),
|
||||
updated_by: 'updater',
|
||||
updated_at: new Date(),
|
||||
});
|
||||
const account = identifiers.pop() as Account;
|
||||
return { accountId: account.id };
|
||||
};
|
||||
|
||||
export const createUser = async (
|
||||
datasource: DataSource,
|
||||
accountId: number,
|
||||
external_id: string,
|
||||
role: string,
|
||||
author_id?: string | undefined,
|
||||
): Promise<{ userId: number; externalId: string; authorId: string }> => {
|
||||
const { identifiers } = await datasource.getRepository(User).insert({
|
||||
account_id: accountId,
|
||||
external_id: external_id,
|
||||
role: role,
|
||||
accepted_terms_version: '1.0',
|
||||
author_id: author_id,
|
||||
email_verified: true,
|
||||
auto_renew: true,
|
||||
license_alert: true,
|
||||
notification: true,
|
||||
encryption: false,
|
||||
prompt: false,
|
||||
created_by: 'test_runner',
|
||||
created_at: new Date(),
|
||||
updated_by: 'updater',
|
||||
updated_at: new Date(),
|
||||
});
|
||||
const user = identifiers.pop() as User;
|
||||
return { userId: user.id, externalId: external_id, authorId: author_id };
|
||||
};
|
||||
|
||||
export const createTask = async (
|
||||
datasource: DataSource,
|
||||
account_id: number,
|
||||
|
||||
@ -23,8 +23,6 @@ import { LicensesService } from './licenses.service';
|
||||
import { makeTestingModule } from '../../common/test/modules';
|
||||
import { DataSource } from 'typeorm';
|
||||
import {
|
||||
createAccount,
|
||||
createUser,
|
||||
createCardLicense,
|
||||
createLicense,
|
||||
createCardLicenseIssue,
|
||||
@ -36,8 +34,8 @@ import {
|
||||
} from './test/utility';
|
||||
import { UsersService } from '../users/users.service';
|
||||
import { makeContext } from '../../common/log';
|
||||
import { IsNotIn } from 'class-validator';
|
||||
import { LICENSE_ALLOCATED_STATUS, LICENSE_TYPE } from '../../constants';
|
||||
import { makeTestSimpleAccount, makeTestUser } from '../../common/test/utility';
|
||||
|
||||
describe('LicensesService', () => {
|
||||
it('ライセンス注文が完了する', async () => {
|
||||
@ -303,13 +301,13 @@ describe('DBテスト', () => {
|
||||
it('カードライセンス発行が完了する(発行数が合っているか確認)', async () => {
|
||||
const module = await makeTestingModule(source);
|
||||
|
||||
const { accountId } = await createAccount(source);
|
||||
const { externalId } = await createUser(
|
||||
source,
|
||||
accountId,
|
||||
'userId',
|
||||
'admin',
|
||||
);
|
||||
const { id: accountId } = await makeTestSimpleAccount(source);
|
||||
const { external_id: externalId } = await makeTestUser(source, {
|
||||
account_id: accountId,
|
||||
external_id: 'userId',
|
||||
role: 'admin',
|
||||
author_id: undefined,
|
||||
});
|
||||
|
||||
const service = module.get<LicensesService>(LicensesService);
|
||||
const issueCount = 500;
|
||||
@ -321,13 +319,13 @@ describe('DBテスト', () => {
|
||||
it('カードライセンス取り込みが完了する', async () => {
|
||||
const module = await makeTestingModule(source);
|
||||
|
||||
const { accountId } = await createAccount(source);
|
||||
const { externalId } = await createUser(
|
||||
source,
|
||||
accountId,
|
||||
'userId',
|
||||
'admin',
|
||||
);
|
||||
const { id: accountId } = await makeTestSimpleAccount(source);
|
||||
const { external_id: externalId } = await makeTestUser(source, {
|
||||
account_id: accountId,
|
||||
external_id: 'userId',
|
||||
role: 'admin',
|
||||
author_id: undefined,
|
||||
});
|
||||
|
||||
const cardLicenseKey = 'WZCETXC0Z9PQZ9GKRGGY';
|
||||
const defaultAccountId = 150;
|
||||
@ -364,13 +362,13 @@ describe('DBテスト', () => {
|
||||
const module = await makeTestingModule(source);
|
||||
|
||||
const now = new Date();
|
||||
const { accountId } = await createAccount(source);
|
||||
const { externalId } = await createUser(
|
||||
source,
|
||||
accountId,
|
||||
'userId',
|
||||
'admin',
|
||||
);
|
||||
const { id: accountId } = await makeTestSimpleAccount(source);
|
||||
const { external_id: externalId } = await makeTestUser(source, {
|
||||
account_id: accountId,
|
||||
external_id: 'userId',
|
||||
role: 'admin',
|
||||
author_id: undefined,
|
||||
});
|
||||
|
||||
// ライセンスを作成する
|
||||
// 1件目
|
||||
@ -499,8 +497,13 @@ describe('ライセンス割り当て', () => {
|
||||
it('未割当のライセンスに対して、ライセンス割り当てが完了する', async () => {
|
||||
const module = await makeTestingModule(source);
|
||||
|
||||
const { accountId } = await createAccount(source);
|
||||
const { userId } = await createUser(source, accountId, 'userId', 'admin');
|
||||
const { id: accountId } = await makeTestSimpleAccount(source);
|
||||
const { id: userId } = await makeTestUser(source, {
|
||||
account_id: accountId,
|
||||
external_id: 'userId',
|
||||
role: 'admin',
|
||||
author_id: undefined,
|
||||
});
|
||||
await createLicense(
|
||||
source,
|
||||
1,
|
||||
@ -544,8 +547,13 @@ describe('ライセンス割り当て', () => {
|
||||
it('再割り当て可能なライセンスに対して、ライセンス割り当てが完了する', async () => {
|
||||
const module = await makeTestingModule(source);
|
||||
|
||||
const { accountId } = await createAccount(source);
|
||||
const { userId } = await createUser(source, accountId, 'userId', 'admin');
|
||||
const { id: accountId } = await makeTestSimpleAccount(source);
|
||||
const { id: userId } = await makeTestUser(source, {
|
||||
account_id: accountId,
|
||||
external_id: 'userId',
|
||||
role: 'admin',
|
||||
author_id: undefined,
|
||||
});
|
||||
const date = new Date();
|
||||
date.setDate(date.getDate() + 30);
|
||||
await createLicense(
|
||||
@ -585,8 +593,13 @@ describe('ライセンス割り当て', () => {
|
||||
it('未割当のライセンスに対して、別のライセンスが割り当てられているユーザーの割り当てが完了する', async () => {
|
||||
const module = await makeTestingModule(source);
|
||||
|
||||
const { accountId } = await createAccount(source);
|
||||
const { userId } = await createUser(source, accountId, 'userId', 'admin');
|
||||
const { id: accountId } = await makeTestSimpleAccount(source);
|
||||
const { id: userId } = await makeTestUser(source, {
|
||||
account_id: accountId,
|
||||
external_id: 'userId',
|
||||
role: 'admin',
|
||||
author_id: undefined,
|
||||
});
|
||||
const date = new Date();
|
||||
date.setDate(date.getDate() + 30);
|
||||
await createLicense(
|
||||
@ -661,8 +674,13 @@ describe('ライセンス割り当て', () => {
|
||||
it('割り当て時にライセンス履歴テーブルへの登録が完了する(元がNORMALのとき)', async () => {
|
||||
const module = await makeTestingModule(source);
|
||||
|
||||
const { accountId } = await createAccount(source);
|
||||
const { userId } = await createUser(source, accountId, 'userId', 'admin');
|
||||
const { id: accountId } = await makeTestSimpleAccount(source);
|
||||
const { id: userId } = await makeTestUser(source, {
|
||||
account_id: accountId,
|
||||
external_id: 'userId',
|
||||
role: 'admin',
|
||||
author_id: undefined,
|
||||
});
|
||||
const date = new Date();
|
||||
date.setDate(date.getDate() + 30);
|
||||
await createLicense(
|
||||
@ -701,8 +719,13 @@ describe('ライセンス割り当て', () => {
|
||||
it('割り当て時にライセンス履歴テーブルへの登録が完了する(元がCARDのとき)', async () => {
|
||||
const module = await makeTestingModule(source);
|
||||
|
||||
const { accountId } = await createAccount(source);
|
||||
const { userId } = await createUser(source, accountId, 'userId', 'admin');
|
||||
const { id: accountId } = await makeTestSimpleAccount(source);
|
||||
const { id: userId } = await makeTestUser(source, {
|
||||
account_id: accountId,
|
||||
external_id: 'userId',
|
||||
role: 'admin',
|
||||
author_id: undefined,
|
||||
});
|
||||
const date = new Date();
|
||||
date.setDate(date.getDate() + 30);
|
||||
await createLicense(
|
||||
@ -741,8 +764,13 @@ describe('ライセンス割り当て', () => {
|
||||
it('割り当て時にライセンス履歴テーブルへの登録が完了する(元がTRIALのとき)', async () => {
|
||||
const module = await makeTestingModule(source);
|
||||
|
||||
const { accountId } = await createAccount(source);
|
||||
const { userId } = await createUser(source, accountId, 'userId', 'admin');
|
||||
const { id: accountId } = await makeTestSimpleAccount(source);
|
||||
const { id: userId } = await makeTestUser(source, {
|
||||
account_id: accountId,
|
||||
external_id: 'userId',
|
||||
role: 'admin',
|
||||
author_id: undefined,
|
||||
});
|
||||
const date = new Date();
|
||||
date.setDate(date.getDate() + 30);
|
||||
await createLicense(
|
||||
@ -781,8 +809,13 @@ describe('ライセンス割り当て', () => {
|
||||
it('有効期限が切れているライセンスを割り当てようとした場合、エラーになる', async () => {
|
||||
const module = await makeTestingModule(source);
|
||||
|
||||
const { accountId } = await createAccount(source);
|
||||
const { userId } = await createUser(source, accountId, 'userId', 'admin');
|
||||
const { id: accountId } = await makeTestSimpleAccount(source);
|
||||
const { id: userId } = await makeTestUser(source, {
|
||||
account_id: accountId,
|
||||
external_id: 'userId',
|
||||
role: 'admin',
|
||||
author_id: undefined,
|
||||
});
|
||||
const date = new Date();
|
||||
date.setDate(date.getDate() - 30);
|
||||
await createLicense(
|
||||
@ -807,8 +840,13 @@ describe('ライセンス割り当て', () => {
|
||||
it('割り当て不可なライセンスを割り当てようとした場合、エラーになる', async () => {
|
||||
const module = await makeTestingModule(source);
|
||||
|
||||
const { accountId } = await createAccount(source);
|
||||
const { userId } = await createUser(source, accountId, 'userId', 'admin');
|
||||
const { id: accountId } = await makeTestSimpleAccount(source);
|
||||
const { id: userId } = await makeTestUser(source, {
|
||||
account_id: accountId,
|
||||
external_id: 'userId',
|
||||
role: 'admin',
|
||||
author_id: undefined,
|
||||
});
|
||||
const date = new Date();
|
||||
date.setDate(date.getDate() + 30);
|
||||
await createLicense(
|
||||
@ -866,8 +904,13 @@ describe('ライセンス割り当て解除', () => {
|
||||
it('ライセンスの割り当て解除が完了する', async () => {
|
||||
const module = await makeTestingModule(source);
|
||||
|
||||
const { accountId } = await createAccount(source);
|
||||
const { userId } = await createUser(source, accountId, 'userId', 'admin');
|
||||
const { id: accountId } = await makeTestSimpleAccount(source);
|
||||
const { id: userId } = await makeTestUser(source, {
|
||||
account_id: accountId,
|
||||
external_id: 'userId',
|
||||
role: 'admin',
|
||||
author_id: undefined,
|
||||
});
|
||||
const date = new Date();
|
||||
date.setDate(date.getDate() + 30);
|
||||
await createLicense(
|
||||
@ -915,9 +958,19 @@ describe('ライセンス割り当て解除', () => {
|
||||
it('ライセンスが既に割り当て解除されていた場合、エラーとなる', async () => {
|
||||
const module = await makeTestingModule(source);
|
||||
|
||||
const { accountId } = await createAccount(source);
|
||||
const { userId } = await createUser(source, accountId, 'userId', 'admin');
|
||||
await createUser(source, accountId, 'userId2', 'admin');
|
||||
const { id: accountId } = await makeTestSimpleAccount(source);
|
||||
const { id: userId } = await makeTestUser(source, {
|
||||
account_id: accountId,
|
||||
external_id: 'userId',
|
||||
role: 'admin',
|
||||
author_id: undefined,
|
||||
});
|
||||
await makeTestUser(source, {
|
||||
account_id: accountId,
|
||||
external_id: 'userId2',
|
||||
role: 'admin',
|
||||
author_id: undefined,
|
||||
});
|
||||
const date = new Date();
|
||||
date.setDate(date.getDate() + 30);
|
||||
await createLicense(
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
import { DataSource } from 'typeorm';
|
||||
import { User } from '../../../repositories/users/entity/user.entity';
|
||||
import { Account } from '../../../repositories/accounts/entity/account.entity';
|
||||
import {
|
||||
License,
|
||||
CardLicense,
|
||||
@ -8,54 +6,6 @@ import {
|
||||
LicenseAllocationHistory,
|
||||
} from '../../../repositories/licenses/entity/license.entity';
|
||||
|
||||
export const createAccount = async (
|
||||
datasource: DataSource,
|
||||
): Promise<{ accountId: number }> => {
|
||||
const { identifiers } = await datasource.getRepository(Account).insert({
|
||||
tier: 1,
|
||||
country: 'JP',
|
||||
delegation_permission: false,
|
||||
locked: false,
|
||||
company_name: 'test inc.',
|
||||
verified: true,
|
||||
deleted_at: '',
|
||||
created_by: 'test_runner',
|
||||
created_at: new Date(),
|
||||
updated_by: 'updater',
|
||||
updated_at: new Date(),
|
||||
});
|
||||
const account = identifiers.pop() as Account;
|
||||
return { accountId: account.id };
|
||||
};
|
||||
|
||||
export const createUser = async (
|
||||
datasource: DataSource,
|
||||
accountId: number,
|
||||
external_id: string,
|
||||
role: string,
|
||||
author_id?: string | undefined,
|
||||
): Promise<{ userId: number; externalId: string }> => {
|
||||
const { identifiers } = await datasource.getRepository(User).insert({
|
||||
account_id: accountId,
|
||||
external_id: external_id,
|
||||
role: role,
|
||||
accepted_terms_version: '1.0',
|
||||
author_id: author_id,
|
||||
email_verified: true,
|
||||
auto_renew: true,
|
||||
license_alert: true,
|
||||
notification: true,
|
||||
encryption: false,
|
||||
prompt: false,
|
||||
created_by: 'test_runner',
|
||||
created_at: new Date(),
|
||||
updated_by: 'updater',
|
||||
updated_at: new Date(),
|
||||
});
|
||||
const user = identifiers.pop() as User;
|
||||
return { userId: user.id, externalId: external_id };
|
||||
};
|
||||
|
||||
export const createLicense = async (
|
||||
datasource: DataSource,
|
||||
licenseId: number,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,8 +1,6 @@
|
||||
import { DataSource } from 'typeorm';
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { User } from '../../../repositories/users/entity/user.entity';
|
||||
import { Account } from '../../../repositories/accounts/entity/account.entity';
|
||||
import { Task } from '../../../repositories/tasks/entity/task.entity';
|
||||
import { AudioFile } from '../../../repositories/audio_files/entity/audio_file.entity';
|
||||
import { CheckoutPermission } from '../../../repositories/checkout_permissions/entity/checkout_permission.entity';
|
||||
@ -102,54 +100,6 @@ export const makeTaskTestingModule = async (
|
||||
}
|
||||
};
|
||||
|
||||
export const createAccount = async (
|
||||
datasource: DataSource,
|
||||
): Promise<{ accountId: number }> => {
|
||||
const { identifiers } = await datasource.getRepository(Account).insert({
|
||||
tier: 1,
|
||||
country: 'JP',
|
||||
delegation_permission: false,
|
||||
locked: false,
|
||||
company_name: 'test inc.',
|
||||
verified: true,
|
||||
deleted_at: '',
|
||||
created_by: 'test_runner',
|
||||
created_at: new Date(),
|
||||
updated_by: 'updater',
|
||||
updated_at: new Date(),
|
||||
});
|
||||
const account = identifiers.pop() as Account;
|
||||
return { accountId: account.id };
|
||||
};
|
||||
|
||||
export const createUser = async (
|
||||
datasource: DataSource,
|
||||
accountId: number,
|
||||
external_id: string,
|
||||
role: string,
|
||||
author_id?: string | undefined,
|
||||
): Promise<{ userId: number; externalId: string }> => {
|
||||
const { identifiers } = await datasource.getRepository(User).insert({
|
||||
account_id: accountId,
|
||||
external_id: external_id,
|
||||
role: role,
|
||||
accepted_terms_version: '1.0',
|
||||
author_id: author_id,
|
||||
email_verified: true,
|
||||
auto_renew: true,
|
||||
license_alert: true,
|
||||
notification: true,
|
||||
encryption: false,
|
||||
prompt: false,
|
||||
created_by: 'test_runner',
|
||||
created_at: new Date(),
|
||||
updated_by: 'updater',
|
||||
updated_at: new Date(),
|
||||
});
|
||||
const user = identifiers.pop() as User;
|
||||
return { userId: user.id, externalId: external_id };
|
||||
};
|
||||
|
||||
export const createTask = async (
|
||||
datasource: DataSource,
|
||||
account_id: number,
|
||||
|
||||
@ -29,8 +29,6 @@ import { NotificationhubService } from '../../../gateways/notificationhub/notifi
|
||||
import { FilesService } from '../../../features/files/files.service';
|
||||
import { LicensesService } from '../../../features/licenses/licenses.service';
|
||||
import { TasksService } from '../../../features/tasks/tasks.service';
|
||||
import { User } from '../../../repositories/users/entity/user.entity';
|
||||
import { Account } from '../../../repositories/accounts/entity/account.entity';
|
||||
import { UserGroup } from '../../../repositories/user_groups/entity/user_group.entity';
|
||||
import { UserGroupMember } from '../../../repositories/user_groups/entity/user_group_member.entity';
|
||||
import { License } from '../../../repositories/licenses/entity/license.entity';
|
||||
@ -38,150 +36,6 @@ import { AdB2cMockValue, makeAdB2cServiceMock } from './users.service.mock';
|
||||
import { AdB2cService } from '../../../gateways/adb2c/adb2c.service';
|
||||
import { LICENSE_ALLOCATED_STATUS, LICENSE_TYPE } from '../../../constants';
|
||||
|
||||
export const createAccountAndAdminUser = async (
|
||||
datasource: DataSource,
|
||||
adminExternalId: string,
|
||||
): Promise<{
|
||||
accountId: number;
|
||||
adminId: number;
|
||||
role: string;
|
||||
tier: number;
|
||||
}> => {
|
||||
const { identifiers: account_idf } = await datasource
|
||||
.getRepository(Account)
|
||||
.insert({
|
||||
tier: 1,
|
||||
country: 'JP',
|
||||
delegation_permission: false,
|
||||
locked: false,
|
||||
company_name: 'test inc.',
|
||||
verified: true,
|
||||
deleted_at: '',
|
||||
created_by: 'test_runner',
|
||||
created_at: new Date(),
|
||||
updated_by: 'updater',
|
||||
updated_at: new Date(),
|
||||
});
|
||||
const account = account_idf.pop() as Account;
|
||||
|
||||
const { identifiers: user_idf } = await datasource
|
||||
.getRepository(User)
|
||||
.insert({
|
||||
account_id: account.id,
|
||||
external_id: adminExternalId,
|
||||
role: 'admin none',
|
||||
accepted_terms_version: '1.0',
|
||||
email_verified: true,
|
||||
auto_renew: true,
|
||||
license_alert: true,
|
||||
notification: true,
|
||||
encryption: true,
|
||||
encryption_password: 'password',
|
||||
prompt: true,
|
||||
created_by: 'test_runner',
|
||||
created_at: new Date(),
|
||||
updated_by: 'updater',
|
||||
updated_at: new Date(),
|
||||
});
|
||||
const user = user_idf.pop() as User;
|
||||
|
||||
// Accountの管理者を設定する
|
||||
await datasource.getRepository(Account).update(
|
||||
{ id: user.account_id },
|
||||
{
|
||||
primary_admin_user_id: user.id,
|
||||
},
|
||||
);
|
||||
|
||||
const accountResult = await getAccount(datasource, account.id);
|
||||
const userResult = await getUser(datasource, user.id);
|
||||
|
||||
return {
|
||||
accountId: account.id,
|
||||
adminId: user.id,
|
||||
role: userResult.role,
|
||||
tier: accountResult.tier,
|
||||
};
|
||||
};
|
||||
|
||||
export const createAccount = async (
|
||||
datasource: DataSource,
|
||||
): Promise<{ accountId: number }> => {
|
||||
const { identifiers } = await datasource.getRepository(Account).insert({
|
||||
tier: 1,
|
||||
country: 'JP',
|
||||
delegation_permission: false,
|
||||
locked: false,
|
||||
company_name: 'test inc.',
|
||||
verified: true,
|
||||
deleted_at: '',
|
||||
created_by: 'test_runner',
|
||||
created_at: new Date(),
|
||||
updated_by: 'updater',
|
||||
updated_at: new Date(),
|
||||
});
|
||||
const account = identifiers.pop() as Account;
|
||||
return { accountId: account.id };
|
||||
};
|
||||
|
||||
export const createUser = async (
|
||||
datasource: DataSource,
|
||||
accountId: number,
|
||||
external_id: string,
|
||||
role: string,
|
||||
author_id?: string | undefined,
|
||||
auto_renew?: boolean,
|
||||
encryption?: boolean | undefined,
|
||||
encryption_password?: string | undefined,
|
||||
prompt?: boolean | undefined,
|
||||
email_verified?: boolean | undefined,
|
||||
): Promise<{ userId: number; externalId: string }> => {
|
||||
const { identifiers } = await datasource.getRepository(User).insert({
|
||||
account_id: accountId,
|
||||
external_id: external_id,
|
||||
role: role,
|
||||
accepted_terms_version: '1.0',
|
||||
author_id: author_id,
|
||||
email_verified: email_verified ?? true,
|
||||
auto_renew: auto_renew,
|
||||
license_alert: true,
|
||||
notification: true,
|
||||
encryption: encryption ?? false,
|
||||
encryption_password: encryption_password,
|
||||
prompt: prompt ?? false,
|
||||
created_by: 'test_runner',
|
||||
created_at: new Date(),
|
||||
updated_by: 'updater',
|
||||
updated_at: new Date(),
|
||||
});
|
||||
const user = identifiers.pop() as User;
|
||||
return { userId: user.id, externalId: external_id };
|
||||
};
|
||||
|
||||
/**
|
||||
* テスト ユーティリティ: 指定IDのアカウントを取得する
|
||||
* @param dataSource データソース
|
||||
* @param id アカウントID
|
||||
* @returns 該当アカウント
|
||||
*/
|
||||
export const getAccount = async (dataSource: DataSource, id: number) => {
|
||||
return await dataSource.getRepository(Account).findOne({
|
||||
where: { id: id },
|
||||
});
|
||||
};
|
||||
|
||||
export const getUser = async (
|
||||
datasource: DataSource,
|
||||
id: number,
|
||||
): Promise<User> => {
|
||||
const user = await datasource.getRepository(User).findOne({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
});
|
||||
return user;
|
||||
};
|
||||
|
||||
export const getLicenses = async (
|
||||
datasource: DataSource,
|
||||
account_id: number,
|
||||
@ -194,33 +48,6 @@ export const getLicenses = async (
|
||||
return licenses;
|
||||
};
|
||||
|
||||
/**
|
||||
* テスト ユーティリティ: 指定外部IDを持つユーザーを取得する
|
||||
* @param dataSource データソース
|
||||
* @param externalId 外部ID
|
||||
* @returns 該当ユーザー
|
||||
*/
|
||||
export const getUserByExternalId = async (
|
||||
datasource: DataSource,
|
||||
externalId: string,
|
||||
): Promise<User> => {
|
||||
const user = await datasource.getRepository(User).findOne({
|
||||
where: {
|
||||
external_id: externalId,
|
||||
},
|
||||
});
|
||||
return user;
|
||||
};
|
||||
|
||||
/**
|
||||
* テスト ユーティリティ: すべてのユーザーを取得する
|
||||
* @param dataSource データソース
|
||||
* @returns 該当ユーザー一覧
|
||||
*/
|
||||
export const getUsers = async (dataSource: DataSource): Promise<User[]> => {
|
||||
return await dataSource.getRepository(User).find();
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param datasource
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user