Merged PR 339: パートナー追加のテストが増えている問題を修正
## 概要 [Task2443: パートナー追加のテストが増えている問題を修正](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/2443) - 重複しているテストを削除 - 重複していないテスト(blob storageで失敗したケース)を移動 ## レビューポイント - 対処として問題ないか ## 動作確認状況 - ローカル環境でnpm run test で成功
This commit is contained in:
parent
deb753b40d
commit
493dbadb8e
@ -528,6 +528,61 @@ describe('createPartnerAccount', () => {
|
||||
expect(users.length).toBe(1);
|
||||
}
|
||||
});
|
||||
|
||||
it('BlobStorageへの通信失敗が原因でアカウントの追加に失敗した場合、エラーとなる(500エラー)', async () => {
|
||||
const module = await makeTestingModule(source);
|
||||
const service = module.get<AccountsService>(AccountsService);
|
||||
|
||||
const parentExternalId = 'parent_external_id';
|
||||
|
||||
await createAccountAndAdminUser(source, parentExternalId);
|
||||
|
||||
const context = makeContext(parentExternalId);
|
||||
const partnerExternalId = 'partner_external_id';
|
||||
const companyName = 'partner_company_name';
|
||||
const country = 'US';
|
||||
const email = 'partner@example.com';
|
||||
const username = 'partner_username';
|
||||
|
||||
overrideAdB2cService(service, {
|
||||
createUser: async () => {
|
||||
return { sub: partnerExternalId };
|
||||
},
|
||||
});
|
||||
|
||||
overrideSendgridService(service, {
|
||||
sendMail: async () => {
|
||||
return;
|
||||
},
|
||||
createMailContentFromEmailConfirmForNormalUser: async () => {
|
||||
return { html: '', text: '', subject: '' };
|
||||
},
|
||||
});
|
||||
overrideBlobstorageService(service, {
|
||||
createContainer: async () => {
|
||||
throw new Error();
|
||||
},
|
||||
});
|
||||
|
||||
try {
|
||||
await service.createPartnerAccount(
|
||||
context,
|
||||
companyName,
|
||||
country,
|
||||
email,
|
||||
username,
|
||||
parentExternalId,
|
||||
TIERS.TIER1,
|
||||
);
|
||||
} catch (e) {
|
||||
if (e instanceof HttpException) {
|
||||
expect(e.getStatus()).toBe(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
expect(e.getResponse()).toEqual(makeErrorResponse('E009999'));
|
||||
} else {
|
||||
fail();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('AccountsService', () => {
|
||||
@ -1394,257 +1449,3 @@ describe('getDealers', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('createPartnerAccount', () => {
|
||||
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('パートナーを追加できる', async () => {
|
||||
const module = await makeTestingModule(source);
|
||||
const service = module.get<AccountsService>(AccountsService);
|
||||
|
||||
const parentExternalId = 'parent_external_id';
|
||||
|
||||
const { accountId: parentAccountId } = await createAccountAndAdminUser(
|
||||
source,
|
||||
parentExternalId,
|
||||
);
|
||||
|
||||
const context = makeContext(parentExternalId);
|
||||
const partnerExternalId = 'partner_external_id';
|
||||
const companyName = 'partner_company_name';
|
||||
const country = 'US';
|
||||
const email = 'partner@example.com';
|
||||
const username = 'partner_username';
|
||||
|
||||
overrideAdB2cService(service, {
|
||||
createUser: async () => {
|
||||
return { sub: partnerExternalId };
|
||||
},
|
||||
});
|
||||
|
||||
overrideSendgridService(service, {
|
||||
sendMail: async () => {
|
||||
return;
|
||||
},
|
||||
createMailContentFromEmailConfirmForNormalUser: async () => {
|
||||
return { html: '', text: '', subject: '' };
|
||||
},
|
||||
});
|
||||
overrideBlobstorageService(service, {
|
||||
createContainer: async () => {
|
||||
return;
|
||||
},
|
||||
});
|
||||
|
||||
{
|
||||
const accounts = await getAccounts(source);
|
||||
expect(accounts.length).toBe(1);
|
||||
}
|
||||
|
||||
await service.createPartnerAccount(
|
||||
context,
|
||||
companyName,
|
||||
country,
|
||||
email,
|
||||
username,
|
||||
parentExternalId,
|
||||
TIERS.TIER1,
|
||||
);
|
||||
|
||||
{
|
||||
const accounts = await getAccounts(source);
|
||||
expect(accounts.length).toBe(2);
|
||||
|
||||
const partnerUser = await getUserFromExternalID(
|
||||
source,
|
||||
partnerExternalId,
|
||||
);
|
||||
const partnerAccount = await getAccount(source, partnerUser.account_id);
|
||||
expect(partnerAccount.company_name).toBe(companyName);
|
||||
expect(partnerAccount.country).toBe(country);
|
||||
expect(partnerAccount.parent_account_id).toBe(parentAccountId);
|
||||
expect(partnerAccount.tier).toBe(TIERS.TIER2);
|
||||
expect(partnerAccount.primary_admin_user_id).toBe(partnerUser.id);
|
||||
expect(partnerAccount.secondary_admin_user_id).toBe(null);
|
||||
}
|
||||
});
|
||||
|
||||
it('パートナーアカウントを作成がAzure AD B2Cへの通信失敗によって失敗すると500エラーが発生する', async () => {
|
||||
const module = await makeTestingModule(source);
|
||||
const service = module.get<AccountsService>(AccountsService);
|
||||
|
||||
const parentExternalId = 'parent_external_id';
|
||||
|
||||
await createAccountAndAdminUser(source, parentExternalId);
|
||||
|
||||
const context = makeContext(parentExternalId);
|
||||
const companyName = 'partner_company_name';
|
||||
const country = 'US';
|
||||
const email = 'partner@example.com';
|
||||
const username = 'partner_username';
|
||||
|
||||
overrideAdB2cService(service, {
|
||||
createUser: async () => {
|
||||
throw new Error();
|
||||
},
|
||||
});
|
||||
|
||||
overrideSendgridService(service, {
|
||||
sendMail: async () => {
|
||||
return;
|
||||
},
|
||||
createMailContentFromEmailConfirmForNormalUser: async () => {
|
||||
return { html: '', text: '', subject: '' };
|
||||
},
|
||||
});
|
||||
overrideBlobstorageService(service, {
|
||||
createContainer: async () => {
|
||||
return;
|
||||
},
|
||||
});
|
||||
|
||||
try {
|
||||
await service.createPartnerAccount(
|
||||
context,
|
||||
companyName,
|
||||
country,
|
||||
email,
|
||||
username,
|
||||
parentExternalId,
|
||||
TIERS.TIER1,
|
||||
);
|
||||
} catch (e) {
|
||||
if (e instanceof HttpException) {
|
||||
expect(e.getStatus()).toBe(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
expect(e.getResponse()).toEqual(makeErrorResponse('E009999'));
|
||||
} else {
|
||||
fail();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it('パートナーアカウントを作成がメールアドレス重複によって失敗すると400エラーが発生する', async () => {
|
||||
const module = await makeTestingModule(source);
|
||||
const service = module.get<AccountsService>(AccountsService);
|
||||
|
||||
const parentExternalId = 'parent_external_id';
|
||||
|
||||
await createAccountAndAdminUser(source, parentExternalId);
|
||||
|
||||
const context = makeContext(parentExternalId);
|
||||
const companyName = 'partner_company_name';
|
||||
const country = 'US';
|
||||
const email = 'partner@example.com';
|
||||
const username = 'partner_username';
|
||||
|
||||
overrideAdB2cService(service, {
|
||||
createUser: async () => {
|
||||
// EmailのConflictエラーを返す
|
||||
return { reason: 'email', message: 'dummy' };
|
||||
},
|
||||
});
|
||||
|
||||
overrideSendgridService(service, {
|
||||
sendMail: async () => {
|
||||
return;
|
||||
},
|
||||
createMailContentFromEmailConfirmForNormalUser: async () => {
|
||||
return { html: '', text: '', subject: '' };
|
||||
},
|
||||
});
|
||||
overrideBlobstorageService(service, {
|
||||
createContainer: async () => {
|
||||
return;
|
||||
},
|
||||
});
|
||||
|
||||
try {
|
||||
await service.createPartnerAccount(
|
||||
context,
|
||||
companyName,
|
||||
country,
|
||||
email,
|
||||
username,
|
||||
parentExternalId,
|
||||
TIERS.TIER1,
|
||||
);
|
||||
} catch (e) {
|
||||
if (e instanceof HttpException) {
|
||||
expect(e.getStatus()).toBe(HttpStatus.BAD_REQUEST);
|
||||
expect(e.getResponse()).toEqual(makeErrorResponse('E010301'));
|
||||
} else {
|
||||
fail();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
it('パートナーアカウントを作成がBlobStorageへの通信失敗によって失敗すると500エラーが発生する', async () => {
|
||||
const module = await makeTestingModule(source);
|
||||
const service = module.get<AccountsService>(AccountsService);
|
||||
|
||||
const parentExternalId = 'parent_external_id';
|
||||
|
||||
await createAccountAndAdminUser(source, parentExternalId);
|
||||
|
||||
const context = makeContext(parentExternalId);
|
||||
const partnerExternalId = 'partner_external_id';
|
||||
const companyName = 'partner_company_name';
|
||||
const country = 'US';
|
||||
const email = 'partner@example.com';
|
||||
const username = 'partner_username';
|
||||
|
||||
overrideAdB2cService(service, {
|
||||
createUser: async () => {
|
||||
return { sub: partnerExternalId };
|
||||
},
|
||||
});
|
||||
|
||||
overrideSendgridService(service, {
|
||||
sendMail: async () => {
|
||||
return;
|
||||
},
|
||||
createMailContentFromEmailConfirmForNormalUser: async () => {
|
||||
return { html: '', text: '', subject: '' };
|
||||
},
|
||||
});
|
||||
overrideBlobstorageService(service, {
|
||||
createContainer: async () => {
|
||||
throw new Error();
|
||||
},
|
||||
});
|
||||
|
||||
try {
|
||||
await service.createPartnerAccount(
|
||||
context,
|
||||
companyName,
|
||||
country,
|
||||
email,
|
||||
username,
|
||||
parentExternalId,
|
||||
TIERS.TIER1,
|
||||
);
|
||||
} catch (e) {
|
||||
if (e instanceof HttpException) {
|
||||
expect(e.getStatus()).toBe(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
expect(e.getResponse()).toEqual(makeErrorResponse('E009999'));
|
||||
} else {
|
||||
fail();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user