Merge branch 'develop'

This commit is contained in:
SAITO-PC-3\saito.k 2024-01-24 18:21:05 +09:00
commit 8eacaef3ec
44 changed files with 1988 additions and 1025 deletions

View File

@ -27,9 +27,30 @@ jobs:
exit 1
fi
displayName: 'タグが付けられたCommitがmainブランチに存在するか確認'
- job: backend_build
- job: backend_test
dependsOn: initialize
condition: succeeded('initialize')
displayName: UnitTest
pool:
vmImage: ubuntu-latest
steps:
- checkout: self
clean: true
fetchDepth: 1
- task: Bash@3
displayName: Bash Script (Test)
inputs:
targetType: inline
workingDirectory: dictation_server/.devcontainer
script: |
docker-compose -f pipeline-docker-compose.yml build
docker-compose -f pipeline-docker-compose.yml up -d
docker-compose exec -T dictation_server sudo npm ci
docker-compose exec -T dictation_server sudo npm run migrate:up:test
docker-compose exec -T dictation_server sudo npm run test
- job: backend_build
dependsOn: backend_test
condition: succeeded('backend_test')
displayName: Build And Push Backend Image
pool:
name: odms-deploy-pipeline
@ -43,51 +64,6 @@ jobs:
command: ci
workingDir: dictation_server
verbose: false
- task: AzureKeyVault@2
displayName: 'Azure Key Vault: kv-odms-secret-stg'
inputs:
ConnectedServiceName: 'omds-service-connection-stg'
KeyVaultName: kv-odms-secret-stg
SecretsFilter: '*'
- task: Bash@3
displayName: Bash Script (Test)
inputs:
targetType: inline
script: |
cd dictation_server
npm run test
env:
JWT_PUBLIC_KEY: $(token-public-key)
JWT_PRIVATE_KEY: $(token-private-key)
SENDGRID_API_KEY: $(sendgrid-api-key)
NOTIFICATION_HUB_NAME: $(notification-hub-name)
NOTIFICATION_HUB_CONNECT_STRING: $(notification-hub-connect-string)
STORAGE_ACCOUNT_NAME_US: $(storage-account-name-us)
STORAGE_ACCOUNT_NAME_AU: $(storage-account-name-au)
STORAGE_ACCOUNT_NAME_EU: $(storage-account-name-eu)
STORAGE_ACCOUNT_KEY_US: $(storage-account-key-us)
STORAGE_ACCOUNT_KEY_AU: $(storage-account-key-au)
STORAGE_ACCOUNT_KEY_EU: $(storage-account-key-eu)
STORAGE_ACCOUNT_ENDPOINT_US: $(storage-account-endpoint-us)
STORAGE_ACCOUNT_ENDPOINT_AU: $(storage-account-endpoint-au)
STORAGE_ACCOUNT_ENDPOINT_EU: $(storage-account-endpoint-eu)
ADB2C_TENANT_ID: $(adb2c-tenant-id)
ADB2C_CLIENT_ID: $(adb2c-client-id)
ADB2C_CLIENT_SECRET: $(adb2c-client-secret)
MAIL_FROM: xxxxxx
APP_DOMAIN: xxxxxxxxx
EMAIL_CONFIRM_LIFETIME: 0
TENANT_NAME: xxxxxxxxxxxx
SIGNIN_FLOW_NAME: xxxxxxxxxxxx
STORAGE_TOKEN_EXPIRE_TIME: 0
REFRESH_TOKEN_LIFETIME_WEB: 86400000
REFRESH_TOKEN_LIFETIME_DEFAULT: 2592000000
ACCESS_TOKEN_LIFETIME_WEB: 7200000
REDIS_HOST: xxxxxxxxxxxx
REDIS_PORT: 0
REDIS_PASSWORD: xxxxxxxxxxxx
ADB2C_CACHE_TTL: 0
STAGE: local
- task: Docker@0
displayName: build
inputs:

View File

@ -51,8 +51,6 @@ export const HEADER_MENUS: {
},
];
export const HEADER_NAME = "ODMS Cloud";
/**
* adminのみに表示するヘッダータブ
*/

View File

@ -17,7 +17,6 @@ import { getFilteredMenus } from "./utils";
import logo from "../../assets/images/OMS_logo_black.svg";
import ac from "../../assets/images/account_circle.svg";
import { LoginedPaths } from "./types";
import { HEADER_NAME } from "./constants";
import logout from "../../assets/images/logout.svg";
import { getTranslationID } from "../../translation";
@ -74,7 +73,6 @@ const LoginedHeader: React.FC<HeaderProps> = (props: HeaderProps) => {
<div className={styles.headerLogo}>
<img src={logo} alt="OM System" />
</div>
<div className={styles.headerSub}>{HEADER_NAME}</div>
<div className={styles.headerMenu}>
<ul>
{filterMenus.map((x) => (

View File

@ -1,7 +1,6 @@
import React from "react";
import styles from "styles/app.module.scss";
import logo from "../../assets/images/OMS_logo_black.svg";
import { HEADER_NAME } from "./constants";
interface NotLoginHeaderProps {
isMobile?: boolean;
@ -16,7 +15,6 @@ const NotLoginHeader: React.FC<NotLoginHeaderProps> = (
<div className={`${styles.headerLogo}`}>
<img src={logo} alt="OM System" />
</div>
<p className={`${styles.headerSub}`}>{HEADER_NAME}</p>
</header>
);
};

View File

@ -11,3 +11,9 @@ export const LICENSE_ALLOCATE_STATUS = {
ALLOCATED: "Allocated",
NOTALLOCATED: "Not Allocated",
} as const;
// NoLicenseの表示
export const NO_LICENSE = "No License" as const;
// ライセンスが割り当てられている場合の表示
export const LICENSE_NORMAL = "License Assigned" as const;

View File

@ -3,6 +3,7 @@ import { USER_ROLES } from "components/auth/constants";
import { convertLocalToUTCDate } from "common/convertLocalToUTCDate";
import {
AddUser,
LicenseStatusType,
RoleType,
UserView,
isLicenseStatusType,
@ -163,6 +164,12 @@ export const selectUserViews = (state: RootState): UserView[] => {
prompt,
typistGroupName
);
// licenseStatus,remaining,expirationの値を変換する
const {
licenseStatus: convertedLicenseStatus,
expiration: convertedExpiration,
remaining: convertedRemaining,
} = convertValueBasedOnLicenseStatus(licenseStatus, expiration, remaining);
// restのid以外をUserViewに追加する
return {
typistGroupName: convertedValues.typistGroupName,
@ -171,10 +178,9 @@ export const selectUserViews = (state: RootState): UserView[] => {
authorId: convertedValues.authorId,
// roleの一文字目を大文字に変換する
role: role.charAt(0).toUpperCase() + role.slice(1),
licenseStatus:
licenseStatus === LICENSE_STATUS.NORMAL ? "-" : licenseStatus,
expiration: expiration ?? "-",
remaining: remaining ?? "-",
licenseStatus: convertedLicenseStatus,
expiration: convertedExpiration,
remaining: convertedRemaining,
...rest,
};
});
@ -254,7 +260,7 @@ export const selectLicenseAllocateUserExpirationDate = (state: RootState) => {
return "-";
}
return `${expiration}(${remaining})`;
return `${expiration ?? "-"}(${remaining ?? "-"})`;
};
export const selectSelectedlicenseId = (state: RootState) =>
@ -328,3 +334,47 @@ const calculateExpiryDate = (expiryDate: string) => {
return `${formattedExpirationDate} (${daysDifference})`;
};
// licenseStatus,remainingに応じて値を変換する
const convertValueBasedOnLicenseStatus = (
licenseStatus: LicenseStatusType,
expiration?: string,
remaining?: number
): {
licenseStatus: LicenseStatusType;
expiration?: string;
remaining?: number;
} => {
if (licenseStatus === LICENSE_STATUS.NOLICENSE) {
return {
licenseStatus,
expiration: undefined,
remaining: undefined,
};
}
// remainingが存在し、かつ負の値である場合は、NoLicenseとする
if (remaining && remaining < 0) {
return {
licenseStatus: LICENSE_STATUS.NOLICENSE,
expiration: undefined,
remaining: undefined,
};
}
if (
licenseStatus === LICENSE_STATUS.RENEW ||
licenseStatus === LICENSE_STATUS.NORMAL ||
licenseStatus === LICENSE_STATUS.ALERT
) {
return {
licenseStatus,
expiration,
remaining,
};
}
// ここに到達することはない
return {
licenseStatus,
expiration: undefined,
remaining: undefined,
};
};

View File

@ -4,14 +4,11 @@ import { LICENSE_STATUS } from "./constants";
// 画面表示用のUserの型を独自に定義
export interface UserView
extends Omit<
User,
"typistGroupName" | "prompt" | "encryption" | "remaining"
> {
extends Omit<User, "typistGroupName" | "prompt" | "encryption"> {
authorId: string;
typistGroupName: string[] | string;
role: string;
licenseStatus: LicenseStatusType | string;
licenseStatus: LicenseStatusType;
prompt: boolean | string;
encryption: boolean | string;
emailVerified: boolean;
@ -19,8 +16,8 @@ export interface UserView
notification: boolean;
name: string;
email: string;
expiration: string;
remaining: number | string;
expiration?: string;
remaining?: number;
}
export interface AddUser {
name: string;
@ -53,8 +50,8 @@ export interface LicenseAllocateUser {
email: string;
authorId: string;
licenseStatus: LicenseStatusType | string;
expiration: string;
remaining: number | string;
expiration?: string;
remaining?: number;
}
export type RoleType = typeof USER_ROLES[keyof typeof USER_ROLES];

View File

@ -54,8 +54,8 @@ const initialState: UsersState = {
email: "",
authorId: "",
licenseStatus: "",
expiration: "",
remaining: "",
expiration: undefined,
remaining: undefined,
},
selectedlicenseId: 0,
hasPasswordMask: false,

View File

@ -13,8 +13,12 @@ import {
} from "features/user";
import { useTranslation } from "react-i18next";
import { getTranslationID } from "translation";
import { isLicenseStatusType, UserView } from "features/user/types";
import { LICENSE_STATUS } from "features/user/constants";
import { LicenseStatusType, UserView } from "features/user/types";
import {
LICENSE_NORMAL,
LICENSE_STATUS,
NO_LICENSE,
} from "features/user/constants";
import { isApproveTier } from "features/auth";
import { TIERS } from "components/auth/constants";
import {
@ -184,66 +188,63 @@ const UserListPage: React.FC = (): JSX.Element => {
</th>
</tr>
{!isLoading &&
users.map((user) => {
const { isAlertLicenseStatus, isAlertRemaining } =
isAlertElement(user.licenseStatus);
return (
<tr key={user.email}>
<td className={styles.clm0}>
<ul className={styles.menuInTable}>
<li>
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions */}
<a
onClick={() => {
onUpdateOpen(user.id);
}}
>
{t(
getTranslationID(
"userListPage.label.editUser"
)
)}
</a>
</li>
{isTier5 && (
<>
<li>
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions */}
<a
onClick={() => {
onAllocateLicensePopupOpen(user);
}}
>
{t(
getTranslationID(
"userListPage.label.licenseAllocation"
)
)}
</a>
</li>
<li>
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions */}
<a
className={
user.licenseStatus ===
LICENSE_STATUS.NOLICENSE
? styles.isDisable
: ""
}
onClick={() => {
onLicenseDeallocation(user.id);
}}
>
{t(
getTranslationID(
"userListPage.label.licenseDeallocation"
)
)}
</a>
</li>
</>
)}
{/* CCB
users.map((user) => (
<tr key={user.email}>
<td className={styles.clm0}>
<ul className={styles.menuInTable}>
<li>
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions */}
<a
onClick={() => {
onUpdateOpen(user.id);
}}
>
{t(
getTranslationID(
"userListPage.label.editUser"
)
)}
</a>
</li>
{isTier5 && (
<>
<li>
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions */}
<a
onClick={() => {
onAllocateLicensePopupOpen(user);
}}
>
{t(
getTranslationID(
"userListPage.label.licenseAllocation"
)
)}
</a>
</li>
<li>
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions */}
<a
className={
user.licenseStatus ===
LICENSE_STATUS.NOLICENSE
? styles.isDisable
: ""
}
onClick={() => {
onLicenseDeallocation(user.id);
}}
>
{t(
getTranslationID(
"userListPage.label.licenseDeallocation"
)
)}
</a>
</li>
</>
)}
{/* CCB
<li>
<a href="">
{t(
@ -254,48 +255,55 @@ const UserListPage: React.FC = (): JSX.Element => {
</a>
</li>
*/}
</ul>
</td>
<td> {user.name}</td>
<td>{user.role}</td>
<td>{user.authorId}</td>
<td>{boolToElement(user.encryption)}</td>
<td>{boolToElement(user.prompt)}</td>
<td>{arrayToElement(user.typistGroupName)}</td>
<td>{user.email}</td>
<td>
<span
className={
isAlertLicenseStatus ? styles.isAlert : ""
}
>
{user.licenseStatus}
</span>
</td>
<td>
<span
className={
isAlertRemaining ? styles.isAlert : ""
}
>
{user.expiration}
</span>
</td>
<td>
<span
className={
isAlertRemaining ? styles.isAlert : ""
}
>
{user.remaining}
</span>
</td>
<td>{boolToElement(user.autoRenew)}</td>
<td>{boolToElement(user.notification)}</td>
<td>{boolToElement(user.emailVerified)}</td>
</tr>
);
})}
</ul>
</td>
<td> {user.name}</td>
<td>{user.role}</td>
<td>{user.authorId}</td>
<td>{boolToElement(user.encryption)}</td>
<td>{boolToElement(user.prompt)}</td>
<td>{arrayToElement(user.typistGroupName)}</td>
<td>{user.email}</td>
<td>
<span
className={
user.licenseStatus ===
LICENSE_STATUS.NOLICENSE ||
user.licenseStatus === LICENSE_STATUS.ALERT
? styles.isAlert
: ""
}
>
{getLicenseStatus(user.licenseStatus)}
</span>
</td>
<td>
<span
className={
user.licenseStatus === LICENSE_STATUS.ALERT
? styles.isAlert
: ""
}
>
{user.expiration ?? "-"}
</span>
</td>
<td>
<span
className={
user.licenseStatus === LICENSE_STATUS.ALERT
? styles.isAlert
: ""
}
>
{user.remaining ?? "-"}
</span>
</td>
<td>{boolToElement(user.autoRenew)}</td>
<td>{boolToElement(user.notification)}</td>
<td>{boolToElement(user.emailVerified)}</td>
</tr>
))}
</tbody>
</table>
{!isLoading && users.length === 0 && (
@ -352,38 +360,15 @@ const arrayToElement = (
));
};
const isAlertElement = (
licenseStatus: string
): {
isAlertLicenseStatus: boolean;
isAlertRemaining: boolean;
} => {
// licenseStatusの型がLicenseStatusTypeでない場合(Normal)、どちらもfalseにする
if (isLicenseStatusType(licenseStatus) === false) {
return {
isAlertLicenseStatus: false,
isAlertRemaining: false,
};
}
// licenseStatusがNOLICENSEの場合、isAlertLicenseStatusをtrueにする(Remainingはハイフン)
// ライセンスステータスに応じて、ライセンスステータスの文字列を返す
const getLicenseStatus = (licenseStatus: LicenseStatusType): string => {
if (licenseStatus === LICENSE_STATUS.NOLICENSE) {
return {
isAlertLicenseStatus: true,
isAlertRemaining: false,
};
return NO_LICENSE;
}
// licenseStatusがALERTの場合、どちらもtrueにする
if (licenseStatus === LICENSE_STATUS.ALERT) {
return {
isAlertLicenseStatus: true,
isAlertRemaining: true,
};
if (licenseStatus === LICENSE_STATUS.NORMAL) {
return LICENSE_NORMAL;
}
// licenseStatusがRENEWの場合、どちらもfalseにする
return {
isAlertLicenseStatus: false,
isAlertRemaining: false,
};
return licenseStatus;
};
export default UserListPage;

View File

@ -2,6 +2,7 @@ version: '3'
services:
dictation_server:
container_name: dictation_server_dev_container
env_file: ../.env
build: .
working_dir: /app/dictation_server
@ -16,6 +17,15 @@ services:
- CHOKIDAR_USEPOLLING=true
networks:
- external
test_mysql_db:
image: mysql:8.0-bullseye
environment:
MYSQL_ROOT_PASSWORD: root_password
MYSQL_DATABASE: odms
MYSQL_USER: user
MYSQL_PASSWORD: password
networks:
- external
networks:
external:
name: omds_network

View File

@ -0,0 +1,35 @@
version: '3'
services:
dictation_server:
container_name: dictation_server_dev_container
env_file: ../.env
build: .
working_dir: /app/dictation_server
ports:
- '8081:8081'
volumes:
- ../../:/app
- node_modules:/app/dictation_server/node_modules
expose:
- '8081'
environment:
- CHOKIDAR_USEPOLLING=true
depends_on:
- test_mysql_db
networks:
- network
test_mysql_db:
image: mysql:8.0-bullseye
environment:
MYSQL_ROOT_PASSWORD: root_password
MYSQL_DATABASE: odms
MYSQL_USER: user
MYSQL_PASSWORD: password
networks:
- network
networks:
network:
name: test_network
volumes:
node_modules:

View File

@ -0,0 +1,37 @@
STAGE=local
NO_COLOR=TRUE
CORS=TRUE
PORT=8081
TENANT_NAME=xxxxxxxxxx
SIGNIN_FLOW_NAME=b2c_1_signin_xxx
ADB2C_TENANT_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
ADB2C_CLIENT_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
ADB2C_CLIENT_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
ADB2C_ORIGIN=https://example.com/xxxxxxxxx.onmicrosoft.com/b2c_1_signin_xxx/
KEY_VAULT_NAME=xxxxxxxxxxxx
JWT_PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEA5IZZNgDew9eGmuFTezwdHYLSaJvUPPIKYoiOeVLD1paWNI51\n7Vkaoh0ngprcKOdv6T1N07V4igK7mOim2zY3yCTR6wcWR3PfFJrl9vh5SOo79koZ\noJb27YiM4jtxfx2dezzp0T2GoNR5rRolPUbWFJXnDe0DVXYXpJLb4LAlF2XAyYX0\nSYKUVUsJnzm5k4xbXtnwPwVbpm0EdswBE6qSfiL9zWk9dvHoKzSnfSDzDFoFcEoV\nchawzYXf/MM1YR4wo5XyzECc6Q5Ah4z522//mBNNaDHv83Yuw3mGShT73iJ0JQdk\nTturshv2Ecma38r6ftrIwNYXw4VVatJM8+GOOQIDAQABAoIBADrwp7u097+dK/tw\nWD61n3DIGAqg/lmFt8X4IH8MKLSE/FKr16CS1bqwOEuIM3ZdUtDeXd9Xs7IsyEPE\n5ZwuXK7DSF0M4+Mj8Ip49Q0Aww9aUoLQU9HGfgN/r4599GTrt31clZXA/6Mlighq\ncOZgCcEfdItz8OMu5SQuOIW4CKkCuaWnPOP26UqZocaXNZfpZH0iFLATMMH/TT8x\nay9ToHTQYE17ijdQ/EOLSwoeDV1CU1CIE3P4YfLJjvpKptly5dTevriHEzBi70Jx\n/KEPUn9Jj2gZafrUxRVhmMbm1zkeYxL3gsqRuTzRjEeeILuZhSJyCkQZyUNARxsg\nQY4DZfECgYEA+YLKUtmYTx60FS6DJ4s31TAsXY8kwhq/lB9E3GBZKDd0DPayXEeK\n4UWRQDTT6MI6fedW69FOZJ5sFLp8HQpcssb4Weq9PCpDhNTx8MCbdH3Um5QR3vfW\naKq/1XM8MDUnx5XcNYd87Aw3azvJAvOPr69as8IPnj6sKaRR9uQjbYUCgYEA6nfV\n5j0qmn0EJXZJblk4mvvjLLoWSs17j9YlrZJlJxXMDFRYtgnelv73xMxOMvcGoxn5\nifs7dpaM2x5EmA6jVU5sYaB/beZGEPWqPYGyjIwXPvUGAAv8Gbnvpp+xlSco/Dum\nIq0w+43ry5/xWh6CjfrvKV0J2bDOiJwPEdu/8iUCgYEAnBBSvL+dpN9vhFAzeOh7\nY71eAqcmNsLEUcG9MJqTKbSFwhYMOewF0iHRWHeylEPokhfBJn8kqYrtz4lVWFTC\n5o/Nh3BsLNXCpbMMIapXkeWiti1HgE9ErPMgSkJpwz18RDpYIqM8X+jEQS6D7HSr\nyxfDg+w+GJza0rEVE3hfMIECgYBw+KZ2VfhmEWBjEHhXE+QjQMR3s320MwebCUqE\nNCpKx8TWF/naVC0MwfLtvqbbBY0MHyLN6d//xpA9r3rLbRojqzKrY2KiuDYAS+3n\nzssRzxoQOozWju+8EYu30/ADdqfXyIHG6X3VZs87AGiQzGyJLmP3oR1y5y7MQa09\nJI16hQKBgHK5uwJhGa281Oo5/FwQ3uYLymbNwSGrsOJXiEu2XwJEXwVi2ELOKh4/\n03pBk3Kva3fIwEK+vCzDNnxShIQqBE76/2I1K1whOfoUehhYvKHGaXl2j70Zz9Ks\nrkGW1cx7p+yDqATDrwHBHTHFh5bUTTn8dN40n0e0W/llurpbBkJM\n-----END RSA PRIVATE KEY-----\n"
JWT_PUBLIC_KEY="-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA5IZZNgDew9eGmuFTezwd\nHYLSaJvUPPIKYoiOeVLD1paWNI517Vkaoh0ngprcKOdv6T1N07V4igK7mOim2zY3\nyCTR6wcWR3PfFJrl9vh5SOo79koZoJb27YiM4jtxfx2dezzp0T2GoNR5rRolPUbW\nFJXnDe0DVXYXpJLb4LAlF2XAyYX0SYKUVUsJnzm5k4xbXtnwPwVbpm0EdswBE6qS\nfiL9zWk9dvHoKzSnfSDzDFoFcEoVchawzYXf/MM1YR4wo5XyzECc6Q5Ah4z522//\nmBNNaDHv83Yuw3mGShT73iJ0JQdkTturshv2Ecma38r6ftrIwNYXw4VVatJM8+GO\nOQIDAQAB\n-----END PUBLIC KEY-----\n"
SENDGRID_API_KEY=SG.P_xxxx_xxxxxxxxxxxxxxx.xxxxxxxxxxxxxxx_xxxxxxxxxxxxxxxxxxxxxxxx-pc
MAIL_FROM=noreply@example.com
NOTIFICATION_HUB_NAME=ntf-odms-dev
NOTIFICATION_HUB_CONNECT_STRING=Endpoint=sb://example.com/;SharedAccessKeyName=DefaultFullSharedAccessSignature;SharedAccessKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX=
APP_DOMAIN=http://localhost:8081/
STORAGE_TOKEN_EXPIRE_TIME=30
STORAGE_ACCOUNT_NAME_US=saxxxxusxxx
STORAGE_ACCOUNT_NAME_AU=saxxxxauxxx
STORAGE_ACCOUNT_NAME_EU=saxxxxeuxxx
STORAGE_ACCOUNT_KEY_US=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX==
STORAGE_ACCOUNT_KEY_AU=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX==
STORAGE_ACCOUNT_KEY_EU=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX==
STORAGE_ACCOUNT_ENDPOINT_US=https://xxxxxxxxxxxx.blob.core.windows.net/
STORAGE_ACCOUNT_ENDPOINT_AU=https://xxxxxxxxxxxx.blob.core.windows.net/
STORAGE_ACCOUNT_ENDPOINT_EU=https://xxxxxxxxxxxx.blob.core.windows.net/
ACCESS_TOKEN_LIFETIME_WEB=7200000
REFRESH_TOKEN_LIFETIME_WEB=86400000
REFRESH_TOKEN_LIFETIME_DEFAULT=2592000000
EMAIL_CONFIRM_LIFETIME=86400000
REDIS_HOST=redis-cache
REDIS_PORT=6379
REDIS_PASSWORD=omdsredispass
ADB2C_CACHE_TTL=86400
TEMPLATE_ROOT=dist

View File

@ -6,3 +6,7 @@ ci:
dialect: mysql
dir: ./dictation_server/db/migrations
datasource: DB_USERNAME:DB_PASS@tcp(DB_HOST:DB_PORT)/DB_NAME?charset=utf8mb4&collation=utf8mb4_0900_ai_ci&parseTime=true
test:
dialect: mysql
dir: /app/dictation_server/db/migrations
datasource: user:password@tcp(test_mysql_db:3306)/odms?charset=utf8mb4&collation=utf8mb4_0900_ai_ci&parseTime=true

View File

@ -0,0 +1,6 @@
-- +migrate Up
ALTER TABLE `users_archive` DROP COLUMN `license_alert`;
-- +migrate Down
ALTER TABLE `users_archive` ADD COLUMN `license_alert` BOOLEAN NOT NULL COMMENT 'ライセンスの期限切れ通知をするかどうか';

View File

@ -17,7 +17,7 @@
"tc": "tsc --noEmit",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\"",
"lint:fix": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test": "jest -w 1",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
@ -26,7 +26,8 @@
"openapi-format": "cat \"src/api/odms/openapi.json\" | jq -c . > \"src/api/odms/openapi.json\" && prettier --write \"src/api/odms/*.json\"",
"migrate:up": "sql-migrate up -config=/app/dictation_server/db/dbconfig.yml -env=local",
"migrate:down": "sql-migrate down -config=/app/dictation_server/db/dbconfig.yml -env=local",
"migrate:status": "sql-migrate status -config=/app/dictation_server/db/dbconfig.yml -env=local"
"migrate:status": "sql-migrate status -config=/app/dictation_server/db/dbconfig.yml -env=local",
"migrate:up:test": "sql-migrate up -config=/app/dictation_server/db/dbconfig.yml -env=test"
},
"dependencies": {
"@azure/identity": "^3.1.3",

View File

@ -0,0 +1,21 @@
import { DataSource } from 'typeorm';
export const truncateAllTable = async (source: DataSource) => {
const entities = source.entityMetadatas;
const queryRunner = source.createQueryRunner();
try {
await queryRunner.startTransaction();
await queryRunner.query('SET FOREIGN_KEY_CHECKS=0');
for (const entity of entities) {
await queryRunner.query(`TRUNCATE TABLE \`${entity.tableName}\``);
}
await queryRunner.query('SET FOREIGN_KEY_CHECKS=1');
await queryRunner.commitTransaction();
} catch (err) {
await queryRunner.rollbackTransaction();
throw err;
} finally {
await queryRunner.release();
}
};

View File

@ -48,7 +48,7 @@ export const makeTestingModule = async (
const module: TestingModule = await Test.createTestingModule({
imports: [
ConfigModule.forRoot({
envFilePath: ['.env.local', '.env'],
envFilePath: ['.env.test', '.env'],
isGlobal: true,
}),
AuthModule,

View File

@ -88,6 +88,16 @@ export const USER_ROLES = {
TYPIST: 'typist',
} as const;
/**
*
* @const {string[]}
*/
export const USER_ROLE_ORDERS = [
USER_ROLES.AUTHOR,
USER_ROLES.TYPIST,
USER_ROLES.NONE,
] as string[];
/**
*
* @const {string[]}

View File

@ -13,7 +13,7 @@ describe('AccountsController', () => {
const module: TestingModule = await Test.createTestingModule({
imports: [
ConfigModule.forRoot({
envFilePath: ['.env.local', '.env'],
envFilePath: ['.env.test', '.env'],
isGlobal: true,
}),
],

View File

@ -14,7 +14,7 @@ describe('AuthController', () => {
const module: TestingModule = await Test.createTestingModule({
imports: [
ConfigModule.forRoot({
envFilePath: ['.env.local', '.env'],
envFilePath: ['.env.test', '.env'],
isGlobal: true,
}),
],

View File

@ -20,6 +20,7 @@ import { v4 as uuidv4 } from 'uuid';
import { TIERS, USER_ROLES } from '../../constants';
import { decode, isVerifyError } from '../../common/jwt';
import { RefreshToken, AccessToken } from '../../common/token';
import { truncateAllTable } from '../../common/test/init';
describe('AuthService', () => {
it('IDトークンの検証とペイロードの取得に成功する', async () => {
@ -162,20 +163,32 @@ describe('AuthService', () => {
describe('checkIsAcceptedLatestVersion', () => {
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();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});
it('同意済み利用規約バージョンが最新のときにチェックが通ること(第五)', async () => {
@ -325,20 +338,32 @@ describe('checkIsAcceptedLatestVersion', () => {
describe('generateDelegationRefreshToken', () => {
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();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});
it('代行操作が許可されたパートナーの代行操作用リフレッシュトークンを取得できること', async () => {
@ -459,20 +484,32 @@ describe('generateDelegationRefreshToken', () => {
describe('generateDelegationAccessToken', () => {
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();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});
it('代行操作用リフレッシュトークンから代行操作用アクセストークンを取得できること', async () => {
@ -558,20 +595,32 @@ describe('generateDelegationAccessToken', () => {
describe('updateDelegationAccessToken', () => {
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();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});
@ -743,7 +792,7 @@ describe('updateDelegationAccessToken', () => {
}
// 代行操作対象アカウントを削除
deleteAccount(source, partnerAccount.id);
await deleteAccount(source, partnerAccount.id);
try {
await service.updateDelegationAccessToken(

View File

@ -10,7 +10,7 @@ describe('FilesController', () => {
const module: TestingModule = await Test.createTestingModule({
imports: [
ConfigModule.forRoot({
envFilePath: ['.env.local', '.env'],
envFilePath: ['.env.test', '.env'],
isGlobal: true,
}),
],

View File

@ -40,23 +40,36 @@ import {
TASK_STATUS,
USER_ROLES,
} from '../../constants';
import { truncateAllTable } from '../../common/test/init';
describe('publishUploadSas', () => {
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();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});
@ -287,20 +300,32 @@ describe('publishUploadSas', () => {
describe('タスク作成から自動ルーティング(DB使用)', () => {
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();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});
it('タスク作成時に、自動ルーティングを行うことができるAPIの引数として渡されたAuthorIDとworkType', async () => {
@ -997,20 +1022,32 @@ describe('タスク作成から自動ルーティング(DB使用)', () => {
describe('音声ファイルダウンロードURL取得', () => {
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();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});
@ -1490,20 +1527,32 @@ describe('音声ファイルダウンロードURL取得', () => {
describe('テンプレートファイルダウンロードURL取得', () => {
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();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});
@ -1933,20 +1982,32 @@ describe('テンプレートファイルダウンロードURL取得', () => {
describe('publishTemplateFileUploadSas', () => {
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();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});
@ -2036,20 +2097,32 @@ describe('publishTemplateFileUploadSas', () => {
describe('templateUploadFinished', () => {
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();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});

View File

@ -152,7 +152,7 @@ export const makeTestingModuleWithBlobAndNotification = async (
const module: TestingModule = await Test.createTestingModule({
imports: [
ConfigModule.forRoot({
envFilePath: ['.env.local', '.env'],
envFilePath: ['.env.test', '.env'],
isGlobal: true,
}),
AuthModule,

View File

@ -11,7 +11,7 @@ describe('LicensesController', () => {
const module: TestingModule = await Test.createTestingModule({
imports: [
ConfigModule.forRoot({
envFilePath: ['.env.local', '.env'],
envFilePath: ['.env.test', '.env'],
isGlobal: true,
}),
],

View File

@ -26,23 +26,36 @@ import {
} from '../../common/test/utility';
import { LicensesRepositoryService } from '../../repositories/licenses/licenses.repository.service';
import { overrideSendgridService } from '../../common/test/overrides';
import { truncateAllTable } from '../../common/test/init';
describe('ライセンス注文', () => {
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();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});
@ -190,20 +203,32 @@ describe('ライセンス注文', () => {
describe('カードライセンス発行', () => {
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();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});
@ -268,20 +293,32 @@ describe('カードライセンス発行', () => {
describe('カードライセンスを取り込む', () => {
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();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});
it('カードライセンス取り込みが完了する', async () => {
@ -601,20 +638,32 @@ describe('カードライセンスを取り込む', () => {
describe('ライセンス割り当て', () => {
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();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});
@ -702,6 +751,7 @@ describe('ライセンス割り当て', () => {
});
const date = new Date();
date.setDate(date.getDate() + 30);
date.setMilliseconds(0);
await createLicense(
source,
1,
@ -768,6 +818,8 @@ describe('ライセンス割り当て', () => {
});
const date = new Date();
date.setDate(date.getDate() + 30);
date.setMilliseconds(0);
await createLicense(
source,
1,
@ -874,6 +926,7 @@ describe('ライセンス割り当て', () => {
});
const date = new Date();
date.setDate(date.getDate() + 30);
date.setMilliseconds(0);
await createLicense(
source,
1,
@ -939,6 +992,7 @@ describe('ライセンス割り当て', () => {
});
const date = new Date();
date.setDate(date.getDate() + 30);
date.setMilliseconds(0);
await createLicense(
source,
1,
@ -1004,6 +1058,7 @@ describe('ライセンス割り当て', () => {
});
const date = new Date();
date.setDate(date.getDate() + 30);
date.setMilliseconds(0);
await createLicense(
source,
1,
@ -1069,6 +1124,7 @@ describe('ライセンス割り当て', () => {
});
const date = new Date();
date.setDate(date.getDate() - 30);
date.setMilliseconds(0);
await createLicense(
source,
1,
@ -1110,6 +1166,7 @@ describe('ライセンス割り当て', () => {
});
const date = new Date();
date.setDate(date.getDate() + 30);
date.setMilliseconds(0);
await createLicense(
source,
1,
@ -1161,20 +1218,32 @@ describe('ライセンス割り当て', () => {
describe('ライセンス割り当て解除', () => {
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();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});
@ -1192,6 +1261,7 @@ describe('ライセンス割り当て解除', () => {
});
const date = new Date();
date.setDate(date.getDate() + 30);
date.setMilliseconds(0);
await createLicense(
source,
1,
@ -1271,6 +1341,7 @@ describe('ライセンス割り当て解除', () => {
});
const date = new Date();
date.setDate(date.getDate() + 30);
date.setMilliseconds(0);
await createLicense(
source,
1,
@ -1316,20 +1387,32 @@ describe('ライセンス割り当て解除', () => {
describe('ライセンス注文キャンセル', () => {
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();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});

View File

@ -172,6 +172,7 @@ export const selectLicenseAllocationHistory = async (
license_id: licence_id,
},
order: {
id: 'DESC',
executed_at: 'DESC',
},
});

View File

@ -10,7 +10,7 @@ describe('NotificationController', () => {
const module: TestingModule = await Test.createTestingModule({
imports: [
ConfigModule.forRoot({
envFilePath: ['.env.local', '.env'],
envFilePath: ['.env.test', '.env'],
isGlobal: true,
}),
],

View File

@ -21,7 +21,7 @@ export const makeNotificationServiceMock = async (
providers: [NotificationService],
imports: [
ConfigModule.forRoot({
envFilePath: ['.env.local', '.env'],
envFilePath: ['.env.test', '.env'],
}),
],
})

View File

@ -10,7 +10,7 @@ describe('TasksController', () => {
const module: TestingModule = await Test.createTestingModule({
imports: [
ConfigModule.forRoot({
envFilePath: ['.env.local', '.env'],
envFilePath: ['.env.test', '.env'],
isGlobal: true,
}),
],

View File

@ -37,6 +37,7 @@ import { createTemplateFile } from '../templates/test/utility';
import { NotificationhubService } from '../../gateways/notificationhub/notificationhub.service';
import { Roles } from '../../common/types/role';
import { TasksRepositoryService } from '../../repositories/tasks/tasks.repository.service';
import { truncateAllTable } from '../../common/test/init';
describe('TasksService', () => {
it('タスク一覧を取得できるadmin', async () => {
@ -584,20 +585,32 @@ describe('TasksService', () => {
describe('DBテスト', () => {
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();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});
@ -775,20 +788,32 @@ describe('TasksService', () => {
describe('changeCheckoutPermission', () => {
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();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});
@ -1405,20 +1430,32 @@ describe('changeCheckoutPermission', () => {
describe('checkout', () => {
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();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});
@ -1605,7 +1642,6 @@ describe('checkout', () => {
account_id: accountId,
external_id: 'typist-user-external-id',
role: 'typist',
author_id: 'MY_AUTHOR_ID',
});
const { id: authorUserId } = await makeTestUser(source, {
account_id: accountId,
@ -1652,7 +1688,6 @@ describe('checkout', () => {
account_id: accountId,
external_id: 'typist-user-external-id',
role: 'typist',
author_id: 'MY_AUTHOR_ID',
});
const { id: authorUserId } = await makeTestUser(source, {
account_id: accountId,
@ -1989,20 +2024,32 @@ describe('checkout', () => {
describe('checkin', () => {
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();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});
@ -2192,20 +2239,32 @@ describe('checkin', () => {
describe('suspend', () => {
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();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});
@ -2391,20 +2450,32 @@ describe('suspend', () => {
describe('cancel', () => {
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();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});
@ -3007,20 +3078,32 @@ describe('cancel', () => {
describe('backup', () => {
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();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});
@ -3301,20 +3384,32 @@ describe('backup', () => {
describe('getNextTask', () => {
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();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});

View File

@ -47,7 +47,7 @@ export const makeTaskTestingModuleWithNotificaiton = async (
const module: TestingModule = await Test.createTestingModule({
imports: [
ConfigModule.forRoot({
envFilePath: ['.env.local', '.env'],
envFilePath: ['.env.test', '.env'],
isGlobal: true,
}),
AuthModule,

View File

@ -10,7 +10,7 @@ describe('TemplatesController', () => {
const module: TestingModule = await Test.createTestingModule({
imports: [
ConfigModule.forRoot({
envFilePath: ['.env.local', '.env'],
envFilePath: ['.env.test', '.env'],
isGlobal: true,
}),
],

View File

@ -7,24 +7,37 @@ import { makeContext } from '../../common/log';
import { TemplateFilesRepositoryService } from '../../repositories/template_files/template_files.repository.service';
import { HttpException, HttpStatus } from '@nestjs/common';
import { makeErrorResponse } from '../../common/error/makeErrorResponse';
import { truncateAllTable } from '../../common/test/init';
describe('getTemplates', () => {
let source: DataSource | undefined = undefined;
beforeEach(async () => {
source = new DataSource({
type: 'sqlite',
database: ':memory:',
logging: false,
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: true, // trueにすると自動的にmigrationが行われるため注意
});
return source.initialize();
let source: DataSource | null = null;
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
source = undefined;
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});
it('テンプレートファイル一覧を取得できる', async () => {

View File

@ -6,23 +6,36 @@ import { makeContext } from '../../common/log';
import { v4 as uuidv4 } from 'uuid';
import { HttpException, HttpStatus } from '@nestjs/common';
import { makeErrorResponse } from '../../common/error/makeErrorResponse';
import { truncateAllTable } from '../../common/test/init';
describe('利用規約取得', () => {
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();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});

View File

@ -67,7 +67,7 @@ export const makeUsersServiceMock = async (
providers: [UsersService],
imports: [
ConfigModule.forRoot({
envFilePath: ['.env.local', '.env'],
envFilePath: ['.env.test', '.env'],
}),
],
})

View File

@ -113,7 +113,7 @@ export const makeTestingModuleWithAdb2c = async (
const module: TestingModule = await Test.createTestingModule({
imports: [
ConfigModule.forRoot({
envFilePath: ['.env.local', '.env'],
envFilePath: ['.env.test', '.env'],
isGlobal: true,
}),
AuthModule,

View File

@ -13,7 +13,7 @@ describe('UsersController', () => {
const module: TestingModule = await Test.createTestingModule({
imports: [
ConfigModule.forRoot({
envFilePath: ['.env.local', '.env'],
envFilePath: ['.env.test', '.env'],
isGlobal: true,
}),
],

View File

@ -1,5 +1,4 @@
import { HttpException, HttpStatus } from '@nestjs/common';
import { AccessToken } from '../../common/token';
import { makeErrorResponse } from '../../common/error/makeErrorResponse';
import {
makeDefaultAdB2cMockValue,
@ -47,21 +46,36 @@ import {
import { v4 as uuidv4 } from 'uuid';
import { createOptionItems, createWorktype } from '../accounts/test/utility';
import { createWorkflow, getWorkflows } from '../workflows/test/utility';
import { truncateAllTable } from '../../common/test/init';
describe('UsersService.confirmUser', () => {
let source: DataSource | null = null;
beforeEach(async () => {
source = new DataSource({
type: 'sqlite',
database: ':memory:',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: true, // trueにすると自動的にmigrationが行われるため注意
});
return source.initialize();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});
@ -420,20 +434,32 @@ describe('UsersService.confirmUserAndInitPassword', () => {
describe('UsersService.createUser', () => {
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();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});
@ -1365,20 +1391,32 @@ describe('UsersService.createUser', () => {
describe('UsersService.getUsers', () => {
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();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});
@ -1389,6 +1427,16 @@ describe('UsersService.getUsers', () => {
if (!module) fail();
const { id: accountId } = await makeTestSimpleAccount(source);
const { id: typistUserId } = await makeTestUser(source, {
account_id: accountId,
external_id: 'external_id2',
role: 'typist',
author_id: undefined,
auto_renew: true,
encryption: false,
encryption_password: undefined,
prompt: false,
});
const { external_id: externalId_author, id: authorUserId } =
await makeTestUser(source, {
account_id: accountId,
@ -1401,17 +1449,6 @@ describe('UsersService.getUsers', () => {
prompt: false,
});
const { id: typistUserId } = await makeTestUser(source, {
account_id: accountId,
external_id: 'external_id2',
role: 'typist',
author_id: undefined,
auto_renew: true,
encryption: false,
encryption_password: undefined,
prompt: false,
});
await createUserGroup(source, accountId, 'group1', [typistUserId]);
const { id: noneUserId } = await makeTestUser(source, {
@ -1843,20 +1880,32 @@ describe('UsersService.getSortCriteria', () => {
describe('UsersService.updateUser', () => {
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();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});
@ -2427,20 +2476,32 @@ describe('UsersService.updateUser', () => {
describe('UsersService.updateAcceptedVersion', () => {
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();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});
@ -2515,20 +2576,32 @@ describe('UsersService.updateAcceptedVersion', () => {
describe('UsersService.getUserName', () => {
let source: DataSource | null = null;
beforeEach(async () => {
source = new DataSource({
type: 'sqlite',
database: ':memory:',
logging: false,
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: true,
});
return source.initialize();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});
@ -2557,20 +2630,32 @@ describe('UsersService.getUserName', () => {
describe('UsersService.getRelations', () => {
let source: DataSource | null = null;
beforeEach(async () => {
source = new DataSource({
type: 'sqlite',
database: ':memory:',
logging: false,
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: true,
});
return source.initialize();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});
@ -2622,6 +2707,8 @@ describe('UsersService.getRelations', () => {
// 作成したデータを確認
{
const workflows = await getWorkflows(source, account.id);
workflows.sort((a, b) => a.id - b.id);
expect(workflows.length).toBe(4);
expect(workflows[0].worktype_id).toBe(worktype1.id);
expect(workflows[0].author_id).toBe(user1);

View File

@ -10,7 +10,7 @@ describe('WorkflowsController', () => {
const module: TestingModule = await Test.createTestingModule({
imports: [
ConfigModule.forRoot({
envFilePath: ['.env.local', '.env'],
envFilePath: ['.env.test', '.env'],
isGlobal: true,
}),
],

View File

@ -19,23 +19,36 @@ import { overrideAdB2cService } from '../../common/test/overrides';
import { WorkflowsRepositoryService } from '../../repositories/workflows/workflows.repository.service';
import { HttpException, HttpStatus } from '@nestjs/common';
import { makeErrorResponse } from '../../common/error/makeErrorResponse';
import { truncateAllTable } from '../../common/test/init';
describe('getWorkflows', () => {
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();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});
@ -47,22 +60,23 @@ describe('getWorkflows', () => {
const { account, admin } = await makeTestAccount(source, { tier: 5 });
const { id: authorId1 } = await makeTestUser(source, {
external_id: 'author1',
author_id: 'AUTHOR1',
author_id: 'BBBBB',
account_id: account.id,
role: USER_ROLES.AUTHOR,
});
const { id: authorId2 } = await makeTestUser(source, {
external_id: 'author2',
author_id: 'AUTHOR2',
author_id: 'AAAAA',
account_id: account.id,
role: USER_ROLES.AUTHOR,
});
const { id: authorId3 } = await makeTestUser(source, {
external_id: 'author3',
author_id: 'AUTHOR3',
author_id: 'CCCCC',
account_id: account.id,
role: USER_ROLES.AUTHOR,
});
const { id: typistId, external_id: typistExternalId } = await makeTestUser(
source,
{
@ -79,6 +93,12 @@ describe('getWorkflows', () => {
);
const { id: worktypeId1 } = await createWorktype(
source,
account.id,
'worktype2',
);
const { id: worktypeId2 } = await createWorktype(
source,
account.id,
'worktype1',
@ -95,7 +115,7 @@ describe('getWorkflows', () => {
source,
account.id,
authorId1,
worktypeId1,
worktypeId2,
templateId1,
);
const workflow2 = await createWorkflow(
@ -112,10 +132,18 @@ describe('getWorkflows', () => {
worktypeId1,
undefined,
);
const workflow4 = await createWorkflow(
source,
account.id,
authorId3,
worktypeId2,
undefined,
);
await createWorkflowTypist(source, workflow1.id, typistId, undefined);
await createWorkflowTypist(source, workflow2.id, undefined, userGroupId);
await createWorkflowTypist(source, workflow3.id, undefined, userGroupId);
await createWorkflowTypist(source, workflow4.id, undefined, userGroupId);
const service = module.get<WorkflowsService>(WorkflowsService);
const context = makeContext(admin.external_id, 'requestId');
@ -123,10 +151,10 @@ describe('getWorkflows', () => {
//作成したデータを確認
{
const workflows = await getWorkflows(source, account.id);
expect(workflows.length).toBe(3);
expect(workflows.length).toBe(4);
expect(workflows[0].id).toBe(workflow1.id);
expect(workflows[0].author_id).toBe(authorId1);
expect(workflows[0].worktype_id).toBe(worktypeId1);
expect(workflows[0].worktype_id).toBe(worktypeId2);
expect(workflows[0].template_id).toBe(templateId1);
expect(workflows[1].id).toBe(workflow2.id);
@ -138,6 +166,11 @@ describe('getWorkflows', () => {
expect(workflows[2].author_id).toBe(authorId3);
expect(workflows[2].worktype_id).toBe(worktypeId1);
expect(workflows[2].template_id).toBe(null);
expect(workflows[3].id).toBe(workflow4.id);
expect(workflows[3].author_id).toBe(authorId3);
expect(workflows[3].worktype_id).toBe(worktypeId2);
expect(workflows[3].template_id).toBe(null);
}
overrideAdB2cService(service, {
@ -148,37 +181,48 @@ describe('getWorkflows', () => {
//実行結果を確認
{
expect(resWorkflows.length).toBe(3);
expect(resWorkflows[0].id).toBe(workflow1.id);
expect(resWorkflows[0].author.id).toBe(authorId1);
expect(resWorkflows[0].author.authorId).toBe('AUTHOR1');
expect(resWorkflows[0].worktype?.id).toBe(worktypeId1);
expect(resWorkflows[0].worktype?.worktypeId).toBe('worktype1');
expect(resWorkflows.length).toBe(4);
expect(resWorkflows[0].id).toBe(workflow2.id);
expect(resWorkflows[0].author.id).toBe(authorId2);
expect(resWorkflows[0].author.authorId).toBe('AAAAA');
expect(resWorkflows[0].worktype).toBe(undefined);
expect(resWorkflows[0].template?.id).toBe(templateId1);
expect(resWorkflows[0].template?.fileName).toBe('fileName1');
expect(resWorkflows[0].typists.length).toBe(1);
expect(resWorkflows[0].typists[0].typistUserId).toBe(typistId);
expect(resWorkflows[0].typists[0].typistName).toBe('typist1');
expect(resWorkflows[0].typists[0].typistGroupId).toBe(userGroupId);
expect(resWorkflows[0].typists[0].typistName).toBe('group1');
expect(resWorkflows[1].id).toBe(workflow2.id);
expect(resWorkflows[1].author.id).toBe(authorId2);
expect(resWorkflows[1].author.authorId).toBe('AUTHOR2');
expect(resWorkflows[1].worktype).toBe(undefined);
expect(resWorkflows[1].id).toBe(workflow1.id);
expect(resWorkflows[1].author.id).toBe(authorId1);
expect(resWorkflows[1].author.authorId).toBe('BBBBB');
expect(resWorkflows[1].worktype?.id).toBe(worktypeId2);
expect(resWorkflows[1].worktype?.worktypeId).toBe('worktype1');
expect(resWorkflows[1].template?.id).toBe(templateId1);
expect(resWorkflows[1].template?.fileName).toBe('fileName1');
expect(resWorkflows[1].typists.length).toBe(1);
expect(resWorkflows[1].typists[0].typistGroupId).toBe(userGroupId);
expect(resWorkflows[1].typists[0].typistName).toBe('group1');
expect(resWorkflows[1].typists[0].typistUserId).toBe(typistId);
expect(resWorkflows[1].typists[0].typistName).toBe('typist1');
expect(resWorkflows[2].id).toBe(workflow3.id);
expect(resWorkflows[2].id).toBe(workflow4.id);
expect(resWorkflows[2].author.id).toBe(authorId3);
expect(resWorkflows[2].author.authorId).toBe('AUTHOR3');
expect(resWorkflows[2].worktype?.id).toBe(worktypeId1);
expect(resWorkflows[2].author.authorId).toBe('CCCCC');
expect(resWorkflows[2].worktype?.id).toBe(worktypeId2);
expect(resWorkflows[2].worktype?.worktypeId).toBe('worktype1');
expect(resWorkflows[2].template).toBe(undefined);
expect(resWorkflows[2].typists.length).toBe(1);
expect(resWorkflows[2].typists[0].typistGroupId).toBe(userGroupId);
expect(resWorkflows[2].typists[0].typistName).toBe('group1');
expect(resWorkflows[3].id).toBe(workflow3.id);
expect(resWorkflows[3].author.id).toBe(authorId3);
expect(resWorkflows[3].author.authorId).toBe('CCCCC');
expect(resWorkflows[3].worktype?.id).toBe(worktypeId1);
expect(resWorkflows[3].worktype?.worktypeId).toBe('worktype2');
expect(resWorkflows[3].template).toBe(undefined);
expect(resWorkflows[3].typists.length).toBe(1);
expect(resWorkflows[3].typists[0].typistGroupId).toBe(userGroupId);
expect(resWorkflows[3].typists[0].typistName).toBe('group1');
}
});
@ -209,7 +253,7 @@ describe('getWorkflows', () => {
const module = await makeTestingModule(source);
if (!module) fail();
// 第五階層のアカウント作成
const { account, admin } = await makeTestAccount(source, { tier: 5 });
const { admin } = await makeTestAccount(source, { tier: 5 });
const service = module.get<WorkflowsService>(WorkflowsService);
const context = makeContext(admin.external_id, 'requestId');
@ -236,22 +280,34 @@ describe('getWorkflows', () => {
describe('createWorkflows', () => {
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;
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});
it('アカウント内にWorkflowを作成できるWorktypeIDあり、テンプレートファイルあり', async () => {
if (!source) fail();
const module = await makeTestingModule(source);
@ -575,6 +631,7 @@ describe('createWorkflows', () => {
//実行結果を確認
{
const workflows = await getWorkflows(source, account.id);
workflows.sort((a, b) => a.id - b.id);
expect(workflows.length).toBe(2);
expect(workflows[1].account_id).toBe(account.id);
expect(workflows[1].author_id).toBe(authorId);
@ -1162,19 +1219,32 @@ describe('createWorkflows', () => {
describe('updateWorkflow', () => {
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();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});
@ -1592,6 +1662,7 @@ describe('updateWorkflow', () => {
//作成したデータを確認
{
const workflows = await getWorkflows(source, account.id);
workflows.sort((a, b) => a.id - b.id);
const workflowTypists = await getAllWorkflowTypists(source);
expect(workflows.length).toBe(2);
expect(workflows[0].id).toBe(preWorkflow1.id);
@ -1627,6 +1698,7 @@ describe('updateWorkflow', () => {
//実行結果を確認
{
const workflows = await getWorkflows(source, account.id);
workflows.sort((a, b) => a.id - b.id);
expect(workflows.length).toBe(2);
expect(workflows[1].account_id).toBe(account.id);
expect(workflows[1].author_id).toBe(authorId2);
@ -2349,19 +2421,32 @@ describe('updateWorkflow', () => {
describe('deleteWorkflows', () => {
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();
beforeAll(async () => {
if (source == null) {
source = await (async () => {
const s = new DataSource({
type: 'mysql',
host: 'test_mysql_db',
port: 3306,
username: 'user',
password: 'password',
database: 'odms',
entities: [__dirname + '/../../**/*.entity{.ts,.js}'],
synchronize: false, // trueにすると自動的にmigrationが行われるため注意
});
return await s.initialize();
})();
}
});
afterEach(async () => {
if (!source) return;
await source.destroy();
beforeEach(async () => {
if (source) {
await truncateAllTable(source);
}
});
afterAll(async () => {
await source?.destroy();
source = null;
});

View File

@ -29,6 +29,7 @@ import {
TIERS,
TRIAL_LICENSE_ISSUE_NUM,
USER_ROLES,
USER_ROLE_ORDERS,
} from '../../constants';
import { License } from '../licenses/entity/license.entity';
import { NewTrialLicenseExpirationDate } from '../../features/licenses/types/types';
@ -496,10 +497,23 @@ export class UsersRepositoryService {
license: true,
},
where: { account_id: accountId },
comment: `${context.getTrackingId()}_${new Date().toUTCString()}`,
});
return dbUsers;
// RoleのAuthor、Typist、Noneの順に並び替える
const roleSortedUsers = dbUsers.sort((a, b) => {
// Roleが同じ場合はIDの昇順で並び替える
if (a.role === b.role) {
return a.id - b.id;
}
return (
USER_ROLE_ORDERS.indexOf(a.role) - USER_ROLE_ORDERS.indexOf(b.role)
);
});
return roleSortedUsers;
});
}

View File

@ -50,7 +50,12 @@ export class WorkflowsRepositoryService {
},
},
order: {
id: 'ASC',
author: {
author_id: 'ASC',
},
worktype: {
custom_worktype_id: 'ASC',
},
},
comment: `${context.getTrackingId()}_${new Date().toUTCString()}`,
});