Skip to content

Commit

Permalink
...add test case: 1-to-multi-value Observable conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
chuan6 committed Aug 13, 2018
1 parent 9ffa253 commit 04c35c3
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/utils/interceptor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,32 @@ describe.only('interceptor spec', () => {
expect(x).to.equal('divided-by-zero')
})
})

it('wrap: one-value Observable to multi-value Observable conversion', function* () {
const cache = new Map([['leo', '你好,里奥']])
const interceptor = (options: { cacheThenRefresh: boolean }, gateFn: any, gateArgs: any[]) => {
const request$ = gateFn(...gateArgs)
if (options.cacheThenRefresh) {
const userName = gateArgs[0]
const requestAndCache = request$.do((hello: string) => cache.set(userName, hello))
if (cache.has(userName)) {
return Observable.concat(Observable.of(cache.get(userName)), requestAndCache)
} else {
return requestAndCache
}
} else {
return request$
}
}
const gate = (userName: string) => {
return Observable.of(`hello ${userName}`)
}
const wrapped = ix.wrap(gate, interceptor)
const intercepted = wrapped({ cacheThenRefresh: true })
yield intercepted('leo').take(2).toArray()
.do((xs) => {
expect(xs).to.deep.equal(['你好,里奥', 'hello leo'])
expect(cache.get('leo')).to.equal('hello leo')
})
})
})

0 comments on commit 04c35c3

Please sign in to comment.