Merge branch 'develop' of https://dev.azure.com/ODMSCloud/ODMS%20Cloud/_git/ODMS%20Cloud into develop
This commit is contained in:
commit
bacd3f41c2
@ -38,7 +38,6 @@ import { RoleGuard } from '../../common/guards/role/roleguards';
|
|||||||
import { retrieveAuthorizationToken } from '../../common/http/helper';
|
import { retrieveAuthorizationToken } from '../../common/http/helper';
|
||||||
import { AccessToken } from '../../common/token';
|
import { AccessToken } from '../../common/token';
|
||||||
import jwt from 'jsonwebtoken';
|
import jwt from 'jsonwebtoken';
|
||||||
import { LicenseHistory } from '../../repositories/licenses/entity/license.entity';
|
|
||||||
|
|
||||||
@ApiTags('accounts')
|
@ApiTags('accounts')
|
||||||
@Controller('accounts')
|
@Controller('accounts')
|
||||||
@ -360,26 +359,9 @@ export class AccountsController {
|
|||||||
): Promise<GetOrderHistoriesResponce> {
|
): Promise<GetOrderHistoriesResponce> {
|
||||||
const { limit, offset, accountId } = body;
|
const { limit, offset, accountId } = body;
|
||||||
|
|
||||||
// XXX Task2261で本実装する
|
const getOrderHistoriesResponce =
|
||||||
const orderHistories: LicenseOrder[] = [];
|
await this.accountService.getOrderHistories(limit, offset, accountId);
|
||||||
const orderHistory: LicenseOrder = {
|
|
||||||
orderDate: '2023/01/01',
|
|
||||||
issueDate: '2023/01/01',
|
|
||||||
numberOfOrder: 50,
|
|
||||||
poNumber: 'PO001',
|
|
||||||
status: 'Issue Requesting',
|
|
||||||
};
|
|
||||||
orderHistories.push(orderHistory);
|
|
||||||
const getOrderHistoriesResponce = new GetOrderHistoriesResponce();
|
|
||||||
getOrderHistoriesResponce.total = 1;
|
|
||||||
getOrderHistoriesResponce.orderHistories = orderHistories;
|
|
||||||
/* =
|
|
||||||
await this.accountService.getOrderHistoriesResponce(
|
|
||||||
limit,
|
|
||||||
offset,
|
|
||||||
accountId,
|
|
||||||
);
|
|
||||||
*/
|
|
||||||
return getOrderHistoriesResponce;
|
return getOrderHistoriesResponce;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { UsersRepositoryModule } from '../../repositories/users/users.repository.module';
|
import { UsersRepositoryModule } from '../../repositories/users/users.repository.module';
|
||||||
|
import { LicensesRepositoryModule } from '../../repositories/licenses/licenses.repository.module';
|
||||||
import { SendGridModule } from '../../gateways/sendgrid/sendgrid.module';
|
import { SendGridModule } from '../../gateways/sendgrid/sendgrid.module';
|
||||||
import { AccountsRepositoryModule } from '../../repositories/accounts/accounts.repository.module';
|
import { AccountsRepositoryModule } from '../../repositories/accounts/accounts.repository.module';
|
||||||
import { AccountsController } from './accounts.controller';
|
import { AccountsController } from './accounts.controller';
|
||||||
@ -11,6 +12,7 @@ import { UserGroupsRepositoryModule } from '../../repositories/user_groups/user_
|
|||||||
imports: [
|
imports: [
|
||||||
AccountsRepositoryModule,
|
AccountsRepositoryModule,
|
||||||
UsersRepositoryModule,
|
UsersRepositoryModule,
|
||||||
|
LicensesRepositoryModule,
|
||||||
UserGroupsRepositoryModule,
|
UserGroupsRepositoryModule,
|
||||||
SendGridModule,
|
SendGridModule,
|
||||||
AdB2cModule,
|
AdB2cModule,
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import {
|
|||||||
makeAccountsServiceMock,
|
makeAccountsServiceMock,
|
||||||
makeDefaultAccountsRepositoryMockValue,
|
makeDefaultAccountsRepositoryMockValue,
|
||||||
makeDefaultAdB2cMockValue,
|
makeDefaultAdB2cMockValue,
|
||||||
|
makeDefaultLicensesRepositoryMockValue,
|
||||||
makeDefaultSendGridlValue,
|
makeDefaultSendGridlValue,
|
||||||
makeDefaultUserGroupsRepositoryMockValue,
|
makeDefaultUserGroupsRepositoryMockValue,
|
||||||
makeDefaultUsersRepositoryMockValue,
|
makeDefaultUsersRepositoryMockValue,
|
||||||
@ -29,6 +30,8 @@ describe('AccountsService', () => {
|
|||||||
makeDefaultAccountsRepositoryMockValue();
|
makeDefaultAccountsRepositoryMockValue();
|
||||||
const configMockValue = makeDefaultConfigValue();
|
const configMockValue = makeDefaultConfigValue();
|
||||||
const sendGridMockValue = makeDefaultSendGridlValue();
|
const sendGridMockValue = makeDefaultSendGridlValue();
|
||||||
|
const licensesRepositoryMockValue =
|
||||||
|
makeDefaultLicensesRepositoryMockValue();
|
||||||
const service = await makeAccountsServiceMock(
|
const service = await makeAccountsServiceMock(
|
||||||
accountsRepositoryMockValue,
|
accountsRepositoryMockValue,
|
||||||
usersRepositoryMockValue,
|
usersRepositoryMockValue,
|
||||||
@ -36,6 +39,7 @@ describe('AccountsService', () => {
|
|||||||
adb2cParam,
|
adb2cParam,
|
||||||
configMockValue,
|
configMockValue,
|
||||||
sendGridMockValue,
|
sendGridMockValue,
|
||||||
|
licensesRepositoryMockValue,
|
||||||
);
|
);
|
||||||
expect(await service.getLicenseSummary(accountId)).toEqual(
|
expect(await service.getLicenseSummary(accountId)).toEqual(
|
||||||
expectedAccountLisenceCounts,
|
expectedAccountLisenceCounts,
|
||||||
@ -53,6 +57,8 @@ describe('AccountsService', () => {
|
|||||||
accountsRepositoryMockValue.getLicenseSummaryInfo = null;
|
accountsRepositoryMockValue.getLicenseSummaryInfo = null;
|
||||||
const configMockValue = makeDefaultConfigValue();
|
const configMockValue = makeDefaultConfigValue();
|
||||||
const sendGridMockValue = makeDefaultSendGridlValue();
|
const sendGridMockValue = makeDefaultSendGridlValue();
|
||||||
|
const licensesRepositoryMockValue =
|
||||||
|
makeDefaultLicensesRepositoryMockValue();
|
||||||
const service = await makeAccountsServiceMock(
|
const service = await makeAccountsServiceMock(
|
||||||
accountsRepositoryMockValue,
|
accountsRepositoryMockValue,
|
||||||
usersRepositoryMockValue,
|
usersRepositoryMockValue,
|
||||||
@ -60,6 +66,7 @@ describe('AccountsService', () => {
|
|||||||
adb2cParam,
|
adb2cParam,
|
||||||
configMockValue,
|
configMockValue,
|
||||||
sendGridMockValue,
|
sendGridMockValue,
|
||||||
|
licensesRepositoryMockValue,
|
||||||
);
|
);
|
||||||
await expect(service.getLicenseSummary(accountId)).rejects.toEqual(
|
await expect(service.getLicenseSummary(accountId)).rejects.toEqual(
|
||||||
new HttpException(
|
new HttpException(
|
||||||
@ -79,6 +86,8 @@ describe('AccountsService', () => {
|
|||||||
makeDefaultAccountsRepositoryMockValue();
|
makeDefaultAccountsRepositoryMockValue();
|
||||||
const configMockValue = makeDefaultConfigValue();
|
const configMockValue = makeDefaultConfigValue();
|
||||||
const sendGridMockValue = makeDefaultSendGridlValue();
|
const sendGridMockValue = makeDefaultSendGridlValue();
|
||||||
|
const licensesRepositoryMockValue =
|
||||||
|
makeDefaultLicensesRepositoryMockValue();
|
||||||
const service = await makeAccountsServiceMock(
|
const service = await makeAccountsServiceMock(
|
||||||
accountsRepositoryMockValue,
|
accountsRepositoryMockValue,
|
||||||
usersRepositoryMockValue,
|
usersRepositoryMockValue,
|
||||||
@ -86,6 +95,7 @@ describe('AccountsService', () => {
|
|||||||
adb2cParam,
|
adb2cParam,
|
||||||
configMockValue,
|
configMockValue,
|
||||||
sendGridMockValue,
|
sendGridMockValue,
|
||||||
|
licensesRepositoryMockValue,
|
||||||
);
|
);
|
||||||
expect(await service.getTypists(externalId)).toEqual([
|
expect(await service.getTypists(externalId)).toEqual([
|
||||||
{ id: 1, name: 'Typist1' },
|
{ id: 1, name: 'Typist1' },
|
||||||
@ -104,6 +114,8 @@ describe('AccountsService', () => {
|
|||||||
makeDefaultAccountsRepositoryMockValue();
|
makeDefaultAccountsRepositoryMockValue();
|
||||||
const configMockValue = makeDefaultConfigValue();
|
const configMockValue = makeDefaultConfigValue();
|
||||||
const sendGridMockValue = makeDefaultSendGridlValue();
|
const sendGridMockValue = makeDefaultSendGridlValue();
|
||||||
|
const licensesRepositoryMockValue =
|
||||||
|
makeDefaultLicensesRepositoryMockValue();
|
||||||
const service = await makeAccountsServiceMock(
|
const service = await makeAccountsServiceMock(
|
||||||
accountsRepositoryMockValue,
|
accountsRepositoryMockValue,
|
||||||
usersRepositoryMockValue,
|
usersRepositoryMockValue,
|
||||||
@ -111,6 +123,7 @@ describe('AccountsService', () => {
|
|||||||
adb2cParam,
|
adb2cParam,
|
||||||
configMockValue,
|
configMockValue,
|
||||||
sendGridMockValue,
|
sendGridMockValue,
|
||||||
|
licensesRepositoryMockValue,
|
||||||
);
|
);
|
||||||
await expect(service.getTypists(externalId)).rejects.toEqual(
|
await expect(service.getTypists(externalId)).rejects.toEqual(
|
||||||
new HttpException(
|
new HttpException(
|
||||||
@ -130,6 +143,8 @@ describe('AccountsService', () => {
|
|||||||
makeDefaultAccountsRepositoryMockValue();
|
makeDefaultAccountsRepositoryMockValue();
|
||||||
const configMockValue = makeDefaultConfigValue();
|
const configMockValue = makeDefaultConfigValue();
|
||||||
const sendGridMockValue = makeDefaultSendGridlValue();
|
const sendGridMockValue = makeDefaultSendGridlValue();
|
||||||
|
const licensesRepositoryMockValue =
|
||||||
|
makeDefaultLicensesRepositoryMockValue();
|
||||||
const service = await makeAccountsServiceMock(
|
const service = await makeAccountsServiceMock(
|
||||||
accountsRepositoryMockValue,
|
accountsRepositoryMockValue,
|
||||||
usersRepositoryMockValue,
|
usersRepositoryMockValue,
|
||||||
@ -137,6 +152,7 @@ describe('AccountsService', () => {
|
|||||||
adb2cParam,
|
adb2cParam,
|
||||||
configMockValue,
|
configMockValue,
|
||||||
sendGridMockValue,
|
sendGridMockValue,
|
||||||
|
licensesRepositoryMockValue,
|
||||||
);
|
);
|
||||||
await expect(service.getTypists(externalId)).rejects.toEqual(
|
await expect(service.getTypists(externalId)).rejects.toEqual(
|
||||||
new HttpException(
|
new HttpException(
|
||||||
@ -156,6 +172,8 @@ describe('AccountsService', () => {
|
|||||||
makeDefaultUserGroupsRepositoryMockValue();
|
makeDefaultUserGroupsRepositoryMockValue();
|
||||||
const configMockValue = makeDefaultConfigValue();
|
const configMockValue = makeDefaultConfigValue();
|
||||||
const sendGridMockValue = makeDefaultSendGridlValue();
|
const sendGridMockValue = makeDefaultSendGridlValue();
|
||||||
|
const licensesRepositoryMockValue =
|
||||||
|
makeDefaultLicensesRepositoryMockValue();
|
||||||
const service = await makeAccountsServiceMock(
|
const service = await makeAccountsServiceMock(
|
||||||
accountsRepositoryMockValue,
|
accountsRepositoryMockValue,
|
||||||
usersRepositoryMockValue,
|
usersRepositoryMockValue,
|
||||||
@ -163,6 +181,7 @@ describe('AccountsService', () => {
|
|||||||
adb2cParam,
|
adb2cParam,
|
||||||
configMockValue,
|
configMockValue,
|
||||||
sendGridMockValue,
|
sendGridMockValue,
|
||||||
|
licensesRepositoryMockValue,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(await service.getTypistGroups(externalId)).toEqual([
|
expect(await service.getTypistGroups(externalId)).toEqual([
|
||||||
@ -181,6 +200,8 @@ describe('AccountsService', () => {
|
|||||||
makeDefaultUserGroupsRepositoryMockValue();
|
makeDefaultUserGroupsRepositoryMockValue();
|
||||||
const configMockValue = makeDefaultConfigValue();
|
const configMockValue = makeDefaultConfigValue();
|
||||||
const sendGridMockValue = makeDefaultSendGridlValue();
|
const sendGridMockValue = makeDefaultSendGridlValue();
|
||||||
|
const licensesRepositoryMockValue =
|
||||||
|
makeDefaultLicensesRepositoryMockValue();
|
||||||
const service = await makeAccountsServiceMock(
|
const service = await makeAccountsServiceMock(
|
||||||
accountsRepositoryMockValue,
|
accountsRepositoryMockValue,
|
||||||
usersRepositoryMockValue,
|
usersRepositoryMockValue,
|
||||||
@ -188,6 +209,7 @@ describe('AccountsService', () => {
|
|||||||
adb2cParam,
|
adb2cParam,
|
||||||
configMockValue,
|
configMockValue,
|
||||||
sendGridMockValue,
|
sendGridMockValue,
|
||||||
|
licensesRepositoryMockValue,
|
||||||
);
|
);
|
||||||
|
|
||||||
await expect(service.getTypistGroups(externalId)).rejects.toEqual(
|
await expect(service.getTypistGroups(externalId)).rejects.toEqual(
|
||||||
@ -208,6 +230,8 @@ describe('AccountsService', () => {
|
|||||||
userGroupsRepositoryMockValue.getUserGroups = new Error('DB failed');
|
userGroupsRepositoryMockValue.getUserGroups = new Error('DB failed');
|
||||||
const configMockValue = makeDefaultConfigValue();
|
const configMockValue = makeDefaultConfigValue();
|
||||||
const sendGridMockValue = makeDefaultSendGridlValue();
|
const sendGridMockValue = makeDefaultSendGridlValue();
|
||||||
|
const licensesRepositoryMockValue =
|
||||||
|
makeDefaultLicensesRepositoryMockValue();
|
||||||
const service = await makeAccountsServiceMock(
|
const service = await makeAccountsServiceMock(
|
||||||
accountsRepositoryMockValue,
|
accountsRepositoryMockValue,
|
||||||
usersRepositoryMockValue,
|
usersRepositoryMockValue,
|
||||||
@ -215,6 +239,7 @@ describe('AccountsService', () => {
|
|||||||
adb2cParam,
|
adb2cParam,
|
||||||
configMockValue,
|
configMockValue,
|
||||||
sendGridMockValue,
|
sendGridMockValue,
|
||||||
|
licensesRepositoryMockValue,
|
||||||
);
|
);
|
||||||
|
|
||||||
await expect(service.getTypistGroups(externalId)).rejects.toEqual(
|
await expect(service.getTypistGroups(externalId)).rejects.toEqual(
|
||||||
@ -239,7 +264,8 @@ describe('AccountsService', () => {
|
|||||||
makeDefaultAccountsRepositoryMockValue();
|
makeDefaultAccountsRepositoryMockValue();
|
||||||
const configMockValue = makeDefaultConfigValue();
|
const configMockValue = makeDefaultConfigValue();
|
||||||
const sendGridMockValue = makeDefaultSendGridlValue();
|
const sendGridMockValue = makeDefaultSendGridlValue();
|
||||||
|
const licensesRepositoryMockValue =
|
||||||
|
makeDefaultLicensesRepositoryMockValue();
|
||||||
const service = await makeAccountsServiceMock(
|
const service = await makeAccountsServiceMock(
|
||||||
accountsRepositoryMockValue,
|
accountsRepositoryMockValue,
|
||||||
usersRepositoryMockValue,
|
usersRepositoryMockValue,
|
||||||
@ -247,6 +273,7 @@ describe('AccountsService', () => {
|
|||||||
adb2cParam,
|
adb2cParam,
|
||||||
configMockValue,
|
configMockValue,
|
||||||
sendGridMockValue,
|
sendGridMockValue,
|
||||||
|
licensesRepositoryMockValue,
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
await service.createPartnerAccount(
|
await service.createPartnerAccount(
|
||||||
@ -275,7 +302,8 @@ describe('AccountsService', () => {
|
|||||||
accountsRepositoryMockValue.createAccount = new Error('DB failed');
|
accountsRepositoryMockValue.createAccount = new Error('DB failed');
|
||||||
const configMockValue = makeDefaultConfigValue();
|
const configMockValue = makeDefaultConfigValue();
|
||||||
const sendGridMockValue = makeDefaultSendGridlValue();
|
const sendGridMockValue = makeDefaultSendGridlValue();
|
||||||
|
const licensesRepositoryMockValue =
|
||||||
|
makeDefaultLicensesRepositoryMockValue();
|
||||||
const service = await makeAccountsServiceMock(
|
const service = await makeAccountsServiceMock(
|
||||||
accountsRepositoryMockValue,
|
accountsRepositoryMockValue,
|
||||||
usersRepositoryMockValue,
|
usersRepositoryMockValue,
|
||||||
@ -283,6 +311,7 @@ describe('AccountsService', () => {
|
|||||||
adb2cParam,
|
adb2cParam,
|
||||||
configMockValue,
|
configMockValue,
|
||||||
sendGridMockValue,
|
sendGridMockValue,
|
||||||
|
licensesRepositoryMockValue,
|
||||||
);
|
);
|
||||||
await expect(
|
await expect(
|
||||||
service.createPartnerAccount(
|
service.createPartnerAccount(
|
||||||
@ -368,7 +397,13 @@ describe('createPartnerAccount', () => {
|
|||||||
await createLicense(source, childAccountId2);
|
await createLicense(source, childAccountId2);
|
||||||
|
|
||||||
// ライセンス注文を追加(子1→親:10ライセンス、子2→親:5ライセンス)
|
// ライセンス注文を追加(子1→親:10ライセンス、子2→親:5ライセンス)
|
||||||
await createLicenseOrder(source, childAccountId1, parentAccountId, 10);
|
await createLicenseOrder(
|
||||||
|
source,
|
||||||
|
childAccountId1,
|
||||||
|
parentAccountId,
|
||||||
|
10,
|
||||||
|
'TEST222',
|
||||||
|
);
|
||||||
await createLicenseOrder(source, childAccountId2, parentAccountId, 5);
|
await createLicenseOrder(source, childAccountId2, parentAccountId, 5);
|
||||||
|
|
||||||
const service = module.get<AccountsService>(AccountsService);
|
const service = module.get<AccountsService>(AccountsService);
|
||||||
@ -397,3 +432,120 @@ describe('createPartnerAccount', () => {
|
|||||||
expect(responce.childrenPartnerLicenses[1].issueRequesting).toBe(5);
|
expect(responce.childrenPartnerLicenses[1].issueRequesting).toBe(5);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('getOrderHistories', () => {
|
||||||
|
let source: DataSource = 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 () => {
|
||||||
|
await source.destroy();
|
||||||
|
source = null;
|
||||||
|
});
|
||||||
|
|
||||||
|
it('指定したアカウントIDの注文履歴情報を取得できる', async () => {
|
||||||
|
const module = await makeTestingModule(source);
|
||||||
|
|
||||||
|
const targetAccountId = 10;
|
||||||
|
const targetParentAccountId = 14;
|
||||||
|
const now = new Date(); // 現在の時刻を取得
|
||||||
|
|
||||||
|
// 注文履歴情報の作成
|
||||||
|
await createLicenseOrder(
|
||||||
|
source,
|
||||||
|
targetAccountId,
|
||||||
|
targetParentAccountId,
|
||||||
|
10,
|
||||||
|
'TEST001',
|
||||||
|
new Date(now.getTime() + 60 * 60 * 1000),
|
||||||
|
);
|
||||||
|
await createLicenseOrder(
|
||||||
|
source,
|
||||||
|
targetAccountId,
|
||||||
|
targetParentAccountId,
|
||||||
|
10,
|
||||||
|
'TEST002',
|
||||||
|
new Date(now.getTime() + 60 * 60 * 1000 * 2),
|
||||||
|
);
|
||||||
|
await createLicenseOrder(
|
||||||
|
source,
|
||||||
|
targetAccountId,
|
||||||
|
targetParentAccountId,
|
||||||
|
10,
|
||||||
|
'TEST003',
|
||||||
|
new Date(now.getTime() + 60 * 60 * 1000 * 3),
|
||||||
|
);
|
||||||
|
await createLicenseOrder(
|
||||||
|
source,
|
||||||
|
targetAccountId,
|
||||||
|
targetParentAccountId,
|
||||||
|
10,
|
||||||
|
'TEST004',
|
||||||
|
new Date(now.getTime() + 60 * 60 * 1000 * 4),
|
||||||
|
);
|
||||||
|
await createLicenseOrder(
|
||||||
|
source,
|
||||||
|
targetAccountId,
|
||||||
|
targetParentAccountId,
|
||||||
|
10,
|
||||||
|
'TEST005',
|
||||||
|
new Date(now.getTime() + 60 * 60 * 1000 * 5),
|
||||||
|
);
|
||||||
|
|
||||||
|
const service = module.get<AccountsService>(AccountsService);
|
||||||
|
const accountId = targetAccountId;
|
||||||
|
const offset = 1;
|
||||||
|
const limit = 2;
|
||||||
|
|
||||||
|
const responce = await service.getOrderHistories(limit, offset, accountId);
|
||||||
|
|
||||||
|
expect(responce.total).toBe(5);
|
||||||
|
|
||||||
|
expect(responce.orderHistories[0].poNumber).toBe('TEST004');
|
||||||
|
expect(responce.orderHistories[1].poNumber).toBe('TEST003');
|
||||||
|
});
|
||||||
|
it('注文履歴情報の取得に失敗した場合、エラーとなる', async () => {
|
||||||
|
const limit = 0;
|
||||||
|
const offset = 0;
|
||||||
|
const accountId = 0;
|
||||||
|
const usersRepositoryMockValue = makeDefaultUsersRepositoryMockValue();
|
||||||
|
usersRepositoryMockValue.findTypistUsers = new Error();
|
||||||
|
const userGroupsRepositoryMockValue =
|
||||||
|
makeDefaultUserGroupsRepositoryMockValue();
|
||||||
|
const adb2cParam = makeDefaultAdB2cMockValue();
|
||||||
|
const accountsRepositoryMockValue =
|
||||||
|
makeDefaultAccountsRepositoryMockValue();
|
||||||
|
const configMockValue = makeDefaultConfigValue();
|
||||||
|
const sendGridMockValue = makeDefaultSendGridlValue();
|
||||||
|
const licensesRepositoryMockValue =
|
||||||
|
makeDefaultLicensesRepositoryMockValue();
|
||||||
|
licensesRepositoryMockValue.getLicenseOrderHistoryInfo = new Error(
|
||||||
|
'DB failed',
|
||||||
|
);
|
||||||
|
const service = await makeAccountsServiceMock(
|
||||||
|
accountsRepositoryMockValue,
|
||||||
|
usersRepositoryMockValue,
|
||||||
|
userGroupsRepositoryMockValue,
|
||||||
|
adb2cParam,
|
||||||
|
configMockValue,
|
||||||
|
sendGridMockValue,
|
||||||
|
licensesRepositoryMockValue,
|
||||||
|
);
|
||||||
|
await expect(
|
||||||
|
service.getOrderHistories(limit, offset, accountId),
|
||||||
|
).rejects.toEqual(
|
||||||
|
new HttpException(
|
||||||
|
makeErrorResponse('E009999'),
|
||||||
|
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@ -20,6 +20,8 @@ import {
|
|||||||
TypistGroup,
|
TypistGroup,
|
||||||
GetPartnerLicensesResponse,
|
GetPartnerLicensesResponse,
|
||||||
PartnerLicenseInfo,
|
PartnerLicenseInfo,
|
||||||
|
GetOrderHistoriesResponce,
|
||||||
|
LicenseOrder,
|
||||||
} from './types/types';
|
} from './types/types';
|
||||||
import { DateWithZeroTime } from '../licenses/types/types';
|
import { DateWithZeroTime } from '../licenses/types/types';
|
||||||
import { GetLicenseSummaryResponse, Typist } from './types/types';
|
import { GetLicenseSummaryResponse, Typist } from './types/types';
|
||||||
@ -27,11 +29,12 @@ import { AccessToken } from '../../common/token';
|
|||||||
import { UserNotFoundError } from '../../repositories/users/errors/types';
|
import { UserNotFoundError } from '../../repositories/users/errors/types';
|
||||||
import { UserGroupsRepositoryService } from '../../repositories/user_groups/user_groups.repository.service';
|
import { UserGroupsRepositoryService } from '../../repositories/user_groups/user_groups.repository.service';
|
||||||
import { makePassword } from '../../common/password';
|
import { makePassword } from '../../common/password';
|
||||||
|
import { LicensesRepositoryService } from '../../repositories/licenses/licenses.repository.service';
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AccountsService {
|
export class AccountsService {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly accountRepository: AccountsRepositoryService,
|
private readonly accountRepository: AccountsRepositoryService,
|
||||||
|
private readonly licensesRepository: LicensesRepositoryService,
|
||||||
private readonly usersRepository: UsersRepositoryService,
|
private readonly usersRepository: UsersRepositoryService,
|
||||||
private readonly userGroupsRepository: UserGroupsRepositoryService,
|
private readonly userGroupsRepository: UserGroupsRepositoryService,
|
||||||
private readonly adB2cService: AdB2cService,
|
private readonly adB2cService: AdB2cService,
|
||||||
@ -492,4 +495,59 @@ export class AccountsService {
|
|||||||
this.logger.log(`[OUT] ${this.getPartnerLicenses.name}`);
|
this.logger.log(`[OUT] ${this.getPartnerLicenses.name}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 注文履歴情報を取得する
|
||||||
|
* @param limit
|
||||||
|
* @param offset
|
||||||
|
* @param accountId
|
||||||
|
* @returns getOrderHistoriesResponce
|
||||||
|
*/
|
||||||
|
async getOrderHistories(
|
||||||
|
limit: number,
|
||||||
|
offset: number,
|
||||||
|
accountId: number,
|
||||||
|
): Promise<GetOrderHistoriesResponce> {
|
||||||
|
this.logger.log(`[IN] ${this.getOrderHistories.name}`);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const licenseHistoryInfo =
|
||||||
|
await this.licensesRepository.getLicenseOrderHistoryInfo(
|
||||||
|
accountId,
|
||||||
|
offset,
|
||||||
|
limit,
|
||||||
|
);
|
||||||
|
|
||||||
|
// 戻り値用に配列の詰めなおしを行う
|
||||||
|
const orderHistories: LicenseOrder[] = [];
|
||||||
|
for (const licenseOrder of licenseHistoryInfo.licenseOrders) {
|
||||||
|
const returnLicenseOrder: LicenseOrder = {
|
||||||
|
issueDate: new Date(licenseOrder.issued_at)
|
||||||
|
.toISOString()
|
||||||
|
.substr(0, 10)
|
||||||
|
.replace(/-/g, '/'),
|
||||||
|
numberOfOrder: licenseOrder.quantity,
|
||||||
|
orderDate: new Date(licenseOrder.ordered_at)
|
||||||
|
.toISOString()
|
||||||
|
.substr(0, 10)
|
||||||
|
.replace(/-/g, '/'),
|
||||||
|
poNumber: licenseOrder.po_number,
|
||||||
|
status: licenseOrder.status,
|
||||||
|
};
|
||||||
|
orderHistories.push(returnLicenseOrder);
|
||||||
|
}
|
||||||
|
const getOrderHistoriesResponse: GetOrderHistoriesResponce = {
|
||||||
|
total: licenseHistoryInfo.total,
|
||||||
|
orderHistories: orderHistories,
|
||||||
|
};
|
||||||
|
return getOrderHistoriesResponse;
|
||||||
|
} catch (e) {
|
||||||
|
this.logger.error(e);
|
||||||
|
throw new HttpException(
|
||||||
|
makeErrorResponse('E009999'),
|
||||||
|
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
this.logger.log(`[OUT] ${this.getOrderHistories.name}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,10 +9,18 @@ import {
|
|||||||
ConflictError,
|
ConflictError,
|
||||||
} from '../../../gateways/adb2c/adb2c.service';
|
} from '../../../gateways/adb2c/adb2c.service';
|
||||||
import { SendGridService } from '../../../gateways/sendgrid/sendgrid.service';
|
import { SendGridService } from '../../../gateways/sendgrid/sendgrid.service';
|
||||||
import { Account, LicenseSummaryInfo } from '../types/types';
|
import { Account, LicenseOrder, LicenseSummaryInfo } from '../types/types';
|
||||||
import { UserGroup } from '../../../repositories/user_groups/entity/user_group.entity';
|
import { UserGroup } from '../../../repositories/user_groups/entity/user_group.entity';
|
||||||
import { UserGroupsRepositoryService } from '../../../repositories/user_groups/user_groups.repository.service';
|
import { UserGroupsRepositoryService } from '../../../repositories/user_groups/user_groups.repository.service';
|
||||||
import { AdB2cUser } from '../../../gateways/adb2c/types/types';
|
import { AdB2cUser } from '../../../gateways/adb2c/types/types';
|
||||||
|
import { LicensesRepositoryService } from '../../../repositories/licenses/licenses.repository.service';
|
||||||
|
|
||||||
|
export type LicensesRepositoryMockValue = {
|
||||||
|
getLicenseOrderHistoryInfo: {
|
||||||
|
total: number;
|
||||||
|
orderHistories: LicenseOrder[];
|
||||||
|
} | Error;
|
||||||
|
};
|
||||||
export type UsersRepositoryMockValue = {
|
export type UsersRepositoryMockValue = {
|
||||||
findUserById: User | Error;
|
findUserById: User | Error;
|
||||||
findUserByExternalId: User | Error;
|
findUserByExternalId: User | Error;
|
||||||
@ -55,6 +63,7 @@ export const makeAccountsServiceMock = async (
|
|||||||
adB2cMockValue: AdB2cMockValue,
|
adB2cMockValue: AdB2cMockValue,
|
||||||
configMockValue: ConfigMockValue,
|
configMockValue: ConfigMockValue,
|
||||||
sendGridMockValue: SendGridMockValue,
|
sendGridMockValue: SendGridMockValue,
|
||||||
|
licensesRepositoryMockValue: LicensesRepositoryMockValue
|
||||||
): Promise<AccountsService> => {
|
): Promise<AccountsService> => {
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
providers: [AccountsService],
|
providers: [AccountsService],
|
||||||
@ -79,6 +88,8 @@ export const makeAccountsServiceMock = async (
|
|||||||
return makeConfigMock(configMockValue);
|
return makeConfigMock(configMockValue);
|
||||||
case SendGridService:
|
case SendGridService:
|
||||||
return makeSendGridServiceMock(sendGridMockValue);
|
return makeSendGridServiceMock(sendGridMockValue);
|
||||||
|
case LicensesRepositoryService:
|
||||||
|
return makeLicensesRepositoryMock(licensesRepositoryMockValue);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.compile();
|
.compile();
|
||||||
@ -111,6 +122,24 @@ export const makeAccountsRepositoryMock = (
|
|||||||
.mockResolvedValue(createAccount),
|
.mockResolvedValue(createAccount),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
export const makeLicensesRepositoryMock = (value: LicensesRepositoryMockValue) => {
|
||||||
|
const { getLicenseOrderHistoryInfo } =
|
||||||
|
value;
|
||||||
|
|
||||||
|
return {
|
||||||
|
findUserById:
|
||||||
|
getLicenseOrderHistoryInfo instanceof Error
|
||||||
|
? jest
|
||||||
|
.fn<Promise<void>, []>()
|
||||||
|
.mockRejectedValue(getLicenseOrderHistoryInfo)
|
||||||
|
: jest
|
||||||
|
.fn<
|
||||||
|
Promise<{ total: number; orderHistories: LicenseOrder[] }>,
|
||||||
|
[]
|
||||||
|
>()
|
||||||
|
.mockResolvedValue(getLicenseOrderHistoryInfo),
|
||||||
|
};
|
||||||
|
};
|
||||||
export const makeUsersRepositoryMock = (value: UsersRepositoryMockValue) => {
|
export const makeUsersRepositoryMock = (value: UsersRepositoryMockValue) => {
|
||||||
const { findUserById, findUserByExternalId, findTypistUsers } = value;
|
const { findUserById, findUserByExternalId, findTypistUsers } = value;
|
||||||
|
|
||||||
@ -355,3 +384,19 @@ export const makeDefaultSendGridlValue = (): SendGridMockValue => {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
export const makeDefaultLicensesRepositoryMockValue = (): LicensesRepositoryMockValue => {
|
||||||
|
return {
|
||||||
|
getLicenseOrderHistoryInfo: {
|
||||||
|
total: 100,
|
||||||
|
orderHistories: [
|
||||||
|
{
|
||||||
|
orderDate: '2023/04/01',
|
||||||
|
issueDate: '2023/04/01',
|
||||||
|
numberOfOrder: 10,
|
||||||
|
poNumber: 'PO001',
|
||||||
|
status:'Issued'
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
};
|
||||||
@ -55,12 +55,14 @@ export const createLicenseOrder = async (
|
|||||||
fromAccountId: number,
|
fromAccountId: number,
|
||||||
toAccountId: number,
|
toAccountId: number,
|
||||||
quantity: number,
|
quantity: number,
|
||||||
|
po_number = 'TEST123',
|
||||||
|
ordered_at = new Date(),
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
const { identifiers } = await datasource.getRepository(LicenseOrder).insert({
|
const { identifiers } = await datasource.getRepository(LicenseOrder).insert({
|
||||||
po_number: 'TEST123',
|
po_number: po_number,
|
||||||
from_account_id: fromAccountId,
|
from_account_id: fromAccountId,
|
||||||
to_account_id: toAccountId,
|
to_account_id: toAccountId,
|
||||||
ordered_at: new Date(),
|
ordered_at: ordered_at,
|
||||||
issued_at: null,
|
issued_at: null,
|
||||||
quantity: quantity,
|
quantity: quantity,
|
||||||
status: 'Issue Requesting',
|
status: 'Issue Requesting',
|
||||||
|
|||||||
@ -255,4 +255,45 @@ export class LicensesRepositoryService {
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* アカウントIDに紐づく注文履歴情報を取得する
|
||||||
|
* @param accountId
|
||||||
|
* @param offset
|
||||||
|
* @param limit
|
||||||
|
* @returns total
|
||||||
|
* @returns licenseOrders
|
||||||
|
*/
|
||||||
|
async getLicenseOrderHistoryInfo(
|
||||||
|
accountId: number,
|
||||||
|
offset: number,
|
||||||
|
limit: number,
|
||||||
|
): Promise<{
|
||||||
|
total: number;
|
||||||
|
licenseOrders: LicenseOrder[];
|
||||||
|
}> {
|
||||||
|
return await this.dataSource.transaction(async (entityManager) => {
|
||||||
|
const licenseOrder = entityManager.getRepository(LicenseOrder);
|
||||||
|
// limit/offsetによらない総件数を取得する
|
||||||
|
const total = await licenseOrder.count({
|
||||||
|
where: {
|
||||||
|
from_account_id: accountId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const licenseOrders = await licenseOrder.find({
|
||||||
|
where: {
|
||||||
|
from_account_id: accountId,
|
||||||
|
},
|
||||||
|
order: {
|
||||||
|
ordered_at: 'DESC',
|
||||||
|
},
|
||||||
|
take: limit,
|
||||||
|
skip: offset,
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
total: total,
|
||||||
|
licenseOrders: licenseOrders,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user