-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c6f89e6
commit 11c679d
Showing
25 changed files
with
433 additions
and
250 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { RequestResult, requestResult } from '@performance-artist/fp-ts-adt'; | ||
import { option } from 'fp-ts'; | ||
import * as rx from 'rxjs'; | ||
import { test } from '../../src'; | ||
import { ReportDeps, withReports as reportsMedium } from './withReports'; | ||
import { makeTodoSource, Todo } from '../basic/todo.source'; | ||
import { TodoDeps } from '../basic/todo.medium'; | ||
import { unorderedEqualStrict } from '../../src/medium/testing'; | ||
|
||
const withReports = test.withMedium(reportsMedium); | ||
|
||
const mockTodos: RequestResult<Todo[]> = requestResult.success([ | ||
{ id: 1, text: '', done: false }, | ||
]); | ||
|
||
const makeDeps = (): ReportDeps & TodoDeps => ({ | ||
todoSource: makeTodoSource(), | ||
todoApi: { | ||
getTodos: () => rx.of(mockTodos), | ||
updateTodo: () => {}, | ||
}, | ||
logger: () => {}, | ||
}); | ||
|
||
describe('reports', () => { | ||
it( | ||
'Triggers report on any update', | ||
withReports(makeDeps, (deps, history, output) => { | ||
const { todoSource } = deps; | ||
|
||
todoSource.dispatch('getTodos')(); | ||
expect(history.take()).toStrictEqual([ | ||
output('setTodos')(mockTodos), | ||
output('updateReport')(mockTodos), | ||
]); | ||
|
||
todoSource.dispatch('toggleDone')(1); | ||
expect(history.take()).toStrictEqual([ | ||
output('updateTodo')(option.some({ id: 1, text: '', done: true })), | ||
output('updateReport')(option.some({ id: 1, text: '', done: true })), | ||
]); | ||
}), | ||
); | ||
|
||
it( | ||
'Triggers logger on error(no todo for the provided id)', | ||
withReports(makeDeps, (deps, history, output) => { | ||
const { todoSource } = deps; | ||
|
||
todoSource.dispatch('toggleDone')(10); | ||
const [first, ...rest] = history.take(); | ||
expect(first).toStrictEqual(output('updateTodo')(option.none)); | ||
expect( | ||
unorderedEqualStrict(rest, [ | ||
output('updateReport')(option.none), | ||
output('errorReport')(10), | ||
]), | ||
).toBe(true); | ||
}), | ||
); | ||
}); |
Oops, something went wrong.