Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test('find', function (t) {
const cid = createCid()
const action$ = Action$.of(cats.actions.find(cid))
const feathers = {
find: () => Rx.Observable.of(values(catsData))
}
const expected = [
actionCreators.start(cid, { service, method: 'find', args: { params: {} } }),
actionCreators.set(cid, 0, catsData[0]),
actionCreators.set(cid, 1, catsData[1]),
actionCreators.set(cid, 2, catsData[2]),
actionCreators.complete(cid)
]
cats.epic(action$, undefined, { feathers })
.toArray() // .reduce(flip(append), [])
.subscribe((actions) => {
t.deepEqual(actions, expected)
t.end()
})
test('update', function (t) {
const cid = createCid()
const action$ = Action$.of(cats.actions.update(cid, 0, nextCat))
const feathers = {
update: () => Rx.Observable.of(merge({ id: 0, feathers: true }, nextCat))
}
const store = {
getState: () => ({ cats: catsData })
}
const expected = [
actionCreators.start(cid, { service, method: 'update', args: { id: 0, data: nextCat, params: {} } }),
actionCreators.set(cid, 0, merge({ id: 0 }, nextCat)),
actionCreators.set(cid, 0, merge({ id: 0, feathers: true }, nextCat)),
actionCreators.complete(cid)
]
cats.epic(action$, store, { feathers })
.toArray()
.subscribe((actions) => {
t.deepEqual(actions, expected)
test('patch', function (t) {
const cid = createCid()
const action$ = Action$.of(cats.actions.patch(cid, 0, nextCat))
const feathers = {
patch: () => Rx.Observable.of(mergeAll([catsData[0], { feathers: true }, nextCat]))
}
const store = {
getState: () => ({ cats: catsData })
}
const expected = [
actionCreators.start(cid, { service, method: 'patch', args: { id: 0, data: nextCat, params: {} } }),
actionCreators.set(cid, 0, merge(catsData[0], nextCat)),
actionCreators.set(cid, 0, mergeAll([catsData[0], { feathers: true }, nextCat])),
actionCreators.complete(cid)
]
cats.epic(action$, store, { feathers })
.toArray()
.subscribe((actions) => {
t.deepEqual(actions, expected)
test('create with rollback', function (t) {
const cid = createCid()
const err = new Error('oh no')
const action$ = Action$.of(cats.actions.create(cid, newCat))
const feathers = {
create: () => Rx.Observable.throw(err)
}
const expected = [
actionCreators.start(cid, { service, method: 'create', args: { data: newCat, params: {} } }),
actionCreators.set(cid, cid, newCat),
actionCreators.set(cid, cid, undefined),
actionCreators.error(cid, err)
]
cats.epic(action$, undefined, { feathers })
.toArray()
.subscribe((actions) => {
t.deepEqual(actions, expected)
t.end()
})
})
test('remove', function (t) {
const cid = createCid()
const action$ = Action$.of(cats.actions.remove(cid, 0))
const feathers = {
remove: () => Rx.Observable.of(catsData[0])
}
const store = {
getState: () => ({ cats: catsData })
}
const expected = [
actionCreators.start(cid, { service, method: 'remove', args: { id: 0, params: {} } }),
actionCreators.set(cid, 0, undefined),
actionCreators.set(cid, 0, undefined),
actionCreators.complete(cid)
]
cats.epic(action$, store, { feathers })
.toArray()
.subscribe((actions) => {
t.deepEqual(actions, expected)
test('get', function (t) {
const cid = createCid()
const action$ = Action$.of(cats.actions.get(cid, 0))
const feathers = {
get: (id) => Rx.Observable.of(catsData[id])
}
const expected = [
actionCreators.start(cid, { service, method: 'get', args: { id: 0, params: {} } }),
actionCreators.set(cid, 0, catsData[0]),
actionCreators.complete(cid)
]
cats.epic(action$, undefined, { feathers })
.toArray()
.subscribe((actions) => {
t.deepEqual(actions, expected)
t.end()
})
})