Merged PR 903: POST /notification/register
## 概要 [Task3983: POST /notification/register](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/3983) - `POST /notification/register`APIのバリデータに対するテストを追加しました。 ## レビューポイント - テストケースに不足はないか。 ## UIの変更 - なし ## クエリの変更 - なし ## 動作確認状況 - ローカルで確認 - 行った修正がデグレを発生させていないことを確認できるか - 具体的にどのような確認をしたか - テストの追加のみなのでほかに影響なし。
This commit is contained in:
parent
3a7c1765ee
commit
261a5afbdd
@ -2,6 +2,9 @@ import { Test, TestingModule } from '@nestjs/testing';
|
|||||||
import { NotificationController } from './notification.controller';
|
import { NotificationController } from './notification.controller';
|
||||||
import { NotificationService } from './notification.service';
|
import { NotificationService } from './notification.service';
|
||||||
import { ConfigModule } from '@nestjs/config';
|
import { ConfigModule } from '@nestjs/config';
|
||||||
|
import { RegisterRequest } from './types/types';
|
||||||
|
import { plainToClass } from 'class-transformer';
|
||||||
|
import { validate } from 'class-validator';
|
||||||
|
|
||||||
describe('NotificationController', () => {
|
describe('NotificationController', () => {
|
||||||
let controller: NotificationController;
|
let controller: NotificationController;
|
||||||
@ -28,3 +31,57 @@ describe('NotificationController', () => {
|
|||||||
expect(controller).toBeDefined();
|
expect(controller).toBeDefined();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('valdation register', () => {
|
||||||
|
it('有効なリクエストが成功する(wns)', async () => {
|
||||||
|
const request = new RegisterRequest();
|
||||||
|
request.pns = 'wns';
|
||||||
|
request.handler = 'test';
|
||||||
|
|
||||||
|
const valdationObject = plainToClass(RegisterRequest, request);
|
||||||
|
|
||||||
|
const errors = await validate(valdationObject);
|
||||||
|
expect(errors.length).toBe(0);
|
||||||
|
});
|
||||||
|
it('有効なリクエストが成功する(apn)', async () => {
|
||||||
|
const request = new RegisterRequest();
|
||||||
|
request.pns = 'apns';
|
||||||
|
request.handler = 'test';
|
||||||
|
|
||||||
|
const valdationObject = plainToClass(RegisterRequest, request);
|
||||||
|
|
||||||
|
const errors = await validate(valdationObject);
|
||||||
|
expect(errors.length).toBe(0);
|
||||||
|
});
|
||||||
|
it('pnsが不正(wns or apns以外)な場合、リクエストが失敗する', async () => {
|
||||||
|
const request = new RegisterRequest();
|
||||||
|
request.pns = 'invalid';
|
||||||
|
request.handler = 'test';
|
||||||
|
|
||||||
|
const valdationObject = plainToClass(RegisterRequest, request);
|
||||||
|
|
||||||
|
const errors = await validate(valdationObject);
|
||||||
|
expect(errors.length).toBe(1);
|
||||||
|
});
|
||||||
|
it('handlerが空文字の場合、リクエストが失敗する', async () => {
|
||||||
|
const request = new RegisterRequest();
|
||||||
|
request.pns = 'apns';
|
||||||
|
request.handler = '';
|
||||||
|
|
||||||
|
const valdationObject = plainToClass(RegisterRequest, request);
|
||||||
|
|
||||||
|
const errors = await validate(valdationObject);
|
||||||
|
expect(errors.length).toBe(1);
|
||||||
|
});
|
||||||
|
it('handlerが文字列でない場合、リクエストが失敗する', async () => {
|
||||||
|
const request = {
|
||||||
|
pns: 'apns',
|
||||||
|
handler: 123,
|
||||||
|
};
|
||||||
|
|
||||||
|
const valdationObject = plainToClass(RegisterRequest, request);
|
||||||
|
|
||||||
|
const errors = await validate(valdationObject);
|
||||||
|
expect(errors.length).toBe(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user