Skip to content

Commit

Permalink
add: テスト作成
Browse files Browse the repository at this point in the history
  • Loading branch information
kahirokunn committed Feb 2, 2019
1 parent 7ed9e9b commit 2c7a41b
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 42 deletions.
3 changes: 3 additions & 0 deletions src/inversify/rejectStubProviders.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
IAuthApplicationService,
} from '@/boundary/authApplicationService/IAuthApplicationService'
import { IBookApplicationService } from '@/boundary/bookApplicationService/IBookApplicationService'
import {
IUserApplicationService,
} from '@/boundary/userApplicationService/IUserApplicationService'
Expand All @@ -11,6 +12,7 @@ import { IUserObservableRepository } from '@/query/observableRepository/user/IUs
import {
AuthApplicationService,
} from '@/stub/domain/app/authApplicationService/RejectService'
import { BookApplicationService } from '@/stub/domain/app/bookApplicationService/RejectService'
import {
UserApplicationService,
} from '@/stub/domain/app/userApplicationService/RejectService'
Expand All @@ -28,4 +30,5 @@ export function stubProviders(container: Container): void {
// application
container.bind(IUserApplicationService).to(UserApplicationService).inSingletonScope()
container.bind(IAuthApplicationService).to(AuthApplicationService).inSingletonScope()
container.bind(IBookApplicationService).to(BookApplicationService).inSingletonScope()
}
3 changes: 3 additions & 0 deletions src/inversify/resolveStubProviders.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
IAuthApplicationService,
} from '@/boundary/authApplicationService/IAuthApplicationService'
import { IBookApplicationService } from '@/boundary/bookApplicationService/IBookApplicationService'
import {
IUserApplicationService,
} from '@/boundary/userApplicationService/IUserApplicationService'
Expand All @@ -9,6 +10,7 @@ import { BlankLogger } from '@/drivers/logger/BlankLogger'
import { UserBLoC } from '@/query/bloc/user/UserBLoC'
import { IUserObservableRepository } from '@/query/observableRepository/user/IUserObservableRepository'
import { AuthApplicationService } from '@/stub/domain/app/authApplicationService/ResolveService'
import { BookApplicationService } from '@/stub/domain/app/bookApplicationService/ResolveService'
import { UserApplicationService } from '@/stub/domain/app/userApplicationService/ResolveService'
import { UserObservableRepository } from '@/stub/query/observableRepository/UserObservableRepository/ResolveRepository'
import { Container } from 'inversify'
Expand All @@ -24,4 +26,5 @@ export function stubProviders(container: Container): void {
// application
container.bind(IUserApplicationService).to(UserApplicationService).inSingletonScope()
container.bind(IAuthApplicationService).to(AuthApplicationService).inSingletonScope()
container.bind(IBookApplicationService).to(BookApplicationService).inSingletonScope()
}
19 changes: 19 additions & 0 deletions src/store/containers/createBookForm/failureCreateBook.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import '@/rejectTestConfiguration'
import { createStore } from '@/store/root'
import { bookFactory } from '@/stub/domain/factory/IBook'
import flushPromises from 'flush-promises'
import { createBook } from './action'
import selector from './selector'


test('本の登録に失敗する', async () => {
const store = createStore()
expect(selector.isSendFailed(store.state)).toBe(false)
expect(selector.isSending(store.state)).toBe(false)
expect(selector.isSendSuccess(store.state)).toBe(false)
store.dispatch(createBook({params: bookFactory()}))
await flushPromises()
expect(selector.isSending(store.state)).toBe(false)
expect(selector.isSendFailed(store.state)).toBe(true)
expect(selector.isSendSuccess(store.state)).toBe(false)
})
22 changes: 0 additions & 22 deletions src/store/containers/createBookForm/failureUpdateProfile.spec.ts

This file was deleted.

20 changes: 20 additions & 0 deletions src/store/containers/createBookForm/successBook.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import '@/resolveTestConfiguration'
import { createStore } from '@/store/root'
import { bookFactory } from '@/stub/domain/factory/IBook'
import flushPromises from 'flush-promises'
import { createBook } from './action'
import selector from './selector'


test('本の登録に成功する', async () => {
const store = createStore()
expect(selector.isSendFailed(store.state)).toBe(false)
expect(selector.isSending(store.state)).toBe(false)
expect(selector.isSendSuccess(store.state)).toBe(false)
store.dispatch(createBook({params: bookFactory()}))
expect(selector.isSending(store.state)).toBe(true)
await flushPromises()
expect(selector.isSending(store.state)).toBe(false)
expect(selector.isSendFailed(store.state)).toBe(false)
expect(selector.isSendSuccess(store.state)).toBe(true)
})
20 changes: 0 additions & 20 deletions src/store/containers/createBookForm/successUpdateProfile.spec.ts

This file was deleted.

16 changes: 16 additions & 0 deletions src/stub/domain/app/bookApplicationService/RejectService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { IBookApplicationService } from '@/boundary/bookApplicationService/IBookApplicationService'
import { injectable } from 'inversify'

@injectable()
export class BookApplicationService implements IBookApplicationService {

public create(): Promise<void> {
throw Error()
}
public update(): Promise<void> {
throw Error()
}
public delete(): Promise<void> {
throw Error()
}
}
16 changes: 16 additions & 0 deletions src/stub/domain/app/bookApplicationService/ResolveService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { IBookApplicationService } from '@/boundary/bookApplicationService/IBookApplicationService'
import { injectable } from 'inversify'

@injectable()
export class BookApplicationService implements IBookApplicationService {

public async create(): Promise<void> {
// pass
}
public async update(): Promise<void> {
// pass
}
public async delete(): Promise<void> {
// pass
}
}
30 changes: 30 additions & 0 deletions src/stub/domain/factory/IBook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {
BookType,
IBook,
Owner,
PurchasedLocation,
} from '@/boundary/bookApplicationService/InOutType'
import uuid from 'uuid'

export function bookFactory(params?: Partial<IBook>): IBook {
const date = new Date()
return {
id: uuid(),
userId: '',
title: '',
purchasedLocation: PurchasedLocation.ONLINE,
purchasedDatetime: date,
description: '',
type: BookType.PHYSICAL_BOOK,
price: 1000,
owner: Owner.COMPANY,
purchasedUrl: '',
downloadUrl: '',
coverImageFilePath: '',
evaluation: null,
receiptImageFilePath: '',
createdAt: date,
updatedAt: date,
...params,
}
}

0 comments on commit 2c7a41b

Please sign in to comment.